repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
kakserpom/phpdaemon
PHPDaemon/Clients/IMAP/Connection.php
Connection.renameFolder
public function renameFolder($cb, $oldName, $newName) { $this->onResponse->push($cb); $this->writeln(self::TAG_RENAMEFOLDER . " RENAME " .$this->escapeString($oldName)." ".$this->escapeString($newName)); }
php
public function renameFolder($cb, $oldName, $newName) { $this->onResponse->push($cb); $this->writeln(self::TAG_RENAMEFOLDER . " RENAME " .$this->escapeString($oldName)." ".$this->escapeString($newName)); }
[ "public", "function", "renameFolder", "(", "$", "cb", ",", "$", "oldName", ",", "$", "newName", ")", "{", "$", "this", "->", "onResponse", "->", "push", "(", "$", "cb", ")", ";", "$", "this", "->", "writeln", "(", "self", "::", "TAG_RENAMEFOLDER", "....
rename and/or move folder @param string $oldName name or instance of folder @param string $newName new global name of folder
[ "rename", "and", "/", "or", "move", "folder" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/IMAP/Connection.php#L585-L590
kakserpom/phpdaemon
PHPDaemon/Clients/IMAP/Connection.php
Connection.removeMessage
public function removeMessage($cb, $uid) { $this->onResponse->push($cb); $this->store([self::FLAG_DELETED], $uid, null, '+', true, self::TAG_DELETEMESSAGE); }
php
public function removeMessage($cb, $uid) { $this->onResponse->push($cb); $this->store([self::FLAG_DELETED], $uid, null, '+', true, self::TAG_DELETEMESSAGE); }
[ "public", "function", "removeMessage", "(", "$", "cb", ",", "$", "uid", ")", "{", "$", "this", "->", "onResponse", "->", "push", "(", "$", "cb", ")", ";", "$", "this", "->", "store", "(", "[", "self", "::", "FLAG_DELETED", "]", ",", "$", "uid", "...
Remove a message from server. @param int $uid unique number of message
[ "Remove", "a", "message", "from", "server", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/IMAP/Connection.php#L596-L600
kakserpom/phpdaemon
PHPDaemon/Clients/IMAP/Connection.php
Connection.logout
public function logout($cb = null) { if ($cb) { $this->onResponse->push($cb); } $this->writeln(self::TAG_LOGOUT . " LOGOUT"); }
php
public function logout($cb = null) { if ($cb) { $this->onResponse->push($cb); } $this->writeln(self::TAG_LOGOUT . " LOGOUT"); }
[ "public", "function", "logout", "(", "$", "cb", "=", "null", ")", "{", "if", "(", "$", "cb", ")", "{", "$", "this", "->", "onResponse", "->", "push", "(", "$", "cb", ")", ";", "}", "$", "this", "->", "writeln", "(", "self", "::", "TAG_LOGOUT", ...
logout of imap server
[ "logout", "of", "imap", "server" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/IMAP/Connection.php#L605-L611
kakserpom/phpdaemon
PHPDaemon/Clients/Asterisk/Connection.php
Connection.onConnected
public function onConnected($cb) { if ($this->state === self::CONN_STATE_HANDSHAKED_ERROR) { $cb($this); } elseif ($this->state === self::CONN_STATE_HANDSHAKED_OK) { $cb($this); } else { if (!$this->onConnected) { $this->onConnected = new StackCallbacks(); } $this->onConnected->push($cb); } }
php
public function onConnected($cb) { if ($this->state === self::CONN_STATE_HANDSHAKED_ERROR) { $cb($this); } elseif ($this->state === self::CONN_STATE_HANDSHAKED_OK) { $cb($this); } else { if (!$this->onConnected) { $this->onConnected = new StackCallbacks(); } $this->onConnected->push($cb); } }
[ "public", "function", "onConnected", "(", "$", "cb", ")", "{", "if", "(", "$", "this", "->", "state", "===", "self", "::", "CONN_STATE_HANDSHAKED_ERROR", ")", "{", "$", "cb", "(", "$", "this", ")", ";", "}", "elseif", "(", "$", "this", "->", "state",...
Execute the given callback when/if the connection is handshaked @param callable Callback @return void
[ "Execute", "the", "given", "callback", "when", "/", "if", "the", "connection", "is", "handshaked" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Asterisk/Connection.php#L127-L140
kakserpom/phpdaemon
PHPDaemon/Clients/Asterisk/Connection.php
Connection.onReady
public function onReady() { if ($this->url === null) { return; } if ($this->connected && !$this->busy) { $this->pool->servConnFree[$this->url]->attach($this); } $url = parse_url($this->url); $this->username = $url['user']; $this->secret = $url['pass']; }
php
public function onReady() { if ($this->url === null) { return; } if ($this->connected && !$this->busy) { $this->pool->servConnFree[$this->url]->attach($this); } $url = parse_url($this->url); $this->username = $url['user']; $this->secret = $url['pass']; }
[ "public", "function", "onReady", "(", ")", "{", "if", "(", "$", "this", "->", "url", "===", "null", ")", "{", "return", ";", "}", "if", "(", "$", "this", "->", "connected", "&&", "!", "$", "this", "->", "busy", ")", "{", "$", "this", "->", "poo...
Called when the connection is handshaked (at low-level), and peer is ready to recv. data @return void
[ "Called", "when", "the", "connection", "is", "handshaked", "(", "at", "low", "-", "level", ")", "and", "peer", "is", "ready", "to", "recv", ".", "data" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Asterisk/Connection.php#L146-L160
kakserpom/phpdaemon
PHPDaemon/Clients/Asterisk/Connection.php
Connection.gracefulShutdown
public function gracefulShutdown() { if ($this->finished) { return !$this->writing; } $this->logoff(); $this->finish(); return false; }
php
public function gracefulShutdown() { if ($this->finished) { return !$this->writing; } $this->logoff(); $this->finish(); return false; }
[ "public", "function", "gracefulShutdown", "(", ")", "{", "if", "(", "$", "this", "->", "finished", ")", "{", "return", "!", "$", "this", "->", "writing", ";", "}", "$", "this", "->", "logoff", "(", ")", ";", "$", "this", "->", "finish", "(", ")", ...
Called when the worker is going to shutdown @return boolean Ready to shutdown?
[ "Called", "when", "the", "worker", "is", "going", "to", "shutdown" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Asterisk/Connection.php#L166-L177
kakserpom/phpdaemon
PHPDaemon/Clients/Asterisk/Connection.php
Connection.onRead
public function onRead() { if ($this->state === self::CONN_STATE_START) { if (($ver = $this->readline()) === null) { return; } $this->pool->setAmiVersion($this->addr, $ver); $this->state = self::CONN_STATE_GOT_INITIAL_PACKET; $this->auth(); } while (($line = $this->readline()) !== null) { //Daemon::log('>>> '.$line); if ($line === '') { $this->instate = self::INPUT_STATE_END_OF_PACKET; $packet =& $this->packets[$this->cnt]; ++$this->cnt; } else { $this->instate = self::INPUT_STATE_PROCESSING; list($header, $value) = Pool::extract($line); $this->packets[$this->cnt][$header] = $value; } if ((int)$this->state === self::CONN_STATE_AUTH) { if ($this->instate === self::INPUT_STATE_END_OF_PACKET) { if ($packet['response'] === 'success') { if ($this->state === self::CONN_STATE_CHALLENGE_PACKET_SENT) { if (is_callable($this->onChallenge)) { $func = $this->onChallenge; $func($this, $packet['challenge']); } } else { if ($packet['message'] === 'authentication accepted') { $this->state = self::CONN_STATE_HANDSHAKED_OK; Daemon::$process->log( __METHOD__ . ': Authentication ok. Connected to ' . parse_url($this->addr, PHP_URL_HOST) ); if ($this->onConnected) { $this->connected = true; $this->onConnected->executeAll($this); $this->onConnected = null; } $this->event('connected'); } } } else { $this->state = self::CONN_STATE_HANDSHAKED_ERROR; Daemon::$process->log( __METHOD__ . ': Authentication failed. Connection to ' . parse_url($this->addr, PHP_URL_HOST) . ' failed.' ); if ($this->onConnected) { $this->connected = false; $this->onConnected->executeAll($this); $this->onConnected = null; } $this->finish(); } $this->packets = []; } } elseif ($this->state === self::CONN_STATE_HANDSHAKED_OK) { if ($this->instate === self::INPUT_STATE_END_OF_PACKET) { // Event if (isset($packet['event']) && !isset($packet['actionid'])) { $this->event('event_' . $packet['event'], $packet); $this->event('event', $packet); } // Response elseif (isset($packet['actionid'])) { $action_id =& $packet['actionid']; if (isset($this->callbacks[$action_id])) { if (isset($this->assertions[$action_id])) { $this->packets[$action_id][] = $packet; $assertations = count( array_uintersect_uassoc( $this->assertions[$action_id], $packet, 'strcasecmp', 'strcasecmp' ) ); if ($assertations === count($this->assertions[$action_id])) { if (is_callable($this->callbacks[$action_id])) { $this->callbacks[$action_id]($this, $this->packets[$action_id]); unset($this->callbacks[$action_id]); } unset($this->assertions[$action_id]); unset($this->packets[$action_id]); } } else { if (is_callable($this->callbacks[$action_id])) { $this->callbacks[$action_id]($this, $packet); unset($this->callbacks[$action_id]); } } } } unset($packet); unset($this->packets[$this->cnt - 1]); } } } }
php
public function onRead() { if ($this->state === self::CONN_STATE_START) { if (($ver = $this->readline()) === null) { return; } $this->pool->setAmiVersion($this->addr, $ver); $this->state = self::CONN_STATE_GOT_INITIAL_PACKET; $this->auth(); } while (($line = $this->readline()) !== null) { //Daemon::log('>>> '.$line); if ($line === '') { $this->instate = self::INPUT_STATE_END_OF_PACKET; $packet =& $this->packets[$this->cnt]; ++$this->cnt; } else { $this->instate = self::INPUT_STATE_PROCESSING; list($header, $value) = Pool::extract($line); $this->packets[$this->cnt][$header] = $value; } if ((int)$this->state === self::CONN_STATE_AUTH) { if ($this->instate === self::INPUT_STATE_END_OF_PACKET) { if ($packet['response'] === 'success') { if ($this->state === self::CONN_STATE_CHALLENGE_PACKET_SENT) { if (is_callable($this->onChallenge)) { $func = $this->onChallenge; $func($this, $packet['challenge']); } } else { if ($packet['message'] === 'authentication accepted') { $this->state = self::CONN_STATE_HANDSHAKED_OK; Daemon::$process->log( __METHOD__ . ': Authentication ok. Connected to ' . parse_url($this->addr, PHP_URL_HOST) ); if ($this->onConnected) { $this->connected = true; $this->onConnected->executeAll($this); $this->onConnected = null; } $this->event('connected'); } } } else { $this->state = self::CONN_STATE_HANDSHAKED_ERROR; Daemon::$process->log( __METHOD__ . ': Authentication failed. Connection to ' . parse_url($this->addr, PHP_URL_HOST) . ' failed.' ); if ($this->onConnected) { $this->connected = false; $this->onConnected->executeAll($this); $this->onConnected = null; } $this->finish(); } $this->packets = []; } } elseif ($this->state === self::CONN_STATE_HANDSHAKED_OK) { if ($this->instate === self::INPUT_STATE_END_OF_PACKET) { // Event if (isset($packet['event']) && !isset($packet['actionid'])) { $this->event('event_' . $packet['event'], $packet); $this->event('event', $packet); } // Response elseif (isset($packet['actionid'])) { $action_id =& $packet['actionid']; if (isset($this->callbacks[$action_id])) { if (isset($this->assertions[$action_id])) { $this->packets[$action_id][] = $packet; $assertations = count( array_uintersect_uassoc( $this->assertions[$action_id], $packet, 'strcasecmp', 'strcasecmp' ) ); if ($assertations === count($this->assertions[$action_id])) { if (is_callable($this->callbacks[$action_id])) { $this->callbacks[$action_id]($this, $this->packets[$action_id]); unset($this->callbacks[$action_id]); } unset($this->assertions[$action_id]); unset($this->packets[$action_id]); } } else { if (is_callable($this->callbacks[$action_id])) { $this->callbacks[$action_id]($this, $packet); unset($this->callbacks[$action_id]); } } } } unset($packet); unset($this->packets[$this->cnt - 1]); } } } }
[ "public", "function", "onRead", "(", ")", "{", "if", "(", "$", "this", "->", "state", "===", "self", "::", "CONN_STATE_START", ")", "{", "if", "(", "(", "$", "ver", "=", "$", "this", "->", "readline", "(", ")", ")", "===", "null", ")", "{", "retu...
Called when new data received @return void
[ "Called", "when", "new", "data", "received" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Asterisk/Connection.php#L196-L309
kakserpom/phpdaemon
PHPDaemon/Clients/Asterisk/Connection.php
Connection.auth
protected function auth() { if ($this->state !== self::CONN_STATE_GOT_INITIAL_PACKET) { return; } if ($this->pool->config->authtype->value === 'md5') { $this->challenge(function ($conn, $challenge) { $packet = "Action: Login\r\n" . "AuthType: MD5\r\n" . "Username: " . $this->username . "\r\n" . "Key: " . md5($challenge . $this->secret) . "\r\n" . "Events: on\r\n" . "\r\n"; $this->state = self::CONN_STATE_LOGIN_PACKET_SENT_AFTER_CHALLENGE; $conn->write($packet); }); } else { $this->login(); } }
php
protected function auth() { if ($this->state !== self::CONN_STATE_GOT_INITIAL_PACKET) { return; } if ($this->pool->config->authtype->value === 'md5') { $this->challenge(function ($conn, $challenge) { $packet = "Action: Login\r\n" . "AuthType: MD5\r\n" . "Username: " . $this->username . "\r\n" . "Key: " . md5($challenge . $this->secret) . "\r\n" . "Events: on\r\n" . "\r\n"; $this->state = self::CONN_STATE_LOGIN_PACKET_SENT_AFTER_CHALLENGE; $conn->write($packet); }); } else { $this->login(); } }
[ "protected", "function", "auth", "(", ")", "{", "if", "(", "$", "this", "->", "state", "!==", "self", "::", "CONN_STATE_GOT_INITIAL_PACKET", ")", "{", "return", ";", "}", "if", "(", "$", "this", "->", "pool", "->", "config", "->", "authtype", "->", "va...
Send authentication packet @return void
[ "Send", "authentication", "packet" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Asterisk/Connection.php#L315-L335
kakserpom/phpdaemon
PHPDaemon/Clients/Asterisk/Connection.php
Connection.login
protected function login() { $this->state = self::CONN_STATE_LOGIN_PACKET_SENT; $this->write( "Action: login\r\n" . "Username: " . $this->username . "\r\n" . "Secret: " . $this->secret . "\r\n" . "Events: on\r\n" . "\r\n" ); }
php
protected function login() { $this->state = self::CONN_STATE_LOGIN_PACKET_SENT; $this->write( "Action: login\r\n" . "Username: " . $this->username . "\r\n" . "Secret: " . $this->secret . "\r\n" . "Events: on\r\n" . "\r\n" ); }
[ "protected", "function", "login", "(", ")", "{", "$", "this", "->", "state", "=", "self", "::", "CONN_STATE_LOGIN_PACKET_SENT", ";", "$", "this", "->", "write", "(", "\"Action: login\\r\\n\"", ".", "\"Username: \"", ".", "$", "this", "->", "username", ".", "...
Action: Login Synopsis: Login Manager Privilege: <none> @return void
[ "Action", ":", "Login", "Synopsis", ":", "Login", "Manager", "Privilege", ":", "<none", ">" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Asterisk/Connection.php#L344-L354
kakserpom/phpdaemon
PHPDaemon/Clients/Asterisk/Connection.php
Connection.challenge
protected function challenge($cb) { $this->onChallenge = $cb; $this->state = self::CONN_STATE_CHALLENGE_PACKET_SENT; $this->write( "Action: Challenge\r\n" . "AuthType: MD5\r\n" . "\r\n" ); }
php
protected function challenge($cb) { $this->onChallenge = $cb; $this->state = self::CONN_STATE_CHALLENGE_PACKET_SENT; $this->write( "Action: Challenge\r\n" . "AuthType: MD5\r\n" . "\r\n" ); }
[ "protected", "function", "challenge", "(", "$", "cb", ")", "{", "$", "this", "->", "onChallenge", "=", "$", "cb", ";", "$", "this", "->", "state", "=", "self", "::", "CONN_STATE_CHALLENGE_PACKET_SENT", ";", "$", "this", "->", "write", "(", "\"Action: Chall...
Action: Challenge Synopsis: Generate Challenge for MD5 Auth Privilege: <none> @param callable $cb @return void
[ "Action", ":", "Challenge", "Synopsis", ":", "Generate", "Challenge", "for", "MD5", "Auth", "Privilege", ":", "<none", ">" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Asterisk/Connection.php#L364-L373
kakserpom/phpdaemon
PHPDaemon/Clients/Asterisk/Connection.php
Connection.setVar
public function setVar($channel, $variable, $value, $cb) { $cmd = "Action: SetVar\r\n"; if ($channel) { $cmd .= "Channel: " . trim($channel) . "\r\n"; } if (isset($variable, $value)) { $cmd .= "Variable: " . trim($variable) . "\r\n" . "Value: " . trim($value) . "\r\n"; $this->command($cmd, $cb); } }
php
public function setVar($channel, $variable, $value, $cb) { $cmd = "Action: SetVar\r\n"; if ($channel) { $cmd .= "Channel: " . trim($channel) . "\r\n"; } if (isset($variable, $value)) { $cmd .= "Variable: " . trim($variable) . "\r\n" . "Value: " . trim($value) . "\r\n"; $this->command($cmd, $cb); } }
[ "public", "function", "setVar", "(", "$", "channel", ",", "$", "variable", ",", "$", "value", ",", "$", "cb", ")", "{", "$", "cmd", "=", "\"Action: SetVar\\r\\n\"", ";", "if", "(", "$", "channel", ")", "{", "$", "cmd", ".=", "\"Channel: \"", ".", "tr...
Action: Setvar Synopsis: Set Channel Variable Privilege: call,all Description: Set a global or local channel variable. Variables: (Names marked with * are required) Channel: Channel to set variable for *Variable: Variable name *Value: Value @param string $channel @param string $variable @param string $value @param callable $cb @callback $cb ( Connection $conn, array $packet ) @return void
[ "Action", ":", "Setvar", "Synopsis", ":", "Set", "Channel", "Variable", "Privilege", ":", "call", "all", "Description", ":", "Set", "a", "global", "or", "local", "channel", "variable", ".", "Variables", ":", "(", "Names", "marked", "with", "*", "are", "req...
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Asterisk/Connection.php#L465-L479
kakserpom/phpdaemon
PHPDaemon/Clients/Asterisk/Connection.php
Connection.status
public function status($cb, $channel = null) { $cmd = "Action: Status\r\n"; if ($channel !== null) { $cmd .= 'Channel: ' . trim($channel) . "\r\n"; } $this->command($cmd, $cb, ['event' => 'statuscomplete']); }
php
public function status($cb, $channel = null) { $cmd = "Action: Status\r\n"; if ($channel !== null) { $cmd .= 'Channel: ' . trim($channel) . "\r\n"; } $this->command($cmd, $cb, ['event' => 'statuscomplete']); }
[ "public", "function", "status", "(", "$", "cb", ",", "$", "channel", "=", "null", ")", "{", "$", "cmd", "=", "\"Action: Status\\r\\n\"", ";", "if", "(", "$", "channel", "!==", "null", ")", "{", "$", "cmd", ".=", "'Channel: '", ".", "trim", "(", "$", ...
Action: Status Synopsis: Lists channel status Privilege: system,call,reporting,all Description: Lists channel status along with requested channel vars. Variables: (Names marked with * are required) Channel: Name of the channel to query for status Variables: Comma ',' separated list of variables to include ActionID: Optional ID for this transaction Will return the status information of each channel along with the value for the specified channel variables. @param callable $cb @param string $channel @callback $cb ( Connection $conn, array $packet ) @return void
[ "Action", ":", "Status", "Synopsis", ":", "Lists", "channel", "status", "Privilege", ":", "system", "call", "reporting", "all", "Description", ":", "Lists", "channel", "status", "along", "with", "requested", "channel", "vars", ".", "Variables", ":", "(", "Name...
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Asterisk/Connection.php#L520-L529
kakserpom/phpdaemon
PHPDaemon/Clients/Asterisk/Connection.php
Connection.originate
public function originate(array $params, $cb) { $params['Async'] = 1; $this->command("Action: Originate\r\n" . $this->implodeParams($params), $cb); }
php
public function originate(array $params, $cb) { $params['Async'] = 1; $this->command("Action: Originate\r\n" . $this->implodeParams($params), $cb); }
[ "public", "function", "originate", "(", "array", "$", "params", ",", "$", "cb", ")", "{", "$", "params", "[", "'Async'", "]", "=", "1", ";", "$", "this", "->", "command", "(", "\"Action: Originate\\r\\n\"", ".", "$", "this", "->", "implodeParams", "(", ...
Action: Originate Synopsis: Originate a call Privilege: call,all Description: first the Channel is rung. Then, when that answers, the Extension is dialled within the Context to initiate the other end of the call. Variables: (Names marked with * are required) *Channel: Channel on which to originate the call (The same as you specify in the Dial application command) *Context: Context to use on connect (must use Exten & Priority with it) *Exten: Extension to use on connect (must use Context & Priority with it) *Priority: Priority to use on connect (must use Context & Exten with it) Timeout: Timeout (in milliseconds) for the originating connection to happen(defaults to 30000 milliseconds) *CallerID: CallerID to use for the call Variable: Channels variables to set (max 32). Variables will be set for both channels (local and connected). Account: Account code for the call Application: Application to use on connect (use Data for parameters) Data : Data if Application parameter is used ActionID: Optional Action id for message matching. @param array $params @param callable $cb Callback called when response received @callback $cb ( Connection $conn, array $packet ) @return void
[ "Action", ":", "Originate", "Synopsis", ":", "Originate", "a", "call", "Privilege", ":", "call", "all", "Description", ":", "first", "the", "Channel", "is", "rung", ".", "Then", "when", "that", "answers", "the", "Extension", "is", "dialled", "within", "the",...
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Asterisk/Connection.php#L578-L583
kakserpom/phpdaemon
PHPDaemon/Clients/Asterisk/Connection.php
Connection.action
public function action($action, $cb, array $params = null, array $assertion = null) { $action = trim($action); $this->command("Action: {$action}\r\n" . ($params ? $this->implodeParams($params) : ''), $cb, $assertion); }
php
public function action($action, $cb, array $params = null, array $assertion = null) { $action = trim($action); $this->command("Action: {$action}\r\n" . ($params ? $this->implodeParams($params) : ''), $cb, $assertion); }
[ "public", "function", "action", "(", "$", "action", ",", "$", "cb", ",", "array", "$", "params", "=", "null", ",", "array", "$", "assertion", "=", "null", ")", "{", "$", "action", "=", "trim", "(", "$", "action", ")", ";", "$", "this", "->", "com...
For almost any actions in Action: ListCommands Privilege: depends on $action @param string $action Action @param callable $cb Callback called when response received @param array $params Parameters @param array $assertion If more events may follow as response this is a main part or full an action complete event indicating that all data has been sent @callback $cb ( Connection $conn, array $packet ) @return void
[ "For", "almost", "any", "actions", "in", "Action", ":", "ListCommands", "Privilege", ":", "depends", "on", "$action" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Asterisk/Connection.php#L630-L635
kakserpom/phpdaemon
PHPDaemon/Clients/Asterisk/Connection.php
Connection.command
protected function command($packet, $cb, $assertion = null) { if ($this->finished) { throw new ConnectionFinished; } if ($this->state !== self::CONN_STATE_HANDSHAKED_OK) { return; } $actionId = Daemon::uniqid(); if (!is_callable($cb, true)) { $cb = false; } $this->callbacks[$actionId] = CallbackWrapper::wrap($cb); if ($assertion !== null) { $this->assertions[$actionId] = $assertion; } $this->write($packet); $this->write('ActionID: ' . $actionId . "\r\n\r\n"); }
php
protected function command($packet, $cb, $assertion = null) { if ($this->finished) { throw new ConnectionFinished; } if ($this->state !== self::CONN_STATE_HANDSHAKED_OK) { return; } $actionId = Daemon::uniqid(); if (!is_callable($cb, true)) { $cb = false; } $this->callbacks[$actionId] = CallbackWrapper::wrap($cb); if ($assertion !== null) { $this->assertions[$actionId] = $assertion; } $this->write($packet); $this->write('ActionID: ' . $actionId . "\r\n\r\n"); }
[ "protected", "function", "command", "(", "$", "packet", ",", "$", "cb", ",", "$", "assertion", "=", "null", ")", "{", "if", "(", "$", "this", "->", "finished", ")", "{", "throw", "new", "ConnectionFinished", ";", "}", "if", "(", "$", "this", "->", ...
Sends arbitrary command @param string $packet A packet for sending by the connected client to Asterisk @param callable $cb Callback called when response received @param array $assertion If more events may follow as response this is a main part or full an action complete event indicating that all data has been sent
[ "Sends", "arbitrary", "command" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Asterisk/Connection.php#L670-L694
kakserpom/phpdaemon
PHPDaemon/Clients/Asterisk/Connection.php
Connection.implodeParams
protected function implodeParams(array $params) { $s = ''; foreach ($params as $header => $value) { $s .= trim($header) . ": " . trim($value) . "\r\n"; } return $s; }
php
protected function implodeParams(array $params) { $s = ''; foreach ($params as $header => $value) { $s .= trim($header) . ": " . trim($value) . "\r\n"; } return $s; }
[ "protected", "function", "implodeParams", "(", "array", "$", "params", ")", "{", "$", "s", "=", "''", ";", "foreach", "(", "$", "params", "as", "$", "header", "=>", "$", "value", ")", "{", "$", "s", ".=", "trim", "(", "$", "header", ")", ".", "\"...
Generate AMI packet string from associative array provided @param array $params @return string
[ "Generate", "AMI", "packet", "string", "from", "associative", "array", "provided" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Asterisk/Connection.php#L701-L710
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Input.php
Input.unfreeze
public function unfreeze($at_front = false) { $f = $this->frozen; $this->frozen = false; //parent::unfreeze($at_front); // @TODO: discuss related pecl-event/libevent bug $this->onRead(); if ($f && $this->EOF) { $this->onEOF(); } $this->req->checkIfReady(); }
php
public function unfreeze($at_front = false) { $f = $this->frozen; $this->frozen = false; //parent::unfreeze($at_front); // @TODO: discuss related pecl-event/libevent bug $this->onRead(); if ($f && $this->EOF) { $this->onEOF(); } $this->req->checkIfReady(); }
[ "public", "function", "unfreeze", "(", "$", "at_front", "=", "false", ")", "{", "$", "f", "=", "$", "this", "->", "frozen", ";", "$", "this", "->", "frozen", "=", "false", ";", "//parent::unfreeze($at_front); // @TODO: discuss related pecl-event/libevent bug", "$"...
Unfreeze input @param boolean $at_front At front. Default is true. If the front of a buffer is frozen, operations that drain data from the front of the buffer, or that prepend data to the buffer, will fail until it is unfrozen. If the back a buffer is frozen, operations that append data from the buffer will fail until it is unfrozen @return void
[ "Unfreeze", "input" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Input.php#L100-L110
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Input.php
Input.onRead
protected function onRead() { if (!empty($this->boundary)) { $this->req->attrs->input->parseMultipart(); } if (($this->req->attrs->contentLength <= $this->readed) && !$this->EOF) { $this->sendEOF(); } }
php
protected function onRead() { if (!empty($this->boundary)) { $this->req->attrs->input->parseMultipart(); } if (($this->req->attrs->contentLength <= $this->readed) && !$this->EOF) { $this->sendEOF(); } }
[ "protected", "function", "onRead", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "boundary", ")", ")", "{", "$", "this", "->", "req", "->", "attrs", "->", "input", "->", "parseMultipart", "(", ")", ";", "}", "if", "(", "(", "$",...
onRead @return void
[ "onRead" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Input.php#L116-L124
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Input.php
Input.onEOF
protected function onEOF() { if (!$this->req) { return; } if ($this->frozen) { return; } if ($this->req->attrs->inputDone) { return; } $this->curPart =& $foo; $this->req->attrs->inputDone = true; $this->req->attrs->raw = ''; if (($l = $this->length) > 0) { $this->req->attrs->raw = $this->read($l); if (isset($this->req->contype['application/x-www-form-urlencoded'])) { Generic::parseStr($this->req->attrs->raw, $this->req->attrs->post); } if (isset($this->req->contype['application/json']) || isset($this->req->contype['application/x-json'])) { $this->req->attrs->post = json_decode($this->req->attrs->raw, true); } } $this->req->postPrepare(); $this->req->checkIfReady(); }
php
protected function onEOF() { if (!$this->req) { return; } if ($this->frozen) { return; } if ($this->req->attrs->inputDone) { return; } $this->curPart =& $foo; $this->req->attrs->inputDone = true; $this->req->attrs->raw = ''; if (($l = $this->length) > 0) { $this->req->attrs->raw = $this->read($l); if (isset($this->req->contype['application/x-www-form-urlencoded'])) { Generic::parseStr($this->req->attrs->raw, $this->req->attrs->post); } if (isset($this->req->contype['application/json']) || isset($this->req->contype['application/x-json'])) { $this->req->attrs->post = json_decode($this->req->attrs->raw, true); } } $this->req->postPrepare(); $this->req->checkIfReady(); }
[ "protected", "function", "onEOF", "(", ")", "{", "if", "(", "!", "$", "this", "->", "req", ")", "{", "return", ";", "}", "if", "(", "$", "this", "->", "frozen", ")", "{", "return", ";", "}", "if", "(", "$", "this", "->", "req", "->", "attrs", ...
onEOF @return void
[ "onEOF" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Input.php#L142-L167
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Input.php
Input.readFromBuffer
public function readFromBuffer(\EventBuffer $buf) { if (!$this->req) { return false; } $n = min($this->req->attrs->contentLength - $this->readed, $buf->length); if ($n > 0) { $m = $this->appendFrom($buf, $n); $this->readed += $m; if ($m > 0) { $this->onRead(); } } else { $this->onRead(); return 0; } return $m; }
php
public function readFromBuffer(\EventBuffer $buf) { if (!$this->req) { return false; } $n = min($this->req->attrs->contentLength - $this->readed, $buf->length); if ($n > 0) { $m = $this->appendFrom($buf, $n); $this->readed += $m; if ($m > 0) { $this->onRead(); } } else { $this->onRead(); return 0; } return $m; }
[ "public", "function", "readFromBuffer", "(", "\\", "EventBuffer", "$", "buf", ")", "{", "if", "(", "!", "$", "this", "->", "req", ")", "{", "return", "false", ";", "}", "$", "n", "=", "min", "(", "$", "this", "->", "req", "->", "attrs", "->", "co...
Moves $n bytes from input buffer to arbitrary buffer @param \EventBuffer $buf Source nuffer @return integer
[ "Moves", "$n", "bytes", "from", "input", "buffer", "to", "arbitrary", "buffer" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Input.php#L202-L219
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Input.php
Input.readFromString
public function readFromString($chunk, $final = true) { $this->add($chunk); $this->readed += mb_orig_strlen($chunk); if ($final) { $this->onRead(); } }
php
public function readFromString($chunk, $final = true) { $this->add($chunk); $this->readed += mb_orig_strlen($chunk); if ($final) { $this->onRead(); } }
[ "public", "function", "readFromString", "(", "$", "chunk", ",", "$", "final", "=", "true", ")", "{", "$", "this", "->", "add", "(", "$", "chunk", ")", ";", "$", "this", "->", "readed", "+=", "mb_orig_strlen", "(", "$", "chunk", ")", ";", "if", "(",...
Append string to input buffer @param string $chunk Piece of request input @param boolean $final Final call is THIS SEQUENCE of calls (not mandatory final in request)? @return void
[ "Append", "string", "to", "input", "buffer" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Input.php#L227-L234
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Input.php
Input.look
public function look($n, $o = 0) { if ($this->length <= $o) { return ''; } return $this->substr($o, $n); }
php
public function look($n, $o = 0) { if ($this->length <= $o) { return ''; } return $this->substr($o, $n); }
[ "public", "function", "look", "(", "$", "n", ",", "$", "o", "=", "0", ")", "{", "if", "(", "$", "this", "->", "length", "<=", "$", "o", ")", "{", "return", "''", ";", "}", "return", "$", "this", "->", "substr", "(", "$", "o", ",", "$", "n",...
Read from buffer without draining @param integer $n Number of bytes to read @param integer $o Offset @return string
[ "Read", "from", "buffer", "without", "draining" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Input.php#L243-L249
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Input.php
Input.parseMultipart
public function parseMultipart() { start: if ($this->frozen) { return; } if ($this->state === self::STATE_SEEKBOUNDARY) { // seek to the nearest boundary if (($p = $this->search('--' . $this->boundary . "\r\n")) === false) { return; } // we have found the nearest boundary at position $p if ($p > 0) { $extra = $this->read($p); if ($extra !== "\r\n") { $this->log('parseBody(): SEEKBOUNDARY: got unexpected data before boundary (length = ' . $p . '): ' . Debug::exportBytes($extra)); } } $this->drain(mb_orig_strlen($this->boundary) + 4); // drain $this->state = self::STATE_HEADERS; } if ($this->state === self::STATE_HEADERS) { // parse the part's headers $this->curPartDisp = false; $i = 0; do { $l = $this->readline(\EventBuffer::EOL_CRLF); if ($l === null) { return; } if ($l === '') { break; } $e = explode(':', $l, 2); $e[0] = strtr(strtoupper($e[0]), Generic::$htr); if (isset($e[1])) { $e[1] = ltrim($e[1]); } if (($e[0] === 'CONTENT_DISPOSITION') && isset($e[1])) { Generic::parseStr($e[1], $this->curPartDisp, true); if (!isset($this->curPartDisp['form-data'])) { break; } if (!isset($this->curPartDisp['name'])) { break; } $this->curPartDisp['name'] = trim($this->curPartDisp['name'], '"'); $name = $this->curPartDisp['name']; if (isset($this->curPartDisp['filename'])) { $this->curPartDisp['filename'] = trim($this->curPartDisp['filename'], '"'); if (!ini_get('file_uploads')) { break; } $this->req->attrs->files[$name] = [ 'name' => $this->curPartDisp['filename'], 'type' => '', 'tmp_name' => null, 'fp' => null, 'error' => UPLOAD_ERR_OK, 'size' => 0, ]; $this->curPart = &$this->req->attrs->files[$name]; $this->req->onUploadFileStart($this); $this->state = self::STATE_UPLOAD; } else { $this->curPart = &$this->req->attrs->post[$name]; $this->curPart = ''; } } elseif (($e[0] === 'CONTENT_TYPE') && isset($e[1])) { if (isset($this->curPartDisp['name']) && isset($this->curPartDisp['filename'])) { $this->curPart['type'] = $e[1]; } } } while ($i++ < 10); if ($this->state === self::STATE_HEADERS) { $this->state = self::STATE_BODY; } goto start; } if (($this->state === self::STATE_BODY) || ($this->state === self::STATE_UPLOAD)) { // process the body $chunkEnd1 = $this->search("\r\n--" . $this->boundary . "\r\n"); $chunkEnd2 = $this->search("\r\n--" . $this->boundary . "--\r\n"); if ($chunkEnd1 === false && $chunkEnd2 === false) { /* we have only piece of Part in buffer */ $l = $this->length - mb_orig_strlen($this->boundary) - 8; if ($l <= 0) { return; } if (($this->state === self::STATE_BODY) && isset($this->curPartDisp['name'])) { $this->curPart .= $this->read($l); } elseif (($this->state === self::STATE_UPLOAD) && isset($this->curPartDisp['filename'])) { $this->curPart['size'] += $l; if ($this->req->getUploadMaxSize() < $this->curPart['size']) { $this->curPart['error'] = UPLOAD_ERR_INI_SIZE; $this->req->header('413 Request Entity Too Large'); $this->req->out(''); $this->req->finish(); } elseif ($this->maxFileSize && ($this->maxFileSize < $this->curPart['size'])) { $this->curPart['error'] = UPLOAD_ERR_FORM_SIZE; $this->req->header('413 Request Entity Too Large'); $this->req->out(''); $this->req->finish(); } else { $this->curChunkSize = $l; $this->req->onUploadFileChunk($this); } } } else { /* we have entire Part in buffer */ if ($chunkEnd1 === false) { $l = $chunkEnd2; $endOfMsg = true; } else { $l = $chunkEnd1; $endOfMsg = false; } if (($this->state === self::STATE_BODY) && isset($this->curPartDisp['name'])) { $this->curPart .= $this->read($l); if ($this->curPartDisp['name'] === 'MAX_FILE_SIZE') { $this->maxFileSize = (int)$this->curPart; } } elseif (($this->state === self::STATE_UPLOAD) && isset($this->curPartDisp['filename'])) { $this->curPart['size'] += $l; $this->curChunkSize = $l; $this->req->onUploadFileChunk($this, true); } $this->state = self::STATE_SEEKBOUNDARY; if ($endOfMsg) { // end of whole message $this->sendEOF(); } else { goto start; // let's read the next part } } } }
php
public function parseMultipart() { start: if ($this->frozen) { return; } if ($this->state === self::STATE_SEEKBOUNDARY) { // seek to the nearest boundary if (($p = $this->search('--' . $this->boundary . "\r\n")) === false) { return; } // we have found the nearest boundary at position $p if ($p > 0) { $extra = $this->read($p); if ($extra !== "\r\n") { $this->log('parseBody(): SEEKBOUNDARY: got unexpected data before boundary (length = ' . $p . '): ' . Debug::exportBytes($extra)); } } $this->drain(mb_orig_strlen($this->boundary) + 4); // drain $this->state = self::STATE_HEADERS; } if ($this->state === self::STATE_HEADERS) { // parse the part's headers $this->curPartDisp = false; $i = 0; do { $l = $this->readline(\EventBuffer::EOL_CRLF); if ($l === null) { return; } if ($l === '') { break; } $e = explode(':', $l, 2); $e[0] = strtr(strtoupper($e[0]), Generic::$htr); if (isset($e[1])) { $e[1] = ltrim($e[1]); } if (($e[0] === 'CONTENT_DISPOSITION') && isset($e[1])) { Generic::parseStr($e[1], $this->curPartDisp, true); if (!isset($this->curPartDisp['form-data'])) { break; } if (!isset($this->curPartDisp['name'])) { break; } $this->curPartDisp['name'] = trim($this->curPartDisp['name'], '"'); $name = $this->curPartDisp['name']; if (isset($this->curPartDisp['filename'])) { $this->curPartDisp['filename'] = trim($this->curPartDisp['filename'], '"'); if (!ini_get('file_uploads')) { break; } $this->req->attrs->files[$name] = [ 'name' => $this->curPartDisp['filename'], 'type' => '', 'tmp_name' => null, 'fp' => null, 'error' => UPLOAD_ERR_OK, 'size' => 0, ]; $this->curPart = &$this->req->attrs->files[$name]; $this->req->onUploadFileStart($this); $this->state = self::STATE_UPLOAD; } else { $this->curPart = &$this->req->attrs->post[$name]; $this->curPart = ''; } } elseif (($e[0] === 'CONTENT_TYPE') && isset($e[1])) { if (isset($this->curPartDisp['name']) && isset($this->curPartDisp['filename'])) { $this->curPart['type'] = $e[1]; } } } while ($i++ < 10); if ($this->state === self::STATE_HEADERS) { $this->state = self::STATE_BODY; } goto start; } if (($this->state === self::STATE_BODY) || ($this->state === self::STATE_UPLOAD)) { // process the body $chunkEnd1 = $this->search("\r\n--" . $this->boundary . "\r\n"); $chunkEnd2 = $this->search("\r\n--" . $this->boundary . "--\r\n"); if ($chunkEnd1 === false && $chunkEnd2 === false) { /* we have only piece of Part in buffer */ $l = $this->length - mb_orig_strlen($this->boundary) - 8; if ($l <= 0) { return; } if (($this->state === self::STATE_BODY) && isset($this->curPartDisp['name'])) { $this->curPart .= $this->read($l); } elseif (($this->state === self::STATE_UPLOAD) && isset($this->curPartDisp['filename'])) { $this->curPart['size'] += $l; if ($this->req->getUploadMaxSize() < $this->curPart['size']) { $this->curPart['error'] = UPLOAD_ERR_INI_SIZE; $this->req->header('413 Request Entity Too Large'); $this->req->out(''); $this->req->finish(); } elseif ($this->maxFileSize && ($this->maxFileSize < $this->curPart['size'])) { $this->curPart['error'] = UPLOAD_ERR_FORM_SIZE; $this->req->header('413 Request Entity Too Large'); $this->req->out(''); $this->req->finish(); } else { $this->curChunkSize = $l; $this->req->onUploadFileChunk($this); } } } else { /* we have entire Part in buffer */ if ($chunkEnd1 === false) { $l = $chunkEnd2; $endOfMsg = true; } else { $l = $chunkEnd1; $endOfMsg = false; } if (($this->state === self::STATE_BODY) && isset($this->curPartDisp['name'])) { $this->curPart .= $this->read($l); if ($this->curPartDisp['name'] === 'MAX_FILE_SIZE') { $this->maxFileSize = (int)$this->curPart; } } elseif (($this->state === self::STATE_UPLOAD) && isset($this->curPartDisp['filename'])) { $this->curPart['size'] += $l; $this->curChunkSize = $l; $this->req->onUploadFileChunk($this, true); } $this->state = self::STATE_SEEKBOUNDARY; if ($endOfMsg) { // end of whole message $this->sendEOF(); } else { goto start; // let's read the next part } } } }
[ "public", "function", "parseMultipart", "(", ")", "{", "start", ":", "if", "(", "$", "this", "->", "frozen", ")", "{", "return", ";", "}", "if", "(", "$", "this", "->", "state", "===", "self", "::", "STATE_SEEKBOUNDARY", ")", "{", "// seek to the nearest...
Parses multipart @return void
[ "Parses", "multipart" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Input.php#L256-L394
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Input.php
Input.getChunkString
public function getChunkString() { if (!$this->curChunkSize) { return false; } $chunk = $this->read($this->curChunkSize); $this->curChunkSize = null; return $chunk; }
php
public function getChunkString() { if (!$this->curChunkSize) { return false; } $chunk = $this->read($this->curChunkSize); $this->curChunkSize = null; return $chunk; }
[ "public", "function", "getChunkString", "(", ")", "{", "if", "(", "!", "$", "this", "->", "curChunkSize", ")", "{", "return", "false", ";", "}", "$", "chunk", "=", "$", "this", "->", "read", "(", "$", "this", "->", "curChunkSize", ")", ";", "$", "t...
Get current upload chunk as string @return string Chunk body
[ "Get", "current", "upload", "chunk", "as", "string" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Input.php#L410-L418
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Input.php
Input.writeChunkToFd
public function writeChunkToFd($fd, $cb = null) { return false; // It is not supported yet (callback missing in EventBuffer->write()) if (!$this->curChunkSize) { return false; } $this->write($fd, $this->curChunkSize); $this->curChunkSize = null; return true; }
php
public function writeChunkToFd($fd, $cb = null) { return false; // It is not supported yet (callback missing in EventBuffer->write()) if (!$this->curChunkSize) { return false; } $this->write($fd, $this->curChunkSize); $this->curChunkSize = null; return true; }
[ "public", "function", "writeChunkToFd", "(", "$", "fd", ",", "$", "cb", "=", "null", ")", "{", "return", "false", ";", "// It is not supported yet (callback missing in EventBuffer->write())", "if", "(", "!", "$", "this", "->", "curChunkSize", ")", "{", "return", ...
Write current upload chunk to file descriptor @todo It is not supported yet (callback missing in EventBuffer->write()) @param mixed $fd File destriptor @param callable $cb Callback @return boolean Success
[ "Write", "current", "upload", "chunk", "to", "file", "descriptor" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Input.php#L427-L436
kakserpom/phpdaemon
PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Channel/ChannelCloseFrame.php
ChannelCloseFrame.create
public static function create( $replyCode = null, $replyText = null, $classId = null, $methodId = null ) { $frame = new self(); if (null !== $replyCode) { $frame->replyCode = $replyCode; } if (null !== $replyText) { $frame->replyText = $replyText; } if (null !== $classId) { $frame->classId = $classId; } if (null !== $methodId) { $frame->methodId = $methodId; } return $frame; }
php
public static function create( $replyCode = null, $replyText = null, $classId = null, $methodId = null ) { $frame = new self(); if (null !== $replyCode) { $frame->replyCode = $replyCode; } if (null !== $replyText) { $frame->replyText = $replyText; } if (null !== $classId) { $frame->classId = $classId; } if (null !== $methodId) { $frame->methodId = $methodId; } return $frame; }
[ "public", "static", "function", "create", "(", "$", "replyCode", "=", "null", ",", "$", "replyText", "=", "null", ",", "$", "classId", "=", "null", ",", "$", "methodId", "=", "null", ")", "{", "$", "frame", "=", "new", "self", "(", ")", ";", "if", ...
short
[ "short" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Channel/ChannelCloseFrame.php#L24-L44
kakserpom/phpdaemon
PHPDaemon/Clients/DNS/Pool.php
Pool.applyConfig
public function applyConfig() { parent::applyConfig(); $pool = $this; if (!isset($this->preloading)) { $this->preloading = new ComplexJob(); } $job = $this->preloading; $job->addJob('resolvfile', function ($jobname, $job) use ($pool) { FileSystem::readfile($pool->config->resolvfile->value, function ($file, $data) use ($pool, $job, $jobname) { if ($file) { foreach (explode("\n", $data) as $line) { $line = trim($line); if ($line !== '' && $line[0] !== '#' && preg_match('~nameserver ([^\r\n;]+)~i', $line, $m)) { $pool->nameServers[] = $m[1]; } } } $job->setResult($jobname); }); }); $job->addJob('hostsfile', function ($jobname, $job) use ($pool) { FileSystem::readfile($pool->config->hostsfile->value, function ($file, $data) use ($pool, $job, $jobname) { if ($file) { preg_match_all('~^([^#]\S+)\s+([^\r\n]+)\s*~m', $data, $m, PREG_SET_ORDER); $pool->hosts = []; foreach ($m as $h) { $hosts = preg_split('~\s+~', $h[2]); $ip = $h[1]; /* skip commentened ips */ if (preg_match('~^[\s]*?#~m', $ip)) { continue; } foreach ($hosts as $host) { $host = rtrim($host, '.') . '.'; $pool->hosts[$host][] = $ip; } } } $job->setResult($jobname); }); }); $job(); }
php
public function applyConfig() { parent::applyConfig(); $pool = $this; if (!isset($this->preloading)) { $this->preloading = new ComplexJob(); } $job = $this->preloading; $job->addJob('resolvfile', function ($jobname, $job) use ($pool) { FileSystem::readfile($pool->config->resolvfile->value, function ($file, $data) use ($pool, $job, $jobname) { if ($file) { foreach (explode("\n", $data) as $line) { $line = trim($line); if ($line !== '' && $line[0] !== '#' && preg_match('~nameserver ([^\r\n;]+)~i', $line, $m)) { $pool->nameServers[] = $m[1]; } } } $job->setResult($jobname); }); }); $job->addJob('hostsfile', function ($jobname, $job) use ($pool) { FileSystem::readfile($pool->config->hostsfile->value, function ($file, $data) use ($pool, $job, $jobname) { if ($file) { preg_match_all('~^([^#]\S+)\s+([^\r\n]+)\s*~m', $data, $m, PREG_SET_ORDER); $pool->hosts = []; foreach ($m as $h) { $hosts = preg_split('~\s+~', $h[2]); $ip = $h[1]; /* skip commentened ips */ if (preg_match('~^[\s]*?#~m', $ip)) { continue; } foreach ($hosts as $host) { $host = rtrim($host, '.') . '.'; $pool->hosts[$host][] = $ip; } } } $job->setResult($jobname); }); }); $job(); }
[ "public", "function", "applyConfig", "(", ")", "{", "parent", "::", "applyConfig", "(", ")", ";", "$", "pool", "=", "$", "this", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "preloading", ")", ")", "{", "$", "this", "->", "preloading", "="...
Applies config @return void
[ "Applies", "config" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/DNS/Pool.php#L158-L201
kakserpom/phpdaemon
PHPDaemon/Clients/DNS/Pool.php
Pool.resolve
public function resolve($hostname, $cb, $noncache = false, $nameServers = []) { if (!$this->preloading->hasCompleted()) { $pool = $this; $this->preloading->addListener(function ($job) use ($hostname, $cb, $noncache, $pool, $nameServers) { $pool->resolve($hostname, $cb, $noncache, $nameServers); }); return; } $hostname = rtrim($hostname, '.') . '.'; if (isset($this->hosts[$hostname])) { $cb($this->hosts[$hostname]); return; } if (!$noncache && ($item = $this->resolveCache->get($hostname))) { // cache hit $ip = $item->getValue(); if ($ip === null) { // operation in progress $item->addListener($cb); } else { // hit $cb($ip); } return; } elseif (!$noncache) { $item = $this->resolveCache->put($hostname, null); $item->addListener($cb); } $pool = $this; $this->get($hostname, function ($response) use ($cb, $noncache, $hostname, $pool) { if (!isset($response['A'])) { if ($noncache) { $cb(false); } else { $pool->resolveCache->put($hostname, false, 5); // 5 - TTL of unsuccessful request } return; } if (!isset($response['A']) && !isset($response['AAAA'])) { $cb(false); return; } $addrs = []; $ttl = 0; if (isset($response['A'])) { foreach ($response['A'] as $r) { $addrs[] = $r['ip']; $ttl = $r['ttl']; } } if (isset($response['AAAA'])) { foreach ($response['AAAA'] as $r) { $addrs[] = $r['ip']; $ttl = $r['ttl']; } } if (sizeof($addrs) === 1) { $addrs = $addrs[0]; } if ($noncache) { $cb($addrs); } else { $pool->resolveCache->put($hostname, $addrs, $ttl); } }, $noncache, $nameServers); }
php
public function resolve($hostname, $cb, $noncache = false, $nameServers = []) { if (!$this->preloading->hasCompleted()) { $pool = $this; $this->preloading->addListener(function ($job) use ($hostname, $cb, $noncache, $pool, $nameServers) { $pool->resolve($hostname, $cb, $noncache, $nameServers); }); return; } $hostname = rtrim($hostname, '.') . '.'; if (isset($this->hosts[$hostname])) { $cb($this->hosts[$hostname]); return; } if (!$noncache && ($item = $this->resolveCache->get($hostname))) { // cache hit $ip = $item->getValue(); if ($ip === null) { // operation in progress $item->addListener($cb); } else { // hit $cb($ip); } return; } elseif (!$noncache) { $item = $this->resolveCache->put($hostname, null); $item->addListener($cb); } $pool = $this; $this->get($hostname, function ($response) use ($cb, $noncache, $hostname, $pool) { if (!isset($response['A'])) { if ($noncache) { $cb(false); } else { $pool->resolveCache->put($hostname, false, 5); // 5 - TTL of unsuccessful request } return; } if (!isset($response['A']) && !isset($response['AAAA'])) { $cb(false); return; } $addrs = []; $ttl = 0; if (isset($response['A'])) { foreach ($response['A'] as $r) { $addrs[] = $r['ip']; $ttl = $r['ttl']; } } if (isset($response['AAAA'])) { foreach ($response['AAAA'] as $r) { $addrs[] = $r['ip']; $ttl = $r['ttl']; } } if (sizeof($addrs) === 1) { $addrs = $addrs[0]; } if ($noncache) { $cb($addrs); } else { $pool->resolveCache->put($hostname, $addrs, $ttl); } }, $noncache, $nameServers); }
[ "public", "function", "resolve", "(", "$", "hostname", ",", "$", "cb", ",", "$", "noncache", "=", "false", ",", "$", "nameServers", "=", "[", "]", ")", "{", "if", "(", "!", "$", "this", "->", "preloading", "->", "hasCompleted", "(", ")", ")", "{", ...
Resolves the host @param string $hostname Hostname @param callable $cb Callback @param boolean $noncache Noncache? @param array $nameServers @callback $cb ( array|string $addrs ) @return void
[ "Resolves", "the", "host" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/DNS/Pool.php#L212-L275
kakserpom/phpdaemon
PHPDaemon/Clients/DNS/Pool.php
Pool.get
public function get($hostname, $cb, $noncache = false, $nameServers = [], $proto = 'udp') { $pool = $this; if (!$nameServers) { $nameServers = $this->nameServers; } if (!$this->preloading->hasCompleted()) { $this->preloading->addListener(function ($job) use ( $hostname, $cb, $noncache, $pool, $nameServers, $proto ) { $pool->get($hostname, $cb, $noncache, $nameServers, $proto); }); return; } $nameServer = reset($nameServers); $isIpv6 = filter_var($nameServer, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); if ($isIpv6) { $nameServer = '[' . $nameServer . ']'; } $onGetConnection = function ($conn) use ($cb, $hostname, $nameServers, $noncache, $pool, $proto) { if (!$conn || !$conn->isConnected()) { if ($proto === 'udp') { //Fail to connect via udp, trying by tcp $pool->get($hostname, $cb, $noncache, $nameServers, 'tcp'); return; } array_shift($nameServers); if (!$nameServers) { //Totally fail to resolve name $cb(false); } else { //Fail connect to curr Ns, but we can try another ns $pool->get($hostname, $cb, $noncache, $nameServers, 'udp'); } } else { $conn->get( $hostname, function ($response) use ($hostname, $cb, $proto, $noncache, $nameServers, $pool) { if ($response === false && $proto === 'udp') { //Fail to connect via udp, trying by tcp $pool->get($hostname, $cb, $noncache, $nameServers, 'tcp'); } else { call_user_func($cb, $response); } } ); } }; list($host, $type, $class) = explode(':', $hostname . '::', 3); if ($type === 'AXFR') { $proto = 'tcp'; } $this->getConnection($proto . '://' . $nameServer, $onGetConnection); return; }
php
public function get($hostname, $cb, $noncache = false, $nameServers = [], $proto = 'udp') { $pool = $this; if (!$nameServers) { $nameServers = $this->nameServers; } if (!$this->preloading->hasCompleted()) { $this->preloading->addListener(function ($job) use ( $hostname, $cb, $noncache, $pool, $nameServers, $proto ) { $pool->get($hostname, $cb, $noncache, $nameServers, $proto); }); return; } $nameServer = reset($nameServers); $isIpv6 = filter_var($nameServer, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); if ($isIpv6) { $nameServer = '[' . $nameServer . ']'; } $onGetConnection = function ($conn) use ($cb, $hostname, $nameServers, $noncache, $pool, $proto) { if (!$conn || !$conn->isConnected()) { if ($proto === 'udp') { //Fail to connect via udp, trying by tcp $pool->get($hostname, $cb, $noncache, $nameServers, 'tcp'); return; } array_shift($nameServers); if (!$nameServers) { //Totally fail to resolve name $cb(false); } else { //Fail connect to curr Ns, but we can try another ns $pool->get($hostname, $cb, $noncache, $nameServers, 'udp'); } } else { $conn->get( $hostname, function ($response) use ($hostname, $cb, $proto, $noncache, $nameServers, $pool) { if ($response === false && $proto === 'udp') { //Fail to connect via udp, trying by tcp $pool->get($hostname, $cb, $noncache, $nameServers, 'tcp'); } else { call_user_func($cb, $response); } } ); } }; list($host, $type, $class) = explode(':', $hostname . '::', 3); if ($type === 'AXFR') { $proto = 'tcp'; } $this->getConnection($proto . '://' . $nameServer, $onGetConnection); return; }
[ "public", "function", "get", "(", "$", "hostname", ",", "$", "cb", ",", "$", "noncache", "=", "false", ",", "$", "nameServers", "=", "[", "]", ",", "$", "proto", "=", "'udp'", ")", "{", "$", "pool", "=", "$", "this", ";", "if", "(", "!", "$", ...
Gets the host information @param string $hostname Hostname @param callable $cb Callback @param boolean $noncache Noncache? @param array $nameServers @param string $proto @callback $cb ( ) @return void
[ "Gets", "the", "host", "information" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/DNS/Pool.php#L287-L346
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.preinit
protected function preinit($req) { if ($req === null) { $req = new \stdClass; $req->attrs = new \stdClass; $req->attrs->inputDone = true; $req->attrs->paramsDone = true; $req->attrs->chunked = false; } $this->attrs = $req->attrs; if ($this->upstream->pool->config->expose->value) { $this->header('X-Powered-By: phpDaemon/' . Daemon::$version); } $this->attrs->input->setRequest($this); $this->parseParams(); }
php
protected function preinit($req) { if ($req === null) { $req = new \stdClass; $req->attrs = new \stdClass; $req->attrs->inputDone = true; $req->attrs->paramsDone = true; $req->attrs->chunked = false; } $this->attrs = $req->attrs; if ($this->upstream->pool->config->expose->value) { $this->header('X-Powered-By: phpDaemon/' . Daemon::$version); } $this->attrs->input->setRequest($this); $this->parseParams(); }
[ "protected", "function", "preinit", "(", "$", "req", ")", "{", "if", "(", "$", "req", "===", "null", ")", "{", "$", "req", "=", "new", "\\", "stdClass", ";", "$", "req", "->", "attrs", "=", "new", "\\", "stdClass", ";", "$", "req", "->", "attrs",...
Preparing before init @param object $req Source request @return void
[ "Preparing", "before", "init" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L140-L159
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.sendfile
public function sendfile($path, $cb, $pri = EIO_PRI_DEFAULT) { if ($this->state === self::STATE_FINISHED) { return false; } try { $this->header('Content-Type: ' . MIME::get($path)); } catch (RequestHeadersAlreadySent $e) { } if ($this->upstream->checkSendfileCap()) { FileSystem::sendfile($this->upstream, $path, $cb, function ($file, $length, $handler) { try { $this->header('Content-Length: ' . $length); } catch (RequestHeadersAlreadySent $e) { } $this->ensureSentHeaders(); $this->upstream->onWriteOnce(function ($conn) use ($handler, $file) { $handler($file); }); return true; }, 0, null, $pri); return true; } $first = true; FileSystem::readfileChunked( $path, $cb, function ($file, $chunk) use (&$first) { // readed chunk if ($this->upstream->isFreed()) { return false; } if ($first) { try { $this->header('Content-Length: ' . $file->stat['size']); } catch (RequestHeadersAlreadySent $e) { } $first = false; } $this->out($chunk); return true; } ); return true; }
php
public function sendfile($path, $cb, $pri = EIO_PRI_DEFAULT) { if ($this->state === self::STATE_FINISHED) { return false; } try { $this->header('Content-Type: ' . MIME::get($path)); } catch (RequestHeadersAlreadySent $e) { } if ($this->upstream->checkSendfileCap()) { FileSystem::sendfile($this->upstream, $path, $cb, function ($file, $length, $handler) { try { $this->header('Content-Length: ' . $length); } catch (RequestHeadersAlreadySent $e) { } $this->ensureSentHeaders(); $this->upstream->onWriteOnce(function ($conn) use ($handler, $file) { $handler($file); }); return true; }, 0, null, $pri); return true; } $first = true; FileSystem::readfileChunked( $path, $cb, function ($file, $chunk) use (&$first) { // readed chunk if ($this->upstream->isFreed()) { return false; } if ($first) { try { $this->header('Content-Length: ' . $file->stat['size']); } catch (RequestHeadersAlreadySent $e) { } $first = false; } $this->out($chunk); return true; } ); return true; }
[ "public", "function", "sendfile", "(", "$", "path", ",", "$", "cb", ",", "$", "pri", "=", "EIO_PRI_DEFAULT", ")", "{", "if", "(", "$", "this", "->", "state", "===", "self", "::", "STATE_FINISHED", ")", "{", "return", "false", ";", "}", "try", "{", ...
Output whole contents of file @param string $path Path @param callable $cb Callback @param integer $pri Priority @return boolean Success
[ "Output", "whole", "contents", "of", "file" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L177-L224
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.checkIfReady
public function checkIfReady() { if (!$this->attrs->paramsDone || !$this->attrs->inputDone) { return false; } if (isset($this->appInstance->passphrase)) { if (!isset($this->attrs->server['PASSPHRASE']) || ($this->appInstance->passphrase !== $this->attrs->server['PASSPHRASE']) ) { $this->finish(); } return false; } if ($this->attrs->input->isFrozen()) { return false; } if ($this->sleepTime === 0) { $this->wakeup(); } return true; }
php
public function checkIfReady() { if (!$this->attrs->paramsDone || !$this->attrs->inputDone) { return false; } if (isset($this->appInstance->passphrase)) { if (!isset($this->attrs->server['PASSPHRASE']) || ($this->appInstance->passphrase !== $this->attrs->server['PASSPHRASE']) ) { $this->finish(); } return false; } if ($this->attrs->input->isFrozen()) { return false; } if ($this->sleepTime === 0) { $this->wakeup(); } return true; }
[ "public", "function", "checkIfReady", "(", ")", "{", "if", "(", "!", "$", "this", "->", "attrs", "->", "paramsDone", "||", "!", "$", "this", "->", "attrs", "->", "inputDone", ")", "{", "return", "false", ";", "}", "if", "(", "isset", "(", "$", "thi...
Called to check if Request is ready @return boolean Ready?
[ "Called", "to", "check", "if", "Request", "is", "ready" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L240-L264
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.parseParams
protected function parseParams() { if (!isset($this->attrs->server['HTTP_CONTENT_LENGTH'])) { $this->attrs->contentLength = 0; } else { $this->attrs->contentLength = (int)$this->attrs->server['HTTP_CONTENT_LENGTH']; } if (isset($this->attrs->server['CONTENT_TYPE']) && !isset($this->attrs->server['HTTP_CONTENT_TYPE'])) { $this->attrs->server['HTTP_CONTENT_TYPE'] = $this->attrs->server['CONTENT_TYPE']; } if (isset($this->attrs->server['QUERY_STRING'])) { self::parseStr($this->attrs->server['QUERY_STRING'], $this->attrs->get); } if (isset($this->attrs->server['REQUEST_METHOD']) && ($this->attrs->server['REQUEST_METHOD'] === 'POST' || $this->attrs->server['REQUEST_METHOD'] === 'PUT') && isset($this->attrs->server['HTTP_CONTENT_TYPE']) ) { $this->attrs->server['REQUEST_METHOD_POST'] = true; self::parseStr($this->attrs->server['HTTP_CONTENT_TYPE'], $this->contype, true); $found = false; foreach ($this->contype as $k => $v) { if (mb_orig_strpos($k, '/') === false) { continue; } if (!$found) { $found = true; } else { unset($this->contype[$k]); } } if (isset($this->contype['multipart/form-data']) && (isset($this->contype['boundary'])) ) { $this->attrs->input->setBoundary($this->contype['boundary']); } } else { $this->attrs->server['REQUEST_METHOD_POST'] = false; } if (isset($this->attrs->server['HTTP_COOKIE'])) { self::parseStr($this->attrs->server['HTTP_COOKIE'], $this->attrs->cookie, true); } if (isset($this->attrs->server['HTTP_AUTHORIZATION'])) { $e = explode(' ', $this->attrs->server['HTTP_AUTHORIZATION'], 2); if (($e[0] === 'Basic') && isset($e[1])) { $e[1] = base64_decode($e[1]); $e = explode(':', $e[1], 2); if (isset($e[1])) { list($this->attrs->server['PHP_AUTH_USER'], $this->attrs->server['PHP_AUTH_PW']) = $e; } } } $this->onParsedParams(); }
php
protected function parseParams() { if (!isset($this->attrs->server['HTTP_CONTENT_LENGTH'])) { $this->attrs->contentLength = 0; } else { $this->attrs->contentLength = (int)$this->attrs->server['HTTP_CONTENT_LENGTH']; } if (isset($this->attrs->server['CONTENT_TYPE']) && !isset($this->attrs->server['HTTP_CONTENT_TYPE'])) { $this->attrs->server['HTTP_CONTENT_TYPE'] = $this->attrs->server['CONTENT_TYPE']; } if (isset($this->attrs->server['QUERY_STRING'])) { self::parseStr($this->attrs->server['QUERY_STRING'], $this->attrs->get); } if (isset($this->attrs->server['REQUEST_METHOD']) && ($this->attrs->server['REQUEST_METHOD'] === 'POST' || $this->attrs->server['REQUEST_METHOD'] === 'PUT') && isset($this->attrs->server['HTTP_CONTENT_TYPE']) ) { $this->attrs->server['REQUEST_METHOD_POST'] = true; self::parseStr($this->attrs->server['HTTP_CONTENT_TYPE'], $this->contype, true); $found = false; foreach ($this->contype as $k => $v) { if (mb_orig_strpos($k, '/') === false) { continue; } if (!$found) { $found = true; } else { unset($this->contype[$k]); } } if (isset($this->contype['multipart/form-data']) && (isset($this->contype['boundary'])) ) { $this->attrs->input->setBoundary($this->contype['boundary']); } } else { $this->attrs->server['REQUEST_METHOD_POST'] = false; } if (isset($this->attrs->server['HTTP_COOKIE'])) { self::parseStr($this->attrs->server['HTTP_COOKIE'], $this->attrs->cookie, true); } if (isset($this->attrs->server['HTTP_AUTHORIZATION'])) { $e = explode(' ', $this->attrs->server['HTTP_AUTHORIZATION'], 2); if (($e[0] === 'Basic') && isset($e[1])) { $e[1] = base64_decode($e[1]); $e = explode(':', $e[1], 2); if (isset($e[1])) { list($this->attrs->server['PHP_AUTH_USER'], $this->attrs->server['PHP_AUTH_PW']) = $e; } } } $this->onParsedParams(); }
[ "protected", "function", "parseParams", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "attrs", "->", "server", "[", "'HTTP_CONTENT_LENGTH'", "]", ")", ")", "{", "$", "this", "->", "attrs", "->", "contentLength", "=", "0", ";", "}", ...
Parses GET-query string and other request's headers @return void
[ "Parses", "GET", "-", "query", "string", "and", "other", "request", "s", "headers" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L279-L339
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.postPrepare
public function postPrepare() { if (!$this->attrs->server['REQUEST_METHOD_POST']) { return; } if (isset($this->attrs->server['REQUEST_PREPARED_UPLOADS']) && $this->attrs->server['REQUEST_PREPARED_UPLOADS'] === 'nginx') { if (isset($this->attrs->server['REQUEST_PREPARED_UPLOADS_URL_PREFIX'])) { $URLprefix = $this->attrs->server['REQUEST_PREPARED_UPLOADS_URL_PREFIX']; $l = mb_orig_strlen($URLprefix); foreach (['PHP_SELF', 'REQUEST_URI', 'SCRIPT_NAME', 'DOCUMENT_URI'] as $k) { if (!isset($this->attrs->server[$k])) { continue; } if (strncmp($this->attrs->server[$k], $URLprefix, $l) === 0) { $this->attrs->server[$k] = substr($this->attrs->server[$k], $l - 1); } } } $prefix = 'file.'; $prefixlen = mb_orig_strlen($prefix); foreach ($this->attrs->post as $k => $v) { if (strncmp($k, $prefix, $prefixlen) === 0) { $e = explode('.', substr($k, $prefixlen)); if (!isset($e[1])) { $e = ['file', $e[0]]; } if (!isset($this->attrs->files[$e[0]])) { $this->attrs->files[$e[0]] = ['error' => UPLOAD_ERR_OK]; } $this->attrs->files[$e[0]][$e[1]] = $v; unset($this->attrs->post[$k]); } } $uploadTmp = $this->getUploadTempDir(); foreach ($this->attrs->files as $k => &$file) { if (!isset($file['tmp_name']) || !isset($file['name']) || !ctype_digit(basename($file['tmp_name'])) || (mb_orig_strpos(pathinfo($file['tmp_name'], PATHINFO_DIRNAME), $uploadTmp) !== 0) ) { unset($this->attrs->files[$k]); continue; } FileSystem::open($file['tmp_name'], 'c+!', function ($fp) use (&$file) { if (!$fp) { return; } $file['fp'] = $fp; }); } unset($file); } if (isset($this->attrs->server['REQUEST_BODY_FILE']) && $this->upstream->pool->config->autoreadbodyfile->value ) { $this->readBodyFile(); } }
php
public function postPrepare() { if (!$this->attrs->server['REQUEST_METHOD_POST']) { return; } if (isset($this->attrs->server['REQUEST_PREPARED_UPLOADS']) && $this->attrs->server['REQUEST_PREPARED_UPLOADS'] === 'nginx') { if (isset($this->attrs->server['REQUEST_PREPARED_UPLOADS_URL_PREFIX'])) { $URLprefix = $this->attrs->server['REQUEST_PREPARED_UPLOADS_URL_PREFIX']; $l = mb_orig_strlen($URLprefix); foreach (['PHP_SELF', 'REQUEST_URI', 'SCRIPT_NAME', 'DOCUMENT_URI'] as $k) { if (!isset($this->attrs->server[$k])) { continue; } if (strncmp($this->attrs->server[$k], $URLprefix, $l) === 0) { $this->attrs->server[$k] = substr($this->attrs->server[$k], $l - 1); } } } $prefix = 'file.'; $prefixlen = mb_orig_strlen($prefix); foreach ($this->attrs->post as $k => $v) { if (strncmp($k, $prefix, $prefixlen) === 0) { $e = explode('.', substr($k, $prefixlen)); if (!isset($e[1])) { $e = ['file', $e[0]]; } if (!isset($this->attrs->files[$e[0]])) { $this->attrs->files[$e[0]] = ['error' => UPLOAD_ERR_OK]; } $this->attrs->files[$e[0]][$e[1]] = $v; unset($this->attrs->post[$k]); } } $uploadTmp = $this->getUploadTempDir(); foreach ($this->attrs->files as $k => &$file) { if (!isset($file['tmp_name']) || !isset($file['name']) || !ctype_digit(basename($file['tmp_name'])) || (mb_orig_strpos(pathinfo($file['tmp_name'], PATHINFO_DIRNAME), $uploadTmp) !== 0) ) { unset($this->attrs->files[$k]); continue; } FileSystem::open($file['tmp_name'], 'c+!', function ($fp) use (&$file) { if (!$fp) { return; } $file['fp'] = $fp; }); } unset($file); } if (isset($this->attrs->server['REQUEST_BODY_FILE']) && $this->upstream->pool->config->autoreadbodyfile->value ) { $this->readBodyFile(); } }
[ "public", "function", "postPrepare", "(", ")", "{", "if", "(", "!", "$", "this", "->", "attrs", "->", "server", "[", "'REQUEST_METHOD_POST'", "]", ")", "{", "return", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "attrs", "->", "server", "[",...
Prepares the request body @return void
[ "Prepares", "the", "request", "body" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L345-L402
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.ensureSentHeaders
public function ensureSentHeaders() { if ($this->headers_sent) { return true; } if (isset($this->headers['STATUS'])) { $h = (isset($this->attrs->noHttpVer) && ($this->attrs->noHttpVer) ? 'Status: ' : $this->attrs->server['SERVER_PROTOCOL']) . ' ' . $this->headers['STATUS'] . "\r\n"; } else { $h = ''; } $http11 = $this->attrs->server['SERVER_PROTOCOL'] === 'HTTP/1.1'; if ($this->contentLength === null && $this->upstream->checkChunkedEncCap() && $http11 ) { $this->attrs->chunked = true; } if ($this->attrs->chunked) { $this->header('Transfer-Encoding: chunked'); } if ($http11) { $connection = isset($this->attrs->server['HTTP_CONNECTION']) ? strtolower($this->attrs->server['HTTP_CONNECTION']) : 'keep-alive'; if ($connection === 'keep-alive' && $this->upstream->getKeepaliveTimeout() > 0) { $this->header('Connection: keep-alive'); $this->keepalive = true; } else { $this->header('Connection: close'); } } else { $this->header('Connection: close'); } foreach ($this->headers as $k => $line) { if ($k !== 'STATUS') { $h .= $line . "\r\n"; } } $h .= "\r\n"; $this->headers_sent_file = __FILE__; $this->headers_sent_line = __LINE__; $this->headers_sent = true; $this->upstream->requestOut($this, $h); return false; }
php
public function ensureSentHeaders() { if ($this->headers_sent) { return true; } if (isset($this->headers['STATUS'])) { $h = (isset($this->attrs->noHttpVer) && ($this->attrs->noHttpVer) ? 'Status: ' : $this->attrs->server['SERVER_PROTOCOL']) . ' ' . $this->headers['STATUS'] . "\r\n"; } else { $h = ''; } $http11 = $this->attrs->server['SERVER_PROTOCOL'] === 'HTTP/1.1'; if ($this->contentLength === null && $this->upstream->checkChunkedEncCap() && $http11 ) { $this->attrs->chunked = true; } if ($this->attrs->chunked) { $this->header('Transfer-Encoding: chunked'); } if ($http11) { $connection = isset($this->attrs->server['HTTP_CONNECTION']) ? strtolower($this->attrs->server['HTTP_CONNECTION']) : 'keep-alive'; if ($connection === 'keep-alive' && $this->upstream->getKeepaliveTimeout() > 0) { $this->header('Connection: keep-alive'); $this->keepalive = true; } else { $this->header('Connection: close'); } } else { $this->header('Connection: close'); } foreach ($this->headers as $k => $line) { if ($k !== 'STATUS') { $h .= $line . "\r\n"; } } $h .= "\r\n"; $this->headers_sent_file = __FILE__; $this->headers_sent_line = __LINE__; $this->headers_sent = true; $this->upstream->requestOut($this, $h); return false; }
[ "public", "function", "ensureSentHeaders", "(", ")", "{", "if", "(", "$", "this", "->", "headers_sent", ")", "{", "return", "true", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "headers", "[", "'STATUS'", "]", ")", ")", "{", "$", "h", "=",...
Ensure that headers are sent @return boolean Were already sent?
[ "Ensure", "that", "headers", "are", "sent" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L408-L452
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.out
public function out($s, $flush = true) { if ($flush) { if (!Daemon::$obInStack) { // preventing recursion ob_flush(); } } if ($this->aborted) { return false; } if (!isset($this->upstream)) { return false; } $l = mb_orig_strlen($s); $this->responseLength += $l; $this->ensureSentHeaders(); if ($this->attrs->chunked) { for ($o = 0; $o < $l;) { $c = min($this->upstream->pool->config->chunksize->value, $l - $o); $chunk = dechex($c) . "\r\n" . ($c === $l ? $s : mb_orig_substr($s, $o, $c)) // content . "\r\n"; if ($this->sendfp) { $this->sendfp->write($chunk); } else { $this->upstream->requestOut($this, $chunk); } $o += $c; } return true; } else { if ($this->sendfp) { $this->sendfp->write($s); return true; } if (Daemon::$compatMode) { echo $s; return true; } return $this->upstream->requestOut($this, $s); } }
php
public function out($s, $flush = true) { if ($flush) { if (!Daemon::$obInStack) { // preventing recursion ob_flush(); } } if ($this->aborted) { return false; } if (!isset($this->upstream)) { return false; } $l = mb_orig_strlen($s); $this->responseLength += $l; $this->ensureSentHeaders(); if ($this->attrs->chunked) { for ($o = 0; $o < $l;) { $c = min($this->upstream->pool->config->chunksize->value, $l - $o); $chunk = dechex($c) . "\r\n" . ($c === $l ? $s : mb_orig_substr($s, $o, $c)) // content . "\r\n"; if ($this->sendfp) { $this->sendfp->write($chunk); } else { $this->upstream->requestOut($this, $chunk); } $o += $c; } return true; } else { if ($this->sendfp) { $this->sendfp->write($s); return true; } if (Daemon::$compatMode) { echo $s; return true; } return $this->upstream->requestOut($this, $s); } }
[ "public", "function", "out", "(", "$", "s", ",", "$", "flush", "=", "true", ")", "{", "if", "(", "$", "flush", ")", "{", "if", "(", "!", "Daemon", "::", "$", "obInStack", ")", "{", "// preventing recursion", "ob_flush", "(", ")", ";", "}", "}", "...
Output some data @param string $s String to out @param boolean $flush ob_flush? @return boolean Success
[ "Output", "some", "data" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L460-L510
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.combinedOut
public function combinedOut($s) { if (!$this->headers_sent) { $e = explode("\r\n\r\n", $s, 2); $h = explode("\r\n", $e[0]); foreach ($h as $l) { $this->header($l); } if (isset($e[1])) { return $this->out($e[1]); } return true; } else { return $this->out($s); } }
php
public function combinedOut($s) { if (!$this->headers_sent) { $e = explode("\r\n\r\n", $s, 2); $h = explode("\r\n", $e[0]); foreach ($h as $l) { $this->header($l); } if (isset($e[1])) { return $this->out($e[1]); } return true; } else { return $this->out($s); } }
[ "public", "function", "combinedOut", "(", "$", "s", ")", "{", "if", "(", "!", "$", "this", "->", "headers_sent", ")", "{", "$", "e", "=", "explode", "(", "\"\\r\\n\\r\\n\"", ",", "$", "s", ",", "2", ")", ";", "$", "h", "=", "explode", "(", "\"\\r...
Outputs data with headers (split by \r\n\r\n) @param string $s Data @return boolean Success
[ "Outputs", "data", "with", "headers", "(", "split", "by", "\\", "r", "\\", "n", "\\", "r", "\\", "n", ")" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L525-L543
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.onWakeup
public function onWakeup() { parent::onWakeup(); if (!Daemon::$obInStack) { // preventing recursion @ob_flush(); } $_GET = &$this->attrs->get; $_POST = &$this->attrs->post; $_COOKIE = &$this->attrs->cookie; $_REQUEST = &$this->attrs->request; $_SESSION = &$this->attrs->session; $_FILES = &$this->attrs->files; $_SERVER = &$this->attrs->server; }
php
public function onWakeup() { parent::onWakeup(); if (!Daemon::$obInStack) { // preventing recursion @ob_flush(); } $_GET = &$this->attrs->get; $_POST = &$this->attrs->post; $_COOKIE = &$this->attrs->cookie; $_REQUEST = &$this->attrs->request; $_SESSION = &$this->attrs->session; $_FILES = &$this->attrs->files; $_SERVER = &$this->attrs->server; }
[ "public", "function", "onWakeup", "(", ")", "{", "parent", "::", "onWakeup", "(", ")", ";", "if", "(", "!", "Daemon", "::", "$", "obInStack", ")", "{", "// preventing recursion", "@", "ob_flush", "(", ")", ";", "}", "$", "_GET", "=", "&", "$", "this"...
Called when the request wakes up @return void
[ "Called", "when", "the", "request", "wakes", "up" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L559-L572
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.onSleep
public function onSleep() { if (!Daemon::$obInStack) { // preventing recursion @ob_flush(); } unset($_GET); unset($_POST); unset($_COOKIE); unset($_REQUEST); unset($_SESSION); unset($_FILES); unset($_SERVER); parent::onSleep(); }
php
public function onSleep() { if (!Daemon::$obInStack) { // preventing recursion @ob_flush(); } unset($_GET); unset($_POST); unset($_COOKIE); unset($_REQUEST); unset($_SESSION); unset($_FILES); unset($_SERVER); parent::onSleep(); }
[ "public", "function", "onSleep", "(", ")", "{", "if", "(", "!", "Daemon", "::", "$", "obInStack", ")", "{", "// preventing recursion", "@", "ob_flush", "(", ")", ";", "}", "unset", "(", "$", "_GET", ")", ";", "unset", "(", "$", "_POST", ")", ";", "...
Called when the request starts sleep @return void
[ "Called", "when", "the", "request", "starts", "sleep" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L578-L591
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.status
public function status($code = 200) { if (!isset(self::$codes[$code])) { return false; } $this->header($code . ' ' . self::$codes[$code]); return true; }
php
public function status($code = 200) { if (!isset(self::$codes[$code])) { return false; } $this->header($code . ' ' . self::$codes[$code]); return true; }
[ "public", "function", "status", "(", "$", "code", "=", "200", ")", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "codes", "[", "$", "code", "]", ")", ")", "{", "return", "false", ";", "}", "$", "this", "->", "header", "(", "$", "code", ...
Send HTTP-status @param integer $code Code @throws RequestHeadersAlreadySent @return boolean Success
[ "Send", "HTTP", "-", "status" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L599-L606
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.headersSent
public function headersSent(&$file, &$line) { $file = $this->headers_sent_file; $line = $this->headers_sent_line; return $this->headers_sent; }
php
public function headersSent(&$file, &$line) { $file = $this->headers_sent_file; $line = $this->headers_sent_line; return $this->headers_sent; }
[ "public", "function", "headersSent", "(", "&", "$", "file", ",", "&", "$", "line", ")", "{", "$", "file", "=", "$", "this", "->", "headers_sent_file", ";", "$", "line", "=", "$", "this", "->", "headers_sent_line", ";", "return", "$", "this", "->", "h...
Checks if headers have been sent @param string &$file File name @param integer &$line Line in file @return boolean Success
[ "Checks", "if", "headers", "have", "been", "sent" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L614-L619
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.setcookie
public function setcookie( $name, $value = '', $maxage = 0, $path = '', $domain = '', $secure = false, $HTTPOnly = false ) { $this->header( 'Set-Cookie: ' . $name . '=' . rawurlencode($value) . (empty($domain) ? '' : '; Domain=' . $domain) . (empty($maxage) ? '' : '; Max-Age=' . $maxage) . (empty($path) ? '' : '; Path=' . $path) . (!$secure ? '' : '; Secure') . (!$HTTPOnly ? '' : '; HttpOnly'), false ); }
php
public function setcookie( $name, $value = '', $maxage = 0, $path = '', $domain = '', $secure = false, $HTTPOnly = false ) { $this->header( 'Set-Cookie: ' . $name . '=' . rawurlencode($value) . (empty($domain) ? '' : '; Domain=' . $domain) . (empty($maxage) ? '' : '; Max-Age=' . $maxage) . (empty($path) ? '' : '; Path=' . $path) . (!$secure ? '' : '; Secure') . (!$HTTPOnly ? '' : '; HttpOnly'), false ); }
[ "public", "function", "setcookie", "(", "$", "name", ",", "$", "value", "=", "''", ",", "$", "maxage", "=", "0", ",", "$", "path", "=", "''", ",", "$", "domain", "=", "''", ",", "$", "secure", "=", "false", ",", "$", "HTTPOnly", "=", "false", "...
Set the cookie @param string $name Name of cookie @param string $value Value @param integer $maxage Optional. Max-Age. Default is 0 @param string $path Optional. Path. Default is empty string @param string $domain Optional. Domain. Default is empty string @param boolean $secure Optional. Secure. Default is false @param boolean $HTTPOnly Optional. HTTPOnly. Default is false @return void
[ "Set", "the", "cookie" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L641-L659
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.parseSize
public static function parseSize($value) { $l = substr($value, -1); if ($l === 'b' || $l === 'B') { return ((int)substr($value, 0, -1)); } if ($l === 'k') { return ((int)substr($value, 0, -1) * 1000); } if ($l === 'K') { return ((int)substr($value, 0, -1) * 1024); } if ($l === 'm') { return ((int)substr($value, 0, -1) * 1000 * 1000); } if ($l === 'M') { return ((int)substr($value, 0, -1) * 1024 * 1024); } if ($l === 'g') { return ((int)substr($value, 0, -1) * 1000 * 1000 * 1000); } if ($l === 'G') { return ((int)substr($value, 0, -1) * 1024 * 1024 * 1024); } return (int)$value; }
php
public static function parseSize($value) { $l = substr($value, -1); if ($l === 'b' || $l === 'B') { return ((int)substr($value, 0, -1)); } if ($l === 'k') { return ((int)substr($value, 0, -1) * 1000); } if ($l === 'K') { return ((int)substr($value, 0, -1) * 1024); } if ($l === 'm') { return ((int)substr($value, 0, -1) * 1000 * 1000); } if ($l === 'M') { return ((int)substr($value, 0, -1) * 1024 * 1024); } if ($l === 'g') { return ((int)substr($value, 0, -1) * 1000 * 1000 * 1000); } if ($l === 'G') { return ((int)substr($value, 0, -1) * 1024 * 1024 * 1024); } return (int)$value; }
[ "public", "static", "function", "parseSize", "(", "$", "value", ")", "{", "$", "l", "=", "substr", "(", "$", "value", ",", "-", "1", ")", ";", "if", "(", "$", "l", "===", "'b'", "||", "$", "l", "===", "'B'", ")", "{", "return", "(", "(", "int...
Converts human-readable representation of size to number of bytes @param string $value String of size @return integer
[ "Converts", "human", "-", "readable", "representation", "of", "size", "to", "number", "of", "bytes" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L742-L775
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.onUploadFileStart
public function onUploadFileStart($in) { $this->freezeInput(); FileSystem::tempnam(ini_get('upload_tmp_dir'), 'php', function ($fp) use ($in) { if (!$fp) { $in->curPart['fp'] = false; $in->curPart['error'] = UPLOAD_ERR_NO_TMP_DIR; } else { $in->curPart['fp'] = $fp; $in->curPart['tmp_name'] = $fp->path; } $this->unfreezeInput(); }); }
php
public function onUploadFileStart($in) { $this->freezeInput(); FileSystem::tempnam(ini_get('upload_tmp_dir'), 'php', function ($fp) use ($in) { if (!$fp) { $in->curPart['fp'] = false; $in->curPart['error'] = UPLOAD_ERR_NO_TMP_DIR; } else { $in->curPart['fp'] = $fp; $in->curPart['tmp_name'] = $fp->path; } $this->unfreezeInput(); }); }
[ "public", "function", "onUploadFileStart", "(", "$", "in", ")", "{", "$", "this", "->", "freezeInput", "(", ")", ";", "FileSystem", "::", "tempnam", "(", "ini_get", "(", "'upload_tmp_dir'", ")", ",", "'php'", ",", "function", "(", "$", "fp", ")", "use", ...
Called when file upload started @param Input $in Input buffer @return void
[ "Called", "when", "file", "upload", "started" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L782-L795
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.onUploadFileChunk
public function onUploadFileChunk($in, $last = false) { if ($in->curPart['error'] !== UPLOAD_ERR_OK) { // just drop the chunk return; } $cb = function ($fp, $result) use ($last, $in) { if ($last) { unset($in->curPart['fp']); } $this->unfreezeInput(); }; if ($in->writeChunkToFd($in->curPart['fp']->getFd())) { // We had written via internal method return; } // Internal method is not available, let's get chunk data into $chunk and then use File->write() $chunk = $in->getChunkString(); if ($chunk === false) { return; } $this->freezeInput(); $in->curPart['fp']->write($chunk, $cb); }
php
public function onUploadFileChunk($in, $last = false) { if ($in->curPart['error'] !== UPLOAD_ERR_OK) { // just drop the chunk return; } $cb = function ($fp, $result) use ($last, $in) { if ($last) { unset($in->curPart['fp']); } $this->unfreezeInput(); }; if ($in->writeChunkToFd($in->curPart['fp']->getFd())) { // We had written via internal method return; } // Internal method is not available, let's get chunk data into $chunk and then use File->write() $chunk = $in->getChunkString(); if ($chunk === false) { return; } $this->freezeInput(); $in->curPart['fp']->write($chunk, $cb); }
[ "public", "function", "onUploadFileChunk", "(", "$", "in", ",", "$", "last", "=", "false", ")", "{", "if", "(", "$", "in", "->", "curPart", "[", "'error'", "]", "!==", "UPLOAD_ERR_OK", ")", "{", "// just drop the chunk", "return", ";", "}", "$", "cb", ...
Called when chunk of incoming file has arrived @param Input $in Input buffer @param boolean $last Last? @return void
[ "Called", "when", "chunk", "of", "incoming", "file", "has", "arrived" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L803-L826
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.unfreezeInput
protected function unfreezeInput() { $this->upstream->unfreezeInput(); if (isset($this->attrs->input)) { $this->attrs->input->unfreeze(); } }
php
protected function unfreezeInput() { $this->upstream->unfreezeInput(); if (isset($this->attrs->input)) { $this->attrs->input->unfreeze(); } }
[ "protected", "function", "unfreezeInput", "(", ")", "{", "$", "this", "->", "upstream", "->", "unfreezeInput", "(", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "attrs", "->", "input", ")", ")", "{", "$", "this", "->", "attrs", "->", "input"...
Unfreeze input @return void
[ "Unfreeze", "input" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L842-L848
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.isUploadedFile
public function isUploadedFile($path) { if (!$path) { return false; } if (mb_orig_strpos($path, $this->getUploadTempDir() . '/') !== 0) { return false; } foreach ($this->attrs->files as $file) { if ($file['tmp_name'] === $path) { return true; } } return false; }
php
public function isUploadedFile($path) { if (!$path) { return false; } if (mb_orig_strpos($path, $this->getUploadTempDir() . '/') !== 0) { return false; } foreach ($this->attrs->files as $file) { if ($file['tmp_name'] === $path) { return true; } } return false; }
[ "public", "function", "isUploadedFile", "(", "$", "path", ")", "{", "if", "(", "!", "$", "path", ")", "{", "return", "false", ";", "}", "if", "(", "mb_orig_strpos", "(", "$", "path", ",", "$", "this", "->", "getUploadTempDir", "(", ")", ".", "'/'", ...
Tells whether the file was uploaded via HTTP POST @param string $path The filename being checked @return boolean Whether if this is uploaded file
[ "Tells", "whether", "the", "file", "was", "uploaded", "via", "HTTP", "POST" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L867-L881
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.moveUploadedFile
public function moveUploadedFile($filename, $dest) { if (!$this->isUploadedFile($filename)) { return false; } return FileSystem::rename($filename, $dest); }
php
public function moveUploadedFile($filename, $dest) { if (!$this->isUploadedFile($filename)) { return false; } return FileSystem::rename($filename, $dest); }
[ "public", "function", "moveUploadedFile", "(", "$", "filename", ",", "$", "dest", ")", "{", "if", "(", "!", "$", "this", "->", "isUploadedFile", "(", "$", "filename", ")", ")", "{", "return", "false", ";", "}", "return", "FileSystem", "::", "rename", "...
Moves an uploaded file to a new location @param string $filename The filename of the uploaded file @param string $dest The destination of the moved file @return boolean Success
[ "Moves", "an", "uploaded", "file", "to", "a", "new", "location" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L889-L895
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.readBodyFile
public function readBodyFile() { if (!isset($this->attrs->server['REQUEST_BODY_FILE'])) { return false; } FileSystem::readfileChunked( $this->attrs->server['REQUEST_BODY_FILE'], function ($file, $success) { $this->attrs->inputDone = true; if ($this->sleepTime === 0) { $this->wakeup(); } }, function ($file, $chunk) { // readed chunk $this->stdin($chunk); } ); return true; }
php
public function readBodyFile() { if (!isset($this->attrs->server['REQUEST_BODY_FILE'])) { return false; } FileSystem::readfileChunked( $this->attrs->server['REQUEST_BODY_FILE'], function ($file, $success) { $this->attrs->inputDone = true; if ($this->sleepTime === 0) { $this->wakeup(); } }, function ($file, $chunk) { // readed chunk $this->stdin($chunk); } ); return true; }
[ "public", "function", "readBodyFile", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "attrs", "->", "server", "[", "'REQUEST_BODY_FILE'", "]", ")", ")", "{", "return", "false", ";", "}", "FileSystem", "::", "readfileChunked", "(", "$", ...
Read request body from the file given in REQUEST_BODY_FILE parameter @return boolean Success
[ "Read", "request", "body", "from", "the", "file", "given", "in", "REQUEST_BODY_FILE", "parameter" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L901-L922
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.parseStr
public static function parseStr($s, &$var, $header = false) { static $cb; if ($cb === null) { $cb = function ($m) { return urlencode(html_entity_decode('&#' . hexdec($m[1]) . ';', ENT_NOQUOTES, 'utf-8')); }; } if ($header) { $s = strtr($s, Generic::$hvaltr); } if ((stripos($s, '%u') !== false) && preg_match('~(%u[a-f\d]{4}|%[c-f][a-f\d](?!%[89a-f][a-f\d]))~is', $s, $m) ) { $s = preg_replace_callback('~%(u[a-f\d]{4}|[a-f\d]{2})~i', $cb, $s); } parse_str($s, $var); }
php
public static function parseStr($s, &$var, $header = false) { static $cb; if ($cb === null) { $cb = function ($m) { return urlencode(html_entity_decode('&#' . hexdec($m[1]) . ';', ENT_NOQUOTES, 'utf-8')); }; } if ($header) { $s = strtr($s, Generic::$hvaltr); } if ((stripos($s, '%u') !== false) && preg_match('~(%u[a-f\d]{4}|%[c-f][a-f\d](?!%[89a-f][a-f\d]))~is', $s, $m) ) { $s = preg_replace_callback('~%(u[a-f\d]{4}|[a-f\d]{2})~i', $cb, $s); } parse_str($s, $var); }
[ "public", "static", "function", "parseStr", "(", "$", "s", ",", "&", "$", "var", ",", "$", "header", "=", "false", ")", "{", "static", "$", "cb", ";", "if", "(", "$", "cb", "===", "null", ")", "{", "$", "cb", "=", "function", "(", "$", "m", "...
Replacement for default parse_str(), it supoorts UCS-2 like this: %uXXXX @param string $s String to parse @param array &$var Reference to the resulting array @param boolean $header Header-style string @return void
[ "Replacement", "for", "default", "parse_str", "()", "it", "supoorts", "UCS", "-", "2", "like", "this", ":", "%uXXXX" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L931-L948
kakserpom/phpdaemon
PHPDaemon/HTTPRequest/Generic.php
Generic.postFinishHandler
protected function postFinishHandler($cb = null) { if (!$this->headers_sent) { $this->out(''); } $this->sendfp = null; if (isset($this->attrs->files)) { foreach ($this->attrs->files as $f) { if (isset($f['tmp_name'])) { FileSystem::unlink($f['tmp_name']); } } } if (isset($this->attrs->session)) { $this->sessionCommit($cb); } else { $cb === null || $cb(); } }
php
protected function postFinishHandler($cb = null) { if (!$this->headers_sent) { $this->out(''); } $this->sendfp = null; if (isset($this->attrs->files)) { foreach ($this->attrs->files as $f) { if (isset($f['tmp_name'])) { FileSystem::unlink($f['tmp_name']); } } } if (isset($this->attrs->session)) { $this->sessionCommit($cb); } else { $cb === null || $cb(); } }
[ "protected", "function", "postFinishHandler", "(", "$", "cb", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "headers_sent", ")", "{", "$", "this", "->", "out", "(", "''", ")", ";", "}", "$", "this", "->", "sendfp", "=", "null", ";", "...
Called after request finish @param callable $cb Callback @return void
[ "Called", "after", "request", "finish" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/HTTPRequest/Generic.php#L955-L973
kakserpom/phpdaemon
PHPDaemon/Cache/CappedStorage.php
CappedStorage.put
public function put($key, $value, $ttl = null) { $k = $this->hash($key); if (isset($this->cache[$k])) { $item = $this->cache[$k]; $item->setValue($value); if ($ttl !== null) { $item->expire = microtime(true) + $ttl; } return $item; } $item = new Item($value); if ($ttl !== null) { $item->expire = microtime(true) + $ttl; } $this->cache[$k] = $item; $s = sizeof($this->cache); if ($s > $this->maxCacheSize + $this->capWindow) { uasort($this->cache, $this->sorter); for (; $s > $this->maxCacheSize; --$s) { array_pop($this->cache); } } return $item; }
php
public function put($key, $value, $ttl = null) { $k = $this->hash($key); if (isset($this->cache[$k])) { $item = $this->cache[$k]; $item->setValue($value); if ($ttl !== null) { $item->expire = microtime(true) + $ttl; } return $item; } $item = new Item($value); if ($ttl !== null) { $item->expire = microtime(true) + $ttl; } $this->cache[$k] = $item; $s = sizeof($this->cache); if ($s > $this->maxCacheSize + $this->capWindow) { uasort($this->cache, $this->sorter); for (; $s > $this->maxCacheSize; --$s) { array_pop($this->cache); } } return $item; }
[ "public", "function", "put", "(", "$", "key", ",", "$", "value", ",", "$", "ttl", "=", "null", ")", "{", "$", "k", "=", "$", "this", "->", "hash", "(", "$", "key", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "cache", "[", "$", "k"...
Puts element in cache @param string $key Key @param mixed $value Value @param integer $ttl Time to live @return mixed
[ "Puts", "element", "in", "cache" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Cache/CappedStorage.php#L61-L85
kakserpom/phpdaemon
PHPDaemon/Cache/CappedStorage.php
CappedStorage.get
public function get($key) { $k = $this->hash($key); if (!isset($this->cache[$k])) { return null; } $item = $this->cache[$k]; if (isset($item->expire)) { if (microtime(true) >= $item->expire) { unset($this->cache[$k]); return null; } } return $item; }
php
public function get($key) { $k = $this->hash($key); if (!isset($this->cache[$k])) { return null; } $item = $this->cache[$k]; if (isset($item->expire)) { if (microtime(true) >= $item->expire) { unset($this->cache[$k]); return null; } } return $item; }
[ "public", "function", "get", "(", "$", "key", ")", "{", "$", "k", "=", "$", "this", "->", "hash", "(", "$", "key", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "cache", "[", "$", "k", "]", ")", ")", "{", "return", "null", ";",...
Gets element by key @param string $key Key @return object Item
[ "Gets", "element", "by", "key" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Cache/CappedStorage.php#L113-L127
kakserpom/phpdaemon
PHPDaemon/PubSub/PubSub.php
PubSub.sub
public function sub($id, $obj, $cb) { if (!isset($this->events[$id])) { return false; } return $this->events[$id]->sub($obj, $cb); }
php
public function sub($id, $obj, $cb) { if (!isset($this->events[$id])) { return false; } return $this->events[$id]->sub($obj, $cb); }
[ "public", "function", "sub", "(", "$", "id", ",", "$", "obj", ",", "$", "cb", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "events", "[", "$", "id", "]", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", ...
Subcribe to event @param string $id Event ID @param object $obj Subscriber @param callable $cb Callback @return boolean Success
[ "Subcribe", "to", "event" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/PubSub/PubSub.php#L36-L42
kakserpom/phpdaemon
PHPDaemon/PubSub/PubSub.php
PubSub.unsub
public function unsub($id, $obj) { if (!isset($this->events[$id])) { return false; } return $this->events[$id]->unsub($obj); }
php
public function unsub($id, $obj) { if (!isset($this->events[$id])) { return false; } return $this->events[$id]->unsub($obj); }
[ "public", "function", "unsub", "(", "$", "id", ",", "$", "obj", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "events", "[", "$", "id", "]", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "events", "[", ...
Unsubscribe object from event @param string $id Event ID @param object $obj Subscriber @return boolean Success
[ "Unsubscribe", "object", "from", "event" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/PubSub/PubSub.php#L71-L77
kakserpom/phpdaemon
PHPDaemon/PubSub/PubSub.php
PubSub.pub
public function pub($id, $data) { if (!isset($this->events[$id])) { return false; } return $this->events[$id]->pub($data); }
php
public function pub($id, $data) { if (!isset($this->events[$id])) { return false; } return $this->events[$id]->pub($data); }
[ "public", "function", "pub", "(", "$", "id", ",", "$", "data", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "events", "[", "$", "id", "]", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "events", "[", "...
Publish @param string $id Event ID @param mixed $data Data @return boolean Success
[ "Publish" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/PubSub/PubSub.php#L85-L91
kakserpom/phpdaemon
PHPDaemon/PubSub/PubSub.php
PubSub.unsubFromAll
public function unsubFromAll($obj) { foreach ($this->events as $event) { $event->unsub($obj); } return true; }
php
public function unsubFromAll($obj) { foreach ($this->events as $event) { $event->unsub($obj); } return true; }
[ "public", "function", "unsubFromAll", "(", "$", "obj", ")", "{", "foreach", "(", "$", "this", "->", "events", "as", "$", "event", ")", "{", "$", "event", "->", "unsub", "(", "$", "obj", ")", ";", "}", "return", "true", ";", "}" ]
Unsubscribe object from all events @param object $obj Subscriber @return boolean Success
[ "Unsubscribe", "object", "from", "all", "events" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/PubSub/PubSub.php#L98-L104
kakserpom/phpdaemon
PHPDaemon/Core/AppInstance.php
AppInstance.isEnabled
public function isEnabled() { return isset($this->config->enable->value) && $this->config->enable->value; }
php
public function isEnabled() { return isset($this->config->enable->value) && $this->config->enable->value; }
[ "public", "function", "isEnabled", "(", ")", "{", "return", "isset", "(", "$", "this", "->", "config", "->", "enable", "->", "value", ")", "&&", "$", "this", "->", "config", "->", "enable", "->", "value", ";", "}" ]
Returns whether if this application is enabled @return boolean
[ "Returns", "whether", "if", "this", "application", "is", "enabled" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/AppInstance.php#L125-L128
kakserpom/phpdaemon
PHPDaemon/Core/AppInstance.php
AppInstance.RPCall
public function RPCall($method, $args) { if (!$this->enableRPC || !is_callable([$this, $method])) { return false; } $func = [$this, $method]; return $func(...$args); }
php
public function RPCall($method, $args) { if (!$this->enableRPC || !is_callable([$this, $method])) { return false; } $func = [$this, $method]; return $func(...$args); }
[ "public", "function", "RPCall", "(", "$", "method", ",", "$", "args", ")", "{", "if", "(", "!", "$", "this", "->", "enableRPC", "||", "!", "is_callable", "(", "[", "$", "this", ",", "$", "method", "]", ")", ")", "{", "return", "false", ";", "}", ...
Function handles incoming Remote Procedure Calls You can override it @param string $method Method name @param array $args Arguments @return mixed Result
[ "Function", "handles", "incoming", "Remote", "Procedure", "Calls", "You", "can", "override", "it" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/AppInstance.php#L173-L180
kakserpom/phpdaemon
PHPDaemon/Core/AppInstance.php
AppInstance.broadcastCall
public function broadcastCall($method, $args = [], $cb = null) { return Daemon::$process->IPCManager->sendBroadcastCall( '\\' . get_class($this) . ($this->name !== '' ? ':' . $this->name : ''), $method, $args, $cb ); }
php
public function broadcastCall($method, $args = [], $cb = null) { return Daemon::$process->IPCManager->sendBroadcastCall( '\\' . get_class($this) . ($this->name !== '' ? ':' . $this->name : ''), $method, $args, $cb ); }
[ "public", "function", "broadcastCall", "(", "$", "method", ",", "$", "args", "=", "[", "]", ",", "$", "cb", "=", "null", ")", "{", "return", "Daemon", "::", "$", "process", "->", "IPCManager", "->", "sendBroadcastCall", "(", "'\\\\'", ".", "get_class", ...
Send broadcast RPC You can override it @param string $method Method name @param array $args Arguments @param callable $cb Callback @return boolean Success
[ "Send", "broadcast", "RPC", "You", "can", "override", "it" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/AppInstance.php#L208-L216
kakserpom/phpdaemon
PHPDaemon/Core/AppInstance.php
AppInstance.singleCall
public function singleCall($method, $args = [], $cb = null) { return Daemon::$process->IPCManager->sendSingleCall( '\\' . get_class($this) . ($this->name !== '' ? ':' . $this->name : ''), $method, $args, $cb ); }
php
public function singleCall($method, $args = [], $cb = null) { return Daemon::$process->IPCManager->sendSingleCall( '\\' . get_class($this) . ($this->name !== '' ? ':' . $this->name : ''), $method, $args, $cb ); }
[ "public", "function", "singleCall", "(", "$", "method", ",", "$", "args", "=", "[", "]", ",", "$", "cb", "=", "null", ")", "{", "return", "Daemon", "::", "$", "process", "->", "IPCManager", "->", "sendSingleCall", "(", "'\\\\'", ".", "get_class", "(", ...
Send RPC, executed once in any worker You can override it @param string $method Method name @param array $args Arguments @param mixed $cb Callback @return boolean Success
[ "Send", "RPC", "executed", "once", "in", "any", "worker", "You", "can", "override", "it" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/AppInstance.php#L226-L234
kakserpom/phpdaemon
PHPDaemon/Core/AppInstance.php
AppInstance.directCall
public function directCall($workerId, $method, $args = [], $cb = null) { return Daemon::$process->IPCManager->sendDirectCall( $workerId, '\\' . get_class($this) . ($this->name !== '' ? ':' . $this->name : ''), $method, $args, $cb ); }
php
public function directCall($workerId, $method, $args = [], $cb = null) { return Daemon::$process->IPCManager->sendDirectCall( $workerId, '\\' . get_class($this) . ($this->name !== '' ? ':' . $this->name : ''), $method, $args, $cb ); }
[ "public", "function", "directCall", "(", "$", "workerId", ",", "$", "method", ",", "$", "args", "=", "[", "]", ",", "$", "cb", "=", "null", ")", "{", "return", "Daemon", "::", "$", "process", "->", "IPCManager", "->", "sendDirectCall", "(", "$", "wor...
Send RPC, executed once in certain worker You can override it @param integer $workerId Worker Id @param string $method Method name @param array $args Arguments @param mixed $cb Callback @return boolean Success
[ "Send", "RPC", "executed", "once", "in", "certain", "worker", "You", "can", "override", "it" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/AppInstance.php#L245-L254
kakserpom/phpdaemon
PHPDaemon/Core/AppInstance.php
AppInstance.handleRequest
public function handleRequest($parent, $upstream) { $req = $this->beginRequest($parent, $upstream); return $req ?: $parent; }
php
public function handleRequest($parent, $upstream) { $req = $this->beginRequest($parent, $upstream); return $req ?: $parent; }
[ "public", "function", "handleRequest", "(", "$", "parent", ",", "$", "upstream", ")", "{", "$", "req", "=", "$", "this", "->", "beginRequest", "(", "$", "parent", ",", "$", "upstream", ")", ";", "return", "$", "req", "?", ":", "$", "parent", ";", "...
Handle the request @param object $parent Parent request @param object $upstream Upstream application @return object Request
[ "Handle", "the", "request" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/AppInstance.php#L272-L276
kakserpom/phpdaemon
PHPDaemon/Core/AppInstance.php
AppInstance.beginRequest
public function beginRequest($req, $upstream) { if (!$this->requestClass) { return false; } $className = $this->requestClass; return new $className($this, $upstream, $req); }
php
public function beginRequest($req, $upstream) { if (!$this->requestClass) { return false; } $className = $this->requestClass; return new $className($this, $upstream, $req); }
[ "public", "function", "beginRequest", "(", "$", "req", ",", "$", "upstream", ")", "{", "if", "(", "!", "$", "this", "->", "requestClass", ")", "{", "return", "false", ";", "}", "$", "className", "=", "$", "this", "->", "requestClass", ";", "return", ...
Create Request instance @param object $req Generic @param object $upstream Upstream application instance @return object Request
[ "Create", "Request", "instance" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/AppInstance.php#L284-L291
kakserpom/phpdaemon
PHPDaemon/Core/AppInstance.php
AppInstance.handleStatus
public function handleStatus($ret) { if ($ret === self::EVENT_CONFIG_UPDATED) { $this->onConfigUpdated(); return true; } elseif ($ret === self::EVENT_GRACEFUL_SHUTDOWN) { return $this->onShutdown(true); } elseif ($ret === self::EVENT_SHUTDOWN) { return $this->onShutdown(); } return false; }
php
public function handleStatus($ret) { if ($ret === self::EVENT_CONFIG_UPDATED) { $this->onConfigUpdated(); return true; } elseif ($ret === self::EVENT_GRACEFUL_SHUTDOWN) { return $this->onShutdown(true); } elseif ($ret === self::EVENT_SHUTDOWN) { return $this->onShutdown(); } return false; }
[ "public", "function", "handleStatus", "(", "$", "ret", ")", "{", "if", "(", "$", "ret", "===", "self", "::", "EVENT_CONFIG_UPDATED", ")", "{", "$", "this", "->", "onConfigUpdated", "(", ")", ";", "return", "true", ";", "}", "elseif", "(", "$", "ret", ...
Handle the worker status @param integer $ret Status code @return boolean Result
[ "Handle", "the", "worker", "status" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/AppInstance.php#L298-L309
kakserpom/phpdaemon
PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Queue/QueueDeclareOkFrame.php
QueueDeclareOkFrame.create
public static function create( $queue = null, $messageCount = null, $consumerCount = null ) { $frame = new self(); if (null !== $queue) { $frame->queue = $queue; } if (null !== $messageCount) { $frame->messageCount = $messageCount; } if (null !== $consumerCount) { $frame->consumerCount = $consumerCount; } return $frame; }
php
public static function create( $queue = null, $messageCount = null, $consumerCount = null ) { $frame = new self(); if (null !== $queue) { $frame->queue = $queue; } if (null !== $messageCount) { $frame->messageCount = $messageCount; } if (null !== $consumerCount) { $frame->consumerCount = $consumerCount; } return $frame; }
[ "public", "static", "function", "create", "(", "$", "queue", "=", "null", ",", "$", "messageCount", "=", "null", ",", "$", "consumerCount", "=", "null", ")", "{", "$", "frame", "=", "new", "self", "(", ")", ";", "if", "(", "null", "!==", "$", "queu...
long
[ "long" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Queue/QueueDeclareOkFrame.php#L22-L39
kakserpom/phpdaemon
PHPDaemon/SockJS/Session.php
Session.handleException
public function handleException($e) { if (!isset($this->route)) { return false; } return $this->route->handleException($e); }
php
public function handleException($e) { if (!isset($this->route)) { return false; } return $this->route->handleException($e); }
[ "public", "function", "handleException", "(", "$", "e", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "route", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "route", "->", "handleException", "(", "$", "e", ")...
Uncaught exception handler @param object $e @return boolean|null Handled?
[ "Uncaught", "exception", "handler" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Session.php#L119-L125
kakserpom/phpdaemon
PHPDaemon/SockJS/Session.php
Session.onHandshake
public function onHandshake() { if (!isset($this->route)) { return; } $this->route->onWakeup(); try { $this->route->onHandshake(); } catch (\Exception $e) { Daemon::uncaughtExceptionHandler($e); } $this->route->onSleep(); }
php
public function onHandshake() { if (!isset($this->route)) { return; } $this->route->onWakeup(); try { $this->route->onHandshake(); } catch (\Exception $e) { Daemon::uncaughtExceptionHandler($e); } $this->route->onSleep(); }
[ "public", "function", "onHandshake", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "route", ")", ")", "{", "return", ";", "}", "$", "this", "->", "route", "->", "onWakeup", "(", ")", ";", "try", "{", "$", "this", "->", "route", ...
onHandshake @return void
[ "onHandshake" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Session.php#L131-L143
kakserpom/phpdaemon
PHPDaemon/SockJS/Session.php
Session.c2s
public function c2s($redis) { if (!$redis) { return; } if ($this->finished) { return; } list(, $chan, $msg) = $redis->result; if ($msg === '') { return; } $this->onFrame($msg, \PHPDaemon\Servers\WebSocket\Pool::STRING); }
php
public function c2s($redis) { if (!$redis) { return; } if ($this->finished) { return; } list(, $chan, $msg) = $redis->result; if ($msg === '') { return; } $this->onFrame($msg, \PHPDaemon\Servers\WebSocket\Pool::STRING); }
[ "public", "function", "c2s", "(", "$", "redis", ")", "{", "if", "(", "!", "$", "redis", ")", "{", "return", ";", "}", "if", "(", "$", "this", "->", "finished", ")", "{", "return", ";", "}", "list", "(", ",", "$", "chan", ",", "$", "msg", ")",...
c2s @param object $redis @return void
[ "c2s" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Session.php#L150-L163
kakserpom/phpdaemon
PHPDaemon/SockJS/Session.php
Session.onFrame
public function onFrame($msg, $type) { $frames = json_decode($msg, true); if (!is_array($frames)) { return; } $this->route->onWakeup(); foreach ($frames as $frame) { try { $this->route->onFrame($frame, \PHPDaemon\Servers\WebSocket\Pool::STRING); } catch (\Exception $e) { Daemon::uncaughtExceptionHandler($e); } } $this->route->onSleep(); }
php
public function onFrame($msg, $type) { $frames = json_decode($msg, true); if (!is_array($frames)) { return; } $this->route->onWakeup(); foreach ($frames as $frame) { try { $this->route->onFrame($frame, \PHPDaemon\Servers\WebSocket\Pool::STRING); } catch (\Exception $e) { Daemon::uncaughtExceptionHandler($e); } } $this->route->onSleep(); }
[ "public", "function", "onFrame", "(", "$", "msg", ",", "$", "type", ")", "{", "$", "frames", "=", "json_decode", "(", "$", "msg", ",", "true", ")", ";", "if", "(", "!", "is_array", "(", "$", "frames", ")", ")", "{", "return", ";", "}", "$", "th...
onFrame @param string $msg [@todo description] @param integer $type [@todo description] @return void
[ "onFrame" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Session.php#L171-L186
kakserpom/phpdaemon
PHPDaemon/SockJS/Session.php
Session.poll
public function poll($redis) { if (!$redis) { return; } list(, $chan, $msg) = $redis->result; $this->pollMode = json_decode($msg, true); Timer::setTimeout($this->finishTimer); $this->flush(); }
php
public function poll($redis) { if (!$redis) { return; } list(, $chan, $msg) = $redis->result; $this->pollMode = json_decode($msg, true); Timer::setTimeout($this->finishTimer); $this->flush(); }
[ "public", "function", "poll", "(", "$", "redis", ")", "{", "if", "(", "!", "$", "redis", ")", "{", "return", ";", "}", "list", "(", ",", "$", "chan", ",", "$", "msg", ")", "=", "$", "redis", "->", "result", ";", "$", "this", "->", "pollMode", ...
poll @param object $redis @return void
[ "poll" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Session.php#L193-L203
kakserpom/phpdaemon
PHPDaemon/SockJS/Session.php
Session.flush
public function flush() { if ($this->pollMode === null) { // first polling request is not there yet return; } if ($this->flushing) { return; } $bsize = sizeof($this->buffer); $fbsize = sizeof($this->framesBuffer); if ($bsize === 0 && $fbsize === 0) { return; } $this->flushing = true; if (in_array('one-by-one', $this->pollMode)) { $b = array_slice($this->buffer, 0, 1); $bsize = sizeof($b); } else { $b = $this->buffer; } if ($fbsize > 0) { if (!in_array('one-by-one', $this->pollMode) || !sizeof($b)) { $b[] = 'a' . $this->toJson($this->framesBuffer); } else { $fbsize = 0; } } $this->appInstance->publish( 's2c:' . $this->id, $this->toJson($b), function ($redis) use ($bsize, $fbsize, $b) { $this->flushing = false; if (!$redis) { return; } //D(['b' => $b, $redis->result]); if ($redis->result === 0) { return; } $reflush = false; if (sizeof($this->buffer) > $bsize) { $this->buffer = array_slice($this->buffer, $bsize); $reflush = true; } else { $this->buffer = []; } if (sizeof($this->framesBuffer) > $fbsize) { $this->framesBuffer = array_slice($this->framesBuffer, $fbsize); $reflush = true; } else { $this->framesBuffer = []; } $this->onWrite(); if ($reflush && in_array('stream', $this->pollMode)) { $this->flush(); } } ); }
php
public function flush() { if ($this->pollMode === null) { // first polling request is not there yet return; } if ($this->flushing) { return; } $bsize = sizeof($this->buffer); $fbsize = sizeof($this->framesBuffer); if ($bsize === 0 && $fbsize === 0) { return; } $this->flushing = true; if (in_array('one-by-one', $this->pollMode)) { $b = array_slice($this->buffer, 0, 1); $bsize = sizeof($b); } else { $b = $this->buffer; } if ($fbsize > 0) { if (!in_array('one-by-one', $this->pollMode) || !sizeof($b)) { $b[] = 'a' . $this->toJson($this->framesBuffer); } else { $fbsize = 0; } } $this->appInstance->publish( 's2c:' . $this->id, $this->toJson($b), function ($redis) use ($bsize, $fbsize, $b) { $this->flushing = false; if (!$redis) { return; } //D(['b' => $b, $redis->result]); if ($redis->result === 0) { return; } $reflush = false; if (sizeof($this->buffer) > $bsize) { $this->buffer = array_slice($this->buffer, $bsize); $reflush = true; } else { $this->buffer = []; } if (sizeof($this->framesBuffer) > $fbsize) { $this->framesBuffer = array_slice($this->framesBuffer, $fbsize); $reflush = true; } else { $this->framesBuffer = []; } $this->onWrite(); if ($reflush && in_array('stream', $this->pollMode)) { $this->flush(); } } ); }
[ "public", "function", "flush", "(", ")", "{", "if", "(", "$", "this", "->", "pollMode", "===", "null", ")", "{", "// first polling request is not there yet", "return", ";", "}", "if", "(", "$", "this", "->", "flushing", ")", "{", "return", ";", "}", "$",...
Flushes buffered packets @return void
[ "Flushes", "buffered", "packets" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Session.php#L266-L325
kakserpom/phpdaemon
PHPDaemon/SockJS/Session.php
Session.sendPacket
public function sendPacket($pct, $cb = null) { if (sizeof($this->framesBuffer)) { $this->buffer[] = 'a' . $this->toJson($this->framesBuffer); $this->framesBuffer = []; } $this->buffer[] = $pct; if ($cb !== null) { $this->onWrite->push($cb); } $this->flush(); }
php
public function sendPacket($pct, $cb = null) { if (sizeof($this->framesBuffer)) { $this->buffer[] = 'a' . $this->toJson($this->framesBuffer); $this->framesBuffer = []; } $this->buffer[] = $pct; if ($cb !== null) { $this->onWrite->push($cb); } $this->flush(); }
[ "public", "function", "sendPacket", "(", "$", "pct", ",", "$", "cb", "=", "null", ")", "{", "if", "(", "sizeof", "(", "$", "this", "->", "framesBuffer", ")", ")", "{", "$", "this", "->", "buffer", "[", "]", "=", "'a'", ".", "$", "this", "->", "...
sendPacket @param object $pct [@todo description] @param callable $cb [@todo description] @callback $cb ( ) @return void
[ "sendPacket" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Session.php#L334-L345
kakserpom/phpdaemon
PHPDaemon/SockJS/Session.php
Session.sendFrame
public function sendFrame($data, $type = 0x00, $cb = null) { if ($this->finished) { return false; } $this->framesBuffer[] = $data; if ($cb !== null) { $this->onWrite->push($cb); } $this->flush(); return true; }
php
public function sendFrame($data, $type = 0x00, $cb = null) { if ($this->finished) { return false; } $this->framesBuffer[] = $data; if ($cb !== null) { $this->onWrite->push($cb); } $this->flush(); return true; }
[ "public", "function", "sendFrame", "(", "$", "data", ",", "$", "type", "=", "0x00", ",", "$", "cb", "=", "null", ")", "{", "if", "(", "$", "this", "->", "finished", ")", "{", "return", "false", ";", "}", "$", "this", "->", "framesBuffer", "[", "]...
Sends a frame. @param string $data Frame's data. @param integer $type Frame's type. See the constants. @param callback $cb Optional. Callback called when the frame is received by client. @callback $cb ( ) @return boolean Success.
[ "Sends", "a", "frame", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Session.php#L355-L366
kakserpom/phpdaemon
PHPDaemon/Examples/ExampleWebSocket.php
ExampleWebSocket.onReady
public function onReady() { $appInstance = $this; // a reference to this application instance for ExampleWebSocketRoute // URI /exampleApp should be handled by ExampleWebSocketRoute \PHPDaemon\Servers\WebSocket\Pool::getInstance()->addRoute('exampleApp', function ($client) use ($appInstance) { return new ExampleWebSocketRoute($client, $appInstance); }); }
php
public function onReady() { $appInstance = $this; // a reference to this application instance for ExampleWebSocketRoute // URI /exampleApp should be handled by ExampleWebSocketRoute \PHPDaemon\Servers\WebSocket\Pool::getInstance()->addRoute('exampleApp', function ($client) use ($appInstance) { return new ExampleWebSocketRoute($client, $appInstance); }); }
[ "public", "function", "onReady", "(", ")", "{", "$", "appInstance", "=", "$", "this", ";", "// a reference to this application instance for ExampleWebSocketRoute", "// URI /exampleApp should be handled by ExampleWebSocketRoute", "\\", "PHPDaemon", "\\", "Servers", "\\", "WebSoc...
Called when the worker is ready to go. @return void
[ "Called", "when", "the", "worker", "is", "ready", "to", "go", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Examples/ExampleWebSocket.php#L18-L25
kakserpom/phpdaemon
PHPDaemon/Examples/ExampleWebSocket.php
ExampleWebSocketRoute.onFrame
public function onFrame($data, $type) { if ($data === 'ping') { $this->client->sendFrame('pong', 'STRING', function ($client) { // optional. called when the frame is transmitted to the client \PHPDaemon\Core\Daemon::log('ExampleWebSocket: \'pong\' received by client.'); } ); } }
php
public function onFrame($data, $type) { if ($data === 'ping') { $this->client->sendFrame('pong', 'STRING', function ($client) { // optional. called when the frame is transmitted to the client \PHPDaemon\Core\Daemon::log('ExampleWebSocket: \'pong\' received by client.'); } ); } }
[ "public", "function", "onFrame", "(", "$", "data", ",", "$", "type", ")", "{", "if", "(", "$", "data", "===", "'ping'", ")", "{", "$", "this", "->", "client", "->", "sendFrame", "(", "'pong'", ",", "'STRING'", ",", "function", "(", "$", "client", "...
Called when new frame received. @param string Frame's contents. @param integer Frame's type. @return void
[ "Called", "when", "new", "frame", "received", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Examples/ExampleWebSocket.php#L48-L57
kakserpom/phpdaemon
PHPDaemon/WebSocket/Route.php
Route.onWakeup
public function onWakeup() { $this->running = true; Daemon::$context = $this; $_SESSION = &$this->attrs->session; $_GET = &$this->attrs->get; $_POST = []; $_COOKIE = &$this->attrs->cookie; Daemon::$process->setState(Daemon::WSTATE_BUSY); }
php
public function onWakeup() { $this->running = true; Daemon::$context = $this; $_SESSION = &$this->attrs->session; $_GET = &$this->attrs->get; $_POST = []; $_COOKIE = &$this->attrs->cookie; Daemon::$process->setState(Daemon::WSTATE_BUSY); }
[ "public", "function", "onWakeup", "(", ")", "{", "$", "this", "->", "running", "=", "true", ";", "Daemon", "::", "$", "context", "=", "$", "this", ";", "$", "_SESSION", "=", "&", "$", "this", "->", "attrs", "->", "session", ";", "$", "_GET", "=", ...
Called when the request wakes up @return void
[ "Called", "when", "the", "request", "wakes", "up" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/WebSocket/Route.php#L87-L96
kakserpom/phpdaemon
PHPDaemon/WebSocket/Route.php
Route.onSleep
public function onSleep() { Daemon::$context = null; $this->running = false; unset($_SESSION, $_GET, $_POST, $_COOKIE); Daemon::$process->setState(Daemon::WSTATE_IDLE); }
php
public function onSleep() { Daemon::$context = null; $this->running = false; unset($_SESSION, $_GET, $_POST, $_COOKIE); Daemon::$process->setState(Daemon::WSTATE_IDLE); }
[ "public", "function", "onSleep", "(", ")", "{", "Daemon", "::", "$", "context", "=", "null", ";", "$", "this", "->", "running", "=", "false", ";", "unset", "(", "$", "_SESSION", ",", "$", "_GET", ",", "$", "_POST", ",", "$", "_COOKIE", ")", ";", ...
Called when the request starts sleep @return void
[ "Called", "when", "the", "request", "starts", "sleep" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/WebSocket/Route.php#L102-L108
kakserpom/phpdaemon
PHPDaemon/WebSocket/Route.php
Route.getCookieStr
protected function getCookieStr($name) { return \PHPDaemon\HTTPRequest\Generic::getString($this->attrs->cookie[$name]); }
php
protected function getCookieStr($name) { return \PHPDaemon\HTTPRequest\Generic::getString($this->attrs->cookie[$name]); }
[ "protected", "function", "getCookieStr", "(", "$", "name", ")", "{", "return", "\\", "PHPDaemon", "\\", "HTTPRequest", "\\", "Generic", "::", "getString", "(", "$", "this", "->", "attrs", "->", "cookie", "[", "$", "name", "]", ")", ";", "}" ]
Get cookie by name @param string $name Name of cookie @return string Contents
[ "Get", "cookie", "by", "name" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/WebSocket/Route.php#L161-L164
kakserpom/phpdaemon
PHPDaemon/Examples/ExampleGibson.php
ExampleGibsonRequest.init
public function init() { $job = $this->job = new \PHPDaemon\Core\ComplexJob(function ($job) { // called when job is done $this->wakeup(); // wake up the request immediately $job->keep(); // prevent from cleaning }); if (isset($_GET['fill'])) { for ($i = 0; $i < 100; ++$i) { $this->appInstance->gibson->set(3600, 'key' . $i, 'val' . $i); } } $job('testquery', function ($jobname, $job) { // registering job named 'testquery' $this->appInstance->gibson->mget('key99', function ($conn) use ($job, $jobname) { if ($conn->isFinal()) { $job->setResult($jobname, $conn->result); } }); }); $job(); // let the fun begin $this->sleep(1, true); // setting timeout*/ }
php
public function init() { $job = $this->job = new \PHPDaemon\Core\ComplexJob(function ($job) { // called when job is done $this->wakeup(); // wake up the request immediately $job->keep(); // prevent from cleaning }); if (isset($_GET['fill'])) { for ($i = 0; $i < 100; ++$i) { $this->appInstance->gibson->set(3600, 'key' . $i, 'val' . $i); } } $job('testquery', function ($jobname, $job) { // registering job named 'testquery' $this->appInstance->gibson->mget('key99', function ($conn) use ($job, $jobname) { if ($conn->isFinal()) { $job->setResult($jobname, $conn->result); } }); }); $job(); // let the fun begin $this->sleep(1, true); // setting timeout*/ }
[ "public", "function", "init", "(", ")", "{", "$", "job", "=", "$", "this", "->", "job", "=", "new", "\\", "PHPDaemon", "\\", "Core", "\\", "ComplexJob", "(", "function", "(", "$", "job", ")", "{", "// called when job is done", "$", "this", "->", "wakeu...
Constructor. @return void
[ "Constructor", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Examples/ExampleGibson.php#L50-L74
kakserpom/phpdaemon
PHPDaemon/Clients/Mongo/MongoId.php
MongoId.import
public static function import($id) { if ($id instanceof static) { return $id; } elseif ($id instanceof \MongoId) { $id = (string)$id; } elseif (!is_string($id)) { if (is_array($id) && isset($id['$id'])) { return static::import($id['$id']); } return false; } elseif (mb_orig_strlen($id) === 24) { if (!ctype_xdigit($id)) { return false; } } elseif (ctype_alnum($id)) { $id = gmp_strval(gmp_init(strrev($id), 62), 16); if (mb_orig_strlen($id) > 24) { return false; } if (mb_orig_strlen($id) < 24) { $id = str_pad($id, 24, '0', STR_PAD_LEFT); } } else { return false; } return new static($id); }
php
public static function import($id) { if ($id instanceof static) { return $id; } elseif ($id instanceof \MongoId) { $id = (string)$id; } elseif (!is_string($id)) { if (is_array($id) && isset($id['$id'])) { return static::import($id['$id']); } return false; } elseif (mb_orig_strlen($id) === 24) { if (!ctype_xdigit($id)) { return false; } } elseif (ctype_alnum($id)) { $id = gmp_strval(gmp_init(strrev($id), 62), 16); if (mb_orig_strlen($id) > 24) { return false; } if (mb_orig_strlen($id) < 24) { $id = str_pad($id, 24, '0', STR_PAD_LEFT); } } else { return false; } return new static($id); }
[ "public", "static", "function", "import", "(", "$", "id", ")", "{", "if", "(", "$", "id", "instanceof", "static", ")", "{", "return", "$", "id", ";", "}", "elseif", "(", "$", "id", "instanceof", "\\", "MongoId", ")", "{", "$", "id", "=", "(", "st...
Import @param mixed $id ID @return mixed
[ "Import" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Mongo/MongoId.php#L33-L60
kakserpom/phpdaemon
PHPDaemon/Core/Pool.php
Pool.RPCall
public function RPCall($method, $args) { if (!is_callable($f = [$this->pool, 'RPCall'])) { return false; } return $f($method, $args); }
php
public function RPCall($method, $args) { if (!is_callable($f = [$this->pool, 'RPCall'])) { return false; } return $f($method, $args); }
[ "public", "function", "RPCall", "(", "$", "method", ",", "$", "args", ")", "{", "if", "(", "!", "is_callable", "(", "$", "f", "=", "[", "$", "this", "->", "pool", ",", "'RPCall'", "]", ")", ")", "{", "return", "false", ";", "}", "return", "$", ...
Function handles incoming Remote Procedure Calls You can override it @param string $method Method name. @param array $args Arguments. @return mixed Result
[ "Function", "handles", "incoming", "Remote", "Procedure", "Calls", "You", "can", "override", "it" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/Pool.php#L25-L31
kakserpom/phpdaemon
PHPDaemon/Core/Pool.php
Pool.onConfigUpdated
public function onConfigUpdated() { if ($this->pool) { $this->pool->config = $this->config; $this->pool->onConfigUpdated(); } }
php
public function onConfigUpdated() { if ($this->pool) { $this->pool->config = $this->config; $this->pool->onConfigUpdated(); } }
[ "public", "function", "onConfigUpdated", "(", ")", "{", "if", "(", "$", "this", "->", "pool", ")", "{", "$", "this", "->", "pool", "->", "config", "=", "$", "this", "->", "config", ";", "$", "this", "->", "pool", "->", "onConfigUpdated", "(", ")", ...
Called when worker is going to update configuration. @return void
[ "Called", "when", "worker", "is", "going", "to", "update", "configuration", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/Pool.php#L48-L54
kakserpom/phpdaemon
PHPDaemon/Core/Pool.php
Pool.onShutdown
public function onShutdown($graceful = false) { if ($this->pool) { return $this->pool->onShutdown($graceful); } return true; }
php
public function onShutdown($graceful = false) { if ($this->pool) { return $this->pool->onShutdown($graceful); } return true; }
[ "public", "function", "onShutdown", "(", "$", "graceful", "=", "false", ")", "{", "if", "(", "$", "this", "->", "pool", ")", "{", "return", "$", "this", "->", "pool", "->", "onShutdown", "(", "$", "graceful", ")", ";", "}", "return", "true", ";", "...
Called when application instance is going to shutdown. @return boolean Ready to shutdown?
[ "Called", "when", "application", "instance", "is", "going", "to", "shutdown", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/Pool.php#L60-L66
kakserpom/phpdaemon
PHPDaemon/Core/Pool.php
Pool.init
protected function init() { if ($this->isEnabled()) { list($class, $name) = explode(':', $this->name . ':'); $realclass = ClassFinder::find($class); $e = explode('\\', $realclass); if (($e[sizeof($e) - 1] !== 'Pool') && class_exists($realclass . '\\Pool')) { $realclass .= '\\Pool'; } if ($realclass !== $class) { $base = '\\PHPDaemon\\Core\\Pool:'; Daemon::$config->renameSection($base . $class . ($name !== '' ? ':' . $name : ''), $base . $realclass . ($name !== '' ? ':' . $name : '')); } if (!class_exists($realclass)) { Daemon::log($realclass . ' class not exists.'); return; } $func = [$realclass, 'getInstance']; $this->pool = $func($name); $this->pool->appInstance = $this; } }
php
protected function init() { if ($this->isEnabled()) { list($class, $name) = explode(':', $this->name . ':'); $realclass = ClassFinder::find($class); $e = explode('\\', $realclass); if (($e[sizeof($e) - 1] !== 'Pool') && class_exists($realclass . '\\Pool')) { $realclass .= '\\Pool'; } if ($realclass !== $class) { $base = '\\PHPDaemon\\Core\\Pool:'; Daemon::$config->renameSection($base . $class . ($name !== '' ? ':' . $name : ''), $base . $realclass . ($name !== '' ? ':' . $name : '')); } if (!class_exists($realclass)) { Daemon::log($realclass . ' class not exists.'); return; } $func = [$realclass, 'getInstance']; $this->pool = $func($name); $this->pool->appInstance = $this; } }
[ "protected", "function", "init", "(", ")", "{", "if", "(", "$", "this", "->", "isEnabled", "(", ")", ")", "{", "list", "(", "$", "class", ",", "$", "name", ")", "=", "explode", "(", "':'", ",", "$", "this", "->", "name", ".", "':'", ")", ";", ...
Constructor. @return void
[ "Constructor", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/Pool.php#L83-L105
kakserpom/phpdaemon
PHPDaemon/Config/Entry/Size.php
Size.humanToPlain
public static function humanToPlain($value) { $l = substr($value, -1); if ($l === 'b' || $l === 'B') { return ((int)substr($value, 0, -1)); } if ($l === 'k') { return ((int)substr($value, 0, -1) * 1000); } if ($l === 'K') { return ((int)substr($value, 0, -1) * 1024); } if ($l === 'm') { return ((int)substr($value, 0, -1) * 1000 * 1000); } if ($l === 'M') { return ((int)substr($value, 0, -1) * 1024 * 1024); } if ($l === 'g') { return ((int)substr($value, 0, -1) * 1000 * 1000 * 1000); } if ($l === 'G') { return ((int)substr($value, 0, -1) * 1024 * 1024 * 1024); } return (int)$value; }
php
public static function humanToPlain($value) { $l = substr($value, -1); if ($l === 'b' || $l === 'B') { return ((int)substr($value, 0, -1)); } if ($l === 'k') { return ((int)substr($value, 0, -1) * 1000); } if ($l === 'K') { return ((int)substr($value, 0, -1) * 1024); } if ($l === 'm') { return ((int)substr($value, 0, -1) * 1000 * 1000); } if ($l === 'M') { return ((int)substr($value, 0, -1) * 1024 * 1024); } if ($l === 'g') { return ((int)substr($value, 0, -1) * 1000 * 1000 * 1000); } if ($l === 'G') { return ((int)substr($value, 0, -1) * 1024 * 1024 * 1024); } return (int)$value; }
[ "public", "static", "function", "humanToPlain", "(", "$", "value", ")", "{", "$", "l", "=", "substr", "(", "$", "value", ",", "-", "1", ")", ";", "if", "(", "$", "l", "===", "'b'", "||", "$", "l", "===", "'B'", ")", "{", "return", "(", "(", "...
Converts human-readable value to plain @param $value @return int
[ "Converts", "human", "-", "readable", "value", "to", "plain" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Config/Entry/Size.php#L20-L53
kakserpom/phpdaemon
PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Basic/BasicConsumeFrame.php
BasicConsumeFrame.create
public static function create( $queue = null, $consumerTag = null, $noLocal = null, $noAck = null, $exclusive = null, $nowait = null, $arguments = null ) { $frame = new self(); if (null !== $queue) { $frame->queue = $queue; } if (null !== $consumerTag) { $frame->consumerTag = $consumerTag; } if (null !== $noLocal) { $frame->noLocal = $noLocal; } if (null !== $noAck) { $frame->noAck = $noAck; } if (null !== $exclusive) { $frame->exclusive = $exclusive; } if (null !== $nowait) { $frame->nowait = $nowait; } if (null !== $arguments) { $frame->arguments = $arguments; } return $frame; }
php
public static function create( $queue = null, $consumerTag = null, $noLocal = null, $noAck = null, $exclusive = null, $nowait = null, $arguments = null ) { $frame = new self(); if (null !== $queue) { $frame->queue = $queue; } if (null !== $consumerTag) { $frame->consumerTag = $consumerTag; } if (null !== $noLocal) { $frame->noLocal = $noLocal; } if (null !== $noAck) { $frame->noAck = $noAck; } if (null !== $exclusive) { $frame->exclusive = $exclusive; } if (null !== $nowait) { $frame->nowait = $nowait; } if (null !== $arguments) { $frame->arguments = $arguments; } return $frame; }
[ "public", "static", "function", "create", "(", "$", "queue", "=", "null", ",", "$", "consumerTag", "=", "null", ",", "$", "noLocal", "=", "null", ",", "$", "noAck", "=", "null", ",", "$", "exclusive", "=", "null", ",", "$", "nowait", "=", "null", "...
table
[ "table" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Basic/BasicConsumeFrame.php#L27-L56
kakserpom/phpdaemon
PHPDaemon/Servers/DebugConsole/Connection.php
Connection.onRead
public function onRead() { $seq = ["\xff\xf4\xff\xfd\x06", "\xff\xec", "\x03", "\x04"]; $finish = false; foreach ($seq as $s) { if ($this->search($s) !== false) { $finish = true; } } while (($line = $this->readline()) !== null) { $line = rtrim($line, "\r\n"); $e = explode(' ', $line, 2); $cmd = trim(strtolower($e[0])); $arg = isset($e[1]) ? $e[1] : ''; if ($cmd === 'quit' || $cmd === 'exit') { $this->disconnect(); } elseif (!$this->auth) { $this->checkPassword($line); } else { $this->processCommand($cmd, $arg); } } if ($finish) { $this->finish(); } }
php
public function onRead() { $seq = ["\xff\xf4\xff\xfd\x06", "\xff\xec", "\x03", "\x04"]; $finish = false; foreach ($seq as $s) { if ($this->search($s) !== false) { $finish = true; } } while (($line = $this->readline()) !== null) { $line = rtrim($line, "\r\n"); $e = explode(' ', $line, 2); $cmd = trim(strtolower($e[0])); $arg = isset($e[1]) ? $e[1] : ''; if ($cmd === 'quit' || $cmd === 'exit') { $this->disconnect(); } elseif (!$this->auth) { $this->checkPassword($line); } else { $this->processCommand($cmd, $arg); } } if ($finish) { $this->finish(); } }
[ "public", "function", "onRead", "(", ")", "{", "$", "seq", "=", "[", "\"\\xff\\xf4\\xff\\xfd\\x06\"", ",", "\"\\xff\\xec\"", ",", "\"\\x03\"", ",", "\"\\x04\"", "]", ";", "$", "finish", "=", "false", ";", "foreach", "(", "$", "seq", "as", "$", "s", ")", ...
Called when new data received. @return void
[ "Called", "when", "new", "data", "received", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/DebugConsole/Connection.php#L44-L71
kakserpom/phpdaemon
PHPDaemon/Servers/DebugConsole/Connection.php
Connection.checkPassword
protected function checkPassword($pass = '') { if (!hash_equals($this->pool->config->passphrase->value, $pass)) { --$this->authTries; if (0 === $this->authTries) { $this->disconnect(); } else { $this->write('Wrong password. Please, try again: '); } } else { $this->writeln('You are authorized.'); $this->auth = true; } }
php
protected function checkPassword($pass = '') { if (!hash_equals($this->pool->config->passphrase->value, $pass)) { --$this->authTries; if (0 === $this->authTries) { $this->disconnect(); } else { $this->write('Wrong password. Please, try again: '); } } else { $this->writeln('You are authorized.'); $this->auth = true; } }
[ "protected", "function", "checkPassword", "(", "$", "pass", "=", "''", ")", "{", "if", "(", "!", "hash_equals", "(", "$", "this", "->", "pool", "->", "config", "->", "passphrase", "->", "value", ",", "$", "pass", ")", ")", "{", "--", "$", "this", "...
Let's check the password @param string $pass Password @return void
[ "Let", "s", "check", "the", "password" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/DebugConsole/Connection.php#L87-L101
kakserpom/phpdaemon
PHPDaemon/Servers/DebugConsole/Connection.php
Connection.processCommand
protected function processCommand($command = '', $argument = '') { switch ($command) { case 'help': $this->writeln(' Debug console for phpDaemon. Allowed commands: help eval exit '); break; case 'ping': $this->writeln('pong'); break; case 'eval': ob_start(); eval($argument); $out = ob_get_contents(); ob_end_clean(); $this->writeln($out); break; default: $this->writeln('Unknown command "' . $command . '". Type "help" to get the list of allowed commands.'); } }
php
protected function processCommand($command = '', $argument = '') { switch ($command) { case 'help': $this->writeln(' Debug console for phpDaemon. Allowed commands: help eval exit '); break; case 'ping': $this->writeln('pong'); break; case 'eval': ob_start(); eval($argument); $out = ob_get_contents(); ob_end_clean(); $this->writeln($out); break; default: $this->writeln('Unknown command "' . $command . '". Type "help" to get the list of allowed commands.'); } }
[ "protected", "function", "processCommand", "(", "$", "command", "=", "''", ",", "$", "argument", "=", "''", ")", "{", "switch", "(", "$", "command", ")", "{", "case", "'help'", ":", "$", "this", "->", "writeln", "(", "'\nDebug console for phpDaemon.\nAllowed...
Run the command @param string $command Command to execute @param string $argument Argument @return void
[ "Run", "the", "command" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/DebugConsole/Connection.php#L109-L134
kakserpom/phpdaemon
PHPDaemon/Examples/ExampleAsyncProcessRequest.php
ExampleAsyncProcessRequest.init
public function init() { $this->header('Content-Type: text/plain'); $this->proc = new \PHPDaemon\Core\ShellCommand(); $this->proc->onReadData(function ($stream, $data) { echo $data; }); $this->proc->onEOF(function ($stream) { $this->wakeup(); }); $this->proc->nice(256); $this->proc->execute('/bin/ls -l /tmp'); }
php
public function init() { $this->header('Content-Type: text/plain'); $this->proc = new \PHPDaemon\Core\ShellCommand(); $this->proc->onReadData(function ($stream, $data) { echo $data; }); $this->proc->onEOF(function ($stream) { $this->wakeup(); }); $this->proc->nice(256); $this->proc->execute('/bin/ls -l /tmp'); }
[ "public", "function", "init", "(", ")", "{", "$", "this", "->", "header", "(", "'Content-Type: text/plain'", ")", ";", "$", "this", "->", "proc", "=", "new", "\\", "PHPDaemon", "\\", "Core", "\\", "ShellCommand", "(", ")", ";", "$", "this", "->", "proc...
Constructor. @return void
[ "Constructor", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Examples/ExampleAsyncProcessRequest.php#L15-L28
kakserpom/phpdaemon
PHPDaemon/Examples/ExampleDNSClientRequest.php
ExampleDNSClientRequest.init
public function init() { $req = $this; $job = $this->job = new \PHPDaemon\Core\ComplexJob(function () use ($req) { // called when job is done $req->wakeup(); // wake up the request immediately }); $job('query', function ($name, $job) { // registering job named 'showvar' \PHPDaemon\Clients\DNS\Pool::getInstance()->get('phpdaemon.net', function ($response) use ($name, $job) { $job->setResult($name, $response); }); }); $job('resolve', function ($name, $job) { // registering job named 'showvar' \PHPDaemon\Clients\DNS\Pool::getInstance()->resolve('phpdaemon.net', function ($ip) use ($name, $job) { $job->setResult($name, ['phpdaemon.net resolved to' => $ip]); }); }); $job(); // let the fun begin $this->sleep(5, true); // setting timeout }
php
public function init() { $req = $this; $job = $this->job = new \PHPDaemon\Core\ComplexJob(function () use ($req) { // called when job is done $req->wakeup(); // wake up the request immediately }); $job('query', function ($name, $job) { // registering job named 'showvar' \PHPDaemon\Clients\DNS\Pool::getInstance()->get('phpdaemon.net', function ($response) use ($name, $job) { $job->setResult($name, $response); }); }); $job('resolve', function ($name, $job) { // registering job named 'showvar' \PHPDaemon\Clients\DNS\Pool::getInstance()->resolve('phpdaemon.net', function ($ip) use ($name, $job) { $job->setResult($name, ['phpdaemon.net resolved to' => $ip]); }); }); $job(); // let the fun begin $this->sleep(5, true); // setting timeout }
[ "public", "function", "init", "(", ")", "{", "$", "req", "=", "$", "this", ";", "$", "job", "=", "$", "this", "->", "job", "=", "new", "\\", "PHPDaemon", "\\", "Core", "\\", "ComplexJob", "(", "function", "(", ")", "use", "(", "$", "req", ")", ...
Constructor. @return void
[ "Constructor", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Examples/ExampleDNSClientRequest.php#L15-L39
kakserpom/phpdaemon
PHPDaemon/Examples/ExampleDNSClientRequest.php
ExampleDNSClientRequest.run
public function run() { try { $this->header('Content-Type: text/plain'); } catch (\Exception $e) { } var_dump($this->job->getResult('query')); var_dump($this->job->getResult('resolve')); }
php
public function run() { try { $this->header('Content-Type: text/plain'); } catch (\Exception $e) { } var_dump($this->job->getResult('query')); var_dump($this->job->getResult('resolve')); }
[ "public", "function", "run", "(", ")", "{", "try", "{", "$", "this", "->", "header", "(", "'Content-Type: text/plain'", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "}", "var_dump", "(", "$", "this", "->", "job", "->", "getResu...
Called when request iterated. @return integer Status.
[ "Called", "when", "request", "iterated", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Examples/ExampleDNSClientRequest.php#L45-L53
kakserpom/phpdaemon
PHPDaemon/Servers/WebSocket/Protocols/V0.php
V0.sendHandshakeReply
public function sendHandshakeReply($extraHeaders = '') { if (!isset($this->server['HTTP_SEC_WEBSOCKET_KEY1']) || !isset($this->server['HTTP_SEC_WEBSOCKET_KEY2'])) { return false; } $final_key = $this->_computeFinalKey( $this->server['HTTP_SEC_WEBSOCKET_KEY1'], $this->server['HTTP_SEC_WEBSOCKET_KEY2'], $this->key ); $this->key = null; if (!$final_key) { return false; } if (!isset($this->server['HTTP_SEC_WEBSOCKET_ORIGIN'])) { $this->server['HTTP_SEC_WEBSOCKET_ORIGIN'] = ''; } $this->write("HTTP/1.1 101 Web Socket Protocol Handshake\r\n" . "Upgrade: WebSocket\r\n" . "Connection: Upgrade\r\n" . "Sec-WebSocket-Origin: " . $this->server['HTTP_ORIGIN'] . "\r\n" . "Sec-WebSocket-Location: ws://" . $this->server['HTTP_HOST'] . $this->server['REQUEST_URI'] . "\r\n"); if ($this->pool->config->expose->value) { $this->writeln('X-Powered-By: phpDaemon/' . Daemon::$version); } if (isset($this->server['HTTP_SEC_WEBSOCKET_PROTOCOL'])) { $this->writeln("Sec-WebSocket-Protocol: " . $this->server['HTTP_SEC_WEBSOCKET_PROTOCOL']); } $this->write($extraHeaders . "\r\n" . $final_key); return true; }
php
public function sendHandshakeReply($extraHeaders = '') { if (!isset($this->server['HTTP_SEC_WEBSOCKET_KEY1']) || !isset($this->server['HTTP_SEC_WEBSOCKET_KEY2'])) { return false; } $final_key = $this->_computeFinalKey( $this->server['HTTP_SEC_WEBSOCKET_KEY1'], $this->server['HTTP_SEC_WEBSOCKET_KEY2'], $this->key ); $this->key = null; if (!$final_key) { return false; } if (!isset($this->server['HTTP_SEC_WEBSOCKET_ORIGIN'])) { $this->server['HTTP_SEC_WEBSOCKET_ORIGIN'] = ''; } $this->write("HTTP/1.1 101 Web Socket Protocol Handshake\r\n" . "Upgrade: WebSocket\r\n" . "Connection: Upgrade\r\n" . "Sec-WebSocket-Origin: " . $this->server['HTTP_ORIGIN'] . "\r\n" . "Sec-WebSocket-Location: ws://" . $this->server['HTTP_HOST'] . $this->server['REQUEST_URI'] . "\r\n"); if ($this->pool->config->expose->value) { $this->writeln('X-Powered-By: phpDaemon/' . Daemon::$version); } if (isset($this->server['HTTP_SEC_WEBSOCKET_PROTOCOL'])) { $this->writeln("Sec-WebSocket-Protocol: " . $this->server['HTTP_SEC_WEBSOCKET_PROTOCOL']); } $this->write($extraHeaders . "\r\n" . $final_key); return true; }
[ "public", "function", "sendHandshakeReply", "(", "$", "extraHeaders", "=", "''", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "server", "[", "'HTTP_SEC_WEBSOCKET_KEY1'", "]", ")", "||", "!", "isset", "(", "$", "this", "->", "server", "[", ...
Sends a handshake message reply @param string Received data (no use in this class) @return boolean OK?
[ "Sends", "a", "handshake", "message", "reply" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/WebSocket/Protocols/V0.php#L24-L58
kakserpom/phpdaemon
PHPDaemon/Servers/WebSocket/Protocols/V0.php
V0._computeFinalKey
protected function _computeFinalKey($key1, $key2, $data) { if (mb_orig_strlen($data) < 8) { Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Invalid handshake data for client "' . $this->addr . '"'); return false; } return md5($this->_computeKey($key1) . $this->_computeKey($key2) . mb_orig_substr($data, 0, 8), true); }
php
protected function _computeFinalKey($key1, $key2, $data) { if (mb_orig_strlen($data) < 8) { Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Invalid handshake data for client "' . $this->addr . '"'); return false; } return md5($this->_computeKey($key1) . $this->_computeKey($key2) . mb_orig_substr($data, 0, 8), true); }
[ "protected", "function", "_computeFinalKey", "(", "$", "key1", ",", "$", "key2", ",", "$", "data", ")", "{", "if", "(", "mb_orig_strlen", "(", "$", "data", ")", "<", "8", ")", "{", "Daemon", "::", "$", "process", "->", "log", "(", "get_class", "(", ...
Computes final key for Sec-WebSocket. @param string Key1 @param string Key2 @param string Data @return string Result
[ "Computes", "final", "key", "for", "Sec", "-", "WebSocket", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/WebSocket/Protocols/V0.php#L67-L74
kakserpom/phpdaemon
PHPDaemon/Servers/WebSocket/Protocols/V0.php
V0._computeKey
protected function _computeKey($key) { $spaces = 0; $digits = ''; for ($i = 0, $s = mb_orig_strlen($key); $i < $s; ++$i) { $c = mb_orig_substr($key, $i, 1); if ($c === "\x20") { ++$spaces; } elseif (ctype_digit($c)) { $digits .= $c; } } if ($spaces > 0) { $result = (float)floor($digits / $spaces); } else { $result = (float)$digits; } return pack('N', $result); }
php
protected function _computeKey($key) { $spaces = 0; $digits = ''; for ($i = 0, $s = mb_orig_strlen($key); $i < $s; ++$i) { $c = mb_orig_substr($key, $i, 1); if ($c === "\x20") { ++$spaces; } elseif (ctype_digit($c)) { $digits .= $c; } } if ($spaces > 0) { $result = (float)floor($digits / $spaces); } else { $result = (float)$digits; } return pack('N', $result); }
[ "protected", "function", "_computeKey", "(", "$", "key", ")", "{", "$", "spaces", "=", "0", ";", "$", "digits", "=", "''", ";", "for", "(", "$", "i", "=", "0", ",", "$", "s", "=", "mb_orig_strlen", "(", "$", "key", ")", ";", "$", "i", "<", "$...
Computes key for Sec-WebSocket. @param string Key @return string Result
[ "Computes", "key", "for", "Sec", "-", "WebSocket", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/WebSocket/Protocols/V0.php#L81-L103
kakserpom/phpdaemon
PHPDaemon/Servers/WebSocket/Protocols/V0.php
V0.onRead
public function onRead() { if ($this->state === self::STATE_PREHANDSHAKE) { if ($this->getInputLength() < 8) { return; } $this->key = $this->readUnlimited(); $this->handshake(); } if ($this->state === self::STATE_HANDSHAKED) { while (($buflen = $this->getInputLength()) >= 2) { $hdr = $this->look(10); $frametype = ord(mb_orig_substr($hdr, 0, 1)); if (($frametype & 0x80) === 0x80) { $len = 0; $i = 0; do { if ($buflen < $i + 1) { // not enough data yet return; } $b = ord(mb_orig_substr($hdr, ++$i, 1)); $n = $b & 0x7F; $len *= 0x80; $len += $n; } while ($b > 0x80); if ($this->pool->maxAllowedPacket <= $len) { // Too big packet $this->finish(); return; } if ($buflen < $len + $i + 1) { // not enough data yet return; } $this->drain($i + 1); $this->onFrame($this->read($len), 'BINARY'); } else { if (($p = $this->search("\xFF")) !== false) { if ($this->pool->maxAllowedPacket <= $p - 1) { // Too big packet $this->finish(); return; } $this->drain(1); $data = $this->read($p); $this->drain(1); $this->onFrame($data, 'STRING'); } else { if ($this->pool->maxAllowedPacket < $buflen - 1) { // Too big packet $this->finish(); return; } // not enough data yet return; } } } } }
php
public function onRead() { if ($this->state === self::STATE_PREHANDSHAKE) { if ($this->getInputLength() < 8) { return; } $this->key = $this->readUnlimited(); $this->handshake(); } if ($this->state === self::STATE_HANDSHAKED) { while (($buflen = $this->getInputLength()) >= 2) { $hdr = $this->look(10); $frametype = ord(mb_orig_substr($hdr, 0, 1)); if (($frametype & 0x80) === 0x80) { $len = 0; $i = 0; do { if ($buflen < $i + 1) { // not enough data yet return; } $b = ord(mb_orig_substr($hdr, ++$i, 1)); $n = $b & 0x7F; $len *= 0x80; $len += $n; } while ($b > 0x80); if ($this->pool->maxAllowedPacket <= $len) { // Too big packet $this->finish(); return; } if ($buflen < $len + $i + 1) { // not enough data yet return; } $this->drain($i + 1); $this->onFrame($this->read($len), 'BINARY'); } else { if (($p = $this->search("\xFF")) !== false) { if ($this->pool->maxAllowedPacket <= $p - 1) { // Too big packet $this->finish(); return; } $this->drain(1); $data = $this->read($p); $this->drain(1); $this->onFrame($data, 'STRING'); } else { if ($this->pool->maxAllowedPacket < $buflen - 1) { // Too big packet $this->finish(); return; } // not enough data yet return; } } } } }
[ "public", "function", "onRead", "(", ")", "{", "if", "(", "$", "this", "->", "state", "===", "self", "::", "STATE_PREHANDSHAKE", ")", "{", "if", "(", "$", "this", "->", "getInputLength", "(", ")", "<", "8", ")", "{", "return", ";", "}", "$", "this"...
Called when new data received @return void
[ "Called", "when", "new", "data", "received" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/WebSocket/Protocols/V0.php#L166-L228
kakserpom/phpdaemon
PHPDaemon/Examples/ExampleRequest.php
ExampleRequest.run
public function run() { $this->sessionStart(); try { $this->header('Content-Type: text/html'); $this->setcookie('testcookie', '1'); } catch (\PHPDaemon\Request\RequestHeadersAlreadySent $e) { } $this->registerShutdownFunction(function () { ?> </html> <?php }); if (!isset($_SESSION['counter'])) { $_SESSION['counter'] = 0; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>It works!</title> </head> <body> <h1>It works! Be happy! ;-) </h1> *Hello world!<br/> Testing Error Message: <?php trigger_error('_text_of_notice_'); ?> <br/>Counter of requests to this Application Instance: <b><?php echo ++$this->appInstance->counter; ?></b> <br />Counter in session: <?php echo ++$_SESSION['counter']; ?> <br/>Memory usage: <?php $mem = memory_get_usage(); echo($mem / 1024 / 1024); ?> MB. (<?php echo $mem; ?>) <br/>Memory real usage: <?php $mem = memory_get_usage(true); echo($mem / 1024 / 1024); ?> MB. (<?php echo $mem; ?>) <br/>My PID: <?php echo getmypid(); ?>. <?php $user = posix_getpwuid(posix_getuid()); $group = posix_getgrgid(posix_getgid()); ?> <br/>My user/group: <?php echo $user['name'] . '/' . $group['name']; ?> <?php $displaystate = true; if ($displaystate) { ?><br/><br/><b>State of workers:</b><?php $stat = \PHPDaemon\Core\Daemon::getStateOfWorkers(); ?> <br/>Idle: <?php echo $stat['idle']; ?> <br/>Busy: <?php echo $stat['busy']; ?> <br/>Total alive: <?php echo $stat['alive']; ?> <br/>Shutdown: <?php echo $stat['shutdown']; ?> <br/>Pre-init: <?php echo $stat['preinit']; ?> <br/>Init: <?php echo $stat['init']; ?> <br/> <?php } ?> <br/><br/> <br/><br/> <form action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES); ?>" method="post" enctype="multipart/form-data"> <input type="file" name="myfile"/> <input type="submit" name="submit" value="Upload"/> </form> <br/> <form action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES); ?>" method="post"> <input type="text" name="mytext" value=""/> <input type="submit" name="submit" value="Send"/> </form> <pre> <?php var_dump([ '_GET' => $_GET, '_POST' => $_POST, '_COOKIE' => $_COOKIE, '_REQUEST' => $_REQUEST, '_FILES' => $_FILES, '_SERVER' => $_SERVER ]); ?></pre> <br/>Request took: <?php printf('%f', round(microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'], 6)); //echo '<!-- '. str_repeat('x',1024*1024).' --->'; //echo '<!-- '. str_repeat('x',1024*1024).' --->'; //echo '<!-- '. str_repeat('x',1024*1024).' --->'; ?> </body> <?php }
php
public function run() { $this->sessionStart(); try { $this->header('Content-Type: text/html'); $this->setcookie('testcookie', '1'); } catch (\PHPDaemon\Request\RequestHeadersAlreadySent $e) { } $this->registerShutdownFunction(function () { ?> </html> <?php }); if (!isset($_SESSION['counter'])) { $_SESSION['counter'] = 0; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>It works!</title> </head> <body> <h1>It works! Be happy! ;-) </h1> *Hello world!<br/> Testing Error Message: <?php trigger_error('_text_of_notice_'); ?> <br/>Counter of requests to this Application Instance: <b><?php echo ++$this->appInstance->counter; ?></b> <br />Counter in session: <?php echo ++$_SESSION['counter']; ?> <br/>Memory usage: <?php $mem = memory_get_usage(); echo($mem / 1024 / 1024); ?> MB. (<?php echo $mem; ?>) <br/>Memory real usage: <?php $mem = memory_get_usage(true); echo($mem / 1024 / 1024); ?> MB. (<?php echo $mem; ?>) <br/>My PID: <?php echo getmypid(); ?>. <?php $user = posix_getpwuid(posix_getuid()); $group = posix_getgrgid(posix_getgid()); ?> <br/>My user/group: <?php echo $user['name'] . '/' . $group['name']; ?> <?php $displaystate = true; if ($displaystate) { ?><br/><br/><b>State of workers:</b><?php $stat = \PHPDaemon\Core\Daemon::getStateOfWorkers(); ?> <br/>Idle: <?php echo $stat['idle']; ?> <br/>Busy: <?php echo $stat['busy']; ?> <br/>Total alive: <?php echo $stat['alive']; ?> <br/>Shutdown: <?php echo $stat['shutdown']; ?> <br/>Pre-init: <?php echo $stat['preinit']; ?> <br/>Init: <?php echo $stat['init']; ?> <br/> <?php } ?> <br/><br/> <br/><br/> <form action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES); ?>" method="post" enctype="multipart/form-data"> <input type="file" name="myfile"/> <input type="submit" name="submit" value="Upload"/> </form> <br/> <form action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES); ?>" method="post"> <input type="text" name="mytext" value=""/> <input type="submit" name="submit" value="Send"/> </form> <pre> <?php var_dump([ '_GET' => $_GET, '_POST' => $_POST, '_COOKIE' => $_COOKIE, '_REQUEST' => $_REQUEST, '_FILES' => $_FILES, '_SERVER' => $_SERVER ]); ?></pre> <br/>Request took: <?php printf('%f', round(microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'], 6)); //echo '<!-- '. str_repeat('x',1024*1024).' --->'; //echo '<!-- '. str_repeat('x',1024*1024).' --->'; //echo '<!-- '. str_repeat('x',1024*1024).' --->'; ?> </body> <?php }
[ "public", "function", "run", "(", ")", "{", "$", "this", "->", "sessionStart", "(", ")", ";", "try", "{", "$", "this", "->", "header", "(", "'Content-Type: text/html'", ")", ";", "$", "this", "->", "setcookie", "(", "'testcookie'", ",", "'1'", ")", ";"...
Called when request iterated. @return integer Status.
[ "Called", "when", "request", "iterated", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Examples/ExampleRequest.php#L12-L128
kakserpom/phpdaemon
PHPDaemon/Servers/WebSocket/Protocols/V13.php
V13.sendHandshakeReply
public function sendHandshakeReply($extraHeaders = '') { if (!isset($this->server['HTTP_SEC_WEBSOCKET_KEY']) || !isset($this->server['HTTP_SEC_WEBSOCKET_VERSION'])) { return false; } if ($this->server['HTTP_SEC_WEBSOCKET_VERSION'] !== '13' && $this->server['HTTP_SEC_WEBSOCKET_VERSION'] !== '8') { return false; } if (isset($this->server['HTTP_ORIGIN'])) { $this->server['HTTP_SEC_WEBSOCKET_ORIGIN'] = $this->server['HTTP_ORIGIN']; } if (!isset($this->server['HTTP_SEC_WEBSOCKET_ORIGIN'])) { $this->server['HTTP_SEC_WEBSOCKET_ORIGIN'] = ''; } $this->write( "HTTP/1.1 101 Switching Protocols\r\n" . "Upgrade: WebSocket\r\n" . "Connection: Upgrade\r\n" . "Date: " . date('r') . "\r\n" . "Sec-WebSocket-Origin: " . $this->server['HTTP_SEC_WEBSOCKET_ORIGIN'] . "\r\n" . "Sec-WebSocket-Location: ws://" . $this->server['HTTP_HOST'] . $this->server['REQUEST_URI'] . "\r\n" . "Sec-WebSocket-Accept: " . base64_encode( sha1( trim( $this->server['HTTP_SEC_WEBSOCKET_KEY'] ) . "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", true ) ) . "\r\n" ); if (isset($this->server['HTTP_SEC_WEBSOCKET_PROTOCOL'])) { $this->writeln("Sec-WebSocket-Protocol: " . $this->server['HTTP_SEC_WEBSOCKET_PROTOCOL']); } if ($this->pool->config->expose->value) { $this->writeln('X-Powered-By: phpDaemon/' . Daemon::$version); } $this->writeln($extraHeaders); return true; }
php
public function sendHandshakeReply($extraHeaders = '') { if (!isset($this->server['HTTP_SEC_WEBSOCKET_KEY']) || !isset($this->server['HTTP_SEC_WEBSOCKET_VERSION'])) { return false; } if ($this->server['HTTP_SEC_WEBSOCKET_VERSION'] !== '13' && $this->server['HTTP_SEC_WEBSOCKET_VERSION'] !== '8') { return false; } if (isset($this->server['HTTP_ORIGIN'])) { $this->server['HTTP_SEC_WEBSOCKET_ORIGIN'] = $this->server['HTTP_ORIGIN']; } if (!isset($this->server['HTTP_SEC_WEBSOCKET_ORIGIN'])) { $this->server['HTTP_SEC_WEBSOCKET_ORIGIN'] = ''; } $this->write( "HTTP/1.1 101 Switching Protocols\r\n" . "Upgrade: WebSocket\r\n" . "Connection: Upgrade\r\n" . "Date: " . date('r') . "\r\n" . "Sec-WebSocket-Origin: " . $this->server['HTTP_SEC_WEBSOCKET_ORIGIN'] . "\r\n" . "Sec-WebSocket-Location: ws://" . $this->server['HTTP_HOST'] . $this->server['REQUEST_URI'] . "\r\n" . "Sec-WebSocket-Accept: " . base64_encode( sha1( trim( $this->server['HTTP_SEC_WEBSOCKET_KEY'] ) . "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", true ) ) . "\r\n" ); if (isset($this->server['HTTP_SEC_WEBSOCKET_PROTOCOL'])) { $this->writeln("Sec-WebSocket-Protocol: " . $this->server['HTTP_SEC_WEBSOCKET_PROTOCOL']); } if ($this->pool->config->expose->value) { $this->writeln('X-Powered-By: phpDaemon/' . Daemon::$version); } $this->writeln($extraHeaders); return true; }
[ "public", "function", "sendHandshakeReply", "(", "$", "extraHeaders", "=", "''", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "server", "[", "'HTTP_SEC_WEBSOCKET_KEY'", "]", ")", "||", "!", "isset", "(", "$", "this", "->", "server", "[", ...
Sends a handshake message reply @param string Received data (no use in this class) @return boolean OK?
[ "Sends", "a", "handshake", "message", "reply" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/WebSocket/Protocols/V13.php#L39-L83
kakserpom/phpdaemon
PHPDaemon/Servers/WebSocket/Protocols/V13.php
V13.sendFrame
public function sendFrame($data, $type = null, $cb = null) { if (!$this->handshaked) { return false; } if ($this->finished && $type !== 'CONNCLOSE') { return false; } /*if (in_array($type, ['STRING', 'BINARY']) && ($this->outgoingCompression > 0) && in_array('deflate-frame', $this->extensions)) { //$data = gzcompress($data, $this->outgoingCompression); //$rsv1 = 1; }*/ $fin = 1; $rsv1 = 0; $rsv2 = 0; $rsv3 = 0; $this->write( chr( bindec( $fin . $rsv1 . $rsv2 . $rsv3 . str_pad( decbin( $this->getFrameType($type) ), 4, '0', STR_PAD_LEFT ) ) ) ); $dataLength = mb_orig_strlen($data); $isMasked = false; $isMaskedInt = $isMasked ? 128 : 0; if ($dataLength <= 125) { $this->write(chr($dataLength + $isMaskedInt)); } elseif ($dataLength <= 65535) { $this->write(chr(126 + $isMaskedInt) . // 126 + 128 chr($dataLength >> 8) . chr($dataLength & 0xFF)); } else { $this->write(chr(127 + $isMaskedInt) . // 127 + 128 chr($dataLength >> 56) . chr($dataLength >> 48) . chr($dataLength >> 40) . chr($dataLength >> 32) . chr($dataLength >> 24) . chr($dataLength >> 16) . chr($dataLength >> 8) . chr($dataLength & 0xFF)); } if ($isMasked) { $mask = chr(mt_rand(0, 0xFF)) . chr(mt_rand(0, 0xFF)) . chr(mt_rand(0, 0xFF)) . chr(mt_rand(0, 0xFF)); $this->write($mask . $this->mask($data, $mask)); } else { $this->write($data); } if ($cb !== null) { $this->onWriteOnce($cb); } return true; }
php
public function sendFrame($data, $type = null, $cb = null) { if (!$this->handshaked) { return false; } if ($this->finished && $type !== 'CONNCLOSE') { return false; } /*if (in_array($type, ['STRING', 'BINARY']) && ($this->outgoingCompression > 0) && in_array('deflate-frame', $this->extensions)) { //$data = gzcompress($data, $this->outgoingCompression); //$rsv1 = 1; }*/ $fin = 1; $rsv1 = 0; $rsv2 = 0; $rsv3 = 0; $this->write( chr( bindec( $fin . $rsv1 . $rsv2 . $rsv3 . str_pad( decbin( $this->getFrameType($type) ), 4, '0', STR_PAD_LEFT ) ) ) ); $dataLength = mb_orig_strlen($data); $isMasked = false; $isMaskedInt = $isMasked ? 128 : 0; if ($dataLength <= 125) { $this->write(chr($dataLength + $isMaskedInt)); } elseif ($dataLength <= 65535) { $this->write(chr(126 + $isMaskedInt) . // 126 + 128 chr($dataLength >> 8) . chr($dataLength & 0xFF)); } else { $this->write(chr(127 + $isMaskedInt) . // 127 + 128 chr($dataLength >> 56) . chr($dataLength >> 48) . chr($dataLength >> 40) . chr($dataLength >> 32) . chr($dataLength >> 24) . chr($dataLength >> 16) . chr($dataLength >> 8) . chr($dataLength & 0xFF)); } if ($isMasked) { $mask = chr(mt_rand(0, 0xFF)) . chr(mt_rand(0, 0xFF)) . chr(mt_rand(0, 0xFF)) . chr(mt_rand(0, 0xFF)); $this->write($mask . $this->mask($data, $mask)); } else { $this->write($data); } if ($cb !== null) { $this->onWriteOnce($cb); } return true; }
[ "public", "function", "sendFrame", "(", "$", "data", ",", "$", "type", "=", "null", ",", "$", "cb", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "handshaked", ")", "{", "return", "false", ";", "}", "if", "(", "$", "this", "->", "fi...
Sends a frame. @param string $data Frame's data. @param string $type Frame's type. ("STRING" OR "BINARY") @param callable $cb Optional. Callback called when the frame is received by client. @callback $cb ( ) @return boolean Success.
[ "Sends", "a", "frame", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/WebSocket/Protocols/V13.php#L94-L161