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/Network/IOStream.php
IOStream.close
public function close() { if (!$this->freed) { $this->freed = true; if (isset($this->bev)) { $this->bev->free(); } $this->bev = null; //$this->eventLoop->interrupt(); } if ($this->pool) { $this->pool->detach($this); } }
php
public function close() { if (!$this->freed) { $this->freed = true; if (isset($this->bev)) { $this->bev->free(); } $this->bev = null; //$this->eventLoop->interrupt(); } if ($this->pool) { $this->pool->detach($this); } }
[ "public", "function", "close", "(", ")", "{", "if", "(", "!", "$", "this", "->", "freed", ")", "{", "$", "this", "->", "freed", "=", "true", ";", "if", "(", "isset", "(", "$", "this", "->", "bev", ")", ")", "{", "$", "this", "->", "bev", "->"...
Close the connection @return void
[ "Close", "the", "connection" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L734-L747
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.onReadEv
public function onReadEv($bev) { if (!$this->ready) { $this->wRead = true; return; } if ($this->finished) { return; } try { $this->onRead(); } catch (\Exception $e) { Daemon::uncaughtExceptionHandler($e); } }
php
public function onReadEv($bev) { if (!$this->ready) { $this->wRead = true; return; } if ($this->finished) { return; } try { $this->onRead(); } catch (\Exception $e) { Daemon::uncaughtExceptionHandler($e); } }
[ "public", "function", "onReadEv", "(", "$", "bev", ")", "{", "if", "(", "!", "$", "this", "->", "ready", ")", "{", "$", "this", "->", "wRead", "=", "true", ";", "return", ";", "}", "if", "(", "$", "this", "->", "finished", ")", "{", "return", "...
Called when the connection has got new data @param object $bev EventBufferEvent @return void
[ "Called", "when", "the", "connection", "has", "got", "new", "data" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L774-L788
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.onWriteOnce
public function onWriteOnce($cb) { if (!$this->writing) { $cb($this); return; } $this->onWriteOnce->push($cb); }
php
public function onWriteOnce($cb) { if (!$this->writing) { $cb($this); return; } $this->onWriteOnce->push($cb); }
[ "public", "function", "onWriteOnce", "(", "$", "cb", ")", "{", "if", "(", "!", "$", "this", "->", "writing", ")", "{", "$", "cb", "(", "$", "this", ")", ";", "return", ";", "}", "$", "this", "->", "onWriteOnce", "->", "push", "(", "$", "cb", ")...
Push callback which will be called only once, when writing is available next time @param callable $cb Callback @return void
[ "Push", "callback", "which", "will", "be", "called", "only", "once", "when", "writing", "is", "available", "next", "time" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L811-L818
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.onWriteEv
public function onWriteEv($bev) { $this->writing = false; if ($this->finished) { if ($this->bev->output->length === 0) { $this->close(); } return; } if (!$this->ready) { $this->ready = true; while (!$this->onWriteOnce->isEmpty()) { try { $this->onWriteOnce->executeOne($this); } catch (\Exception $e) { Daemon::uncaughtExceptionHandler($e); } if (!$this->ready) { return; } } $this->alive = true; try { $this->onReady(); if ($this->wRead) { $this->wRead = false; $this->onRead(); } } catch (\Exception $e) { Daemon::uncaughtExceptionHandler($e); } } else { $this->onWriteOnce->executeAll($this); } try { $this->onWrite(); } catch (\Exception $e) { Daemon::uncaughtExceptionHandler($e); } }
php
public function onWriteEv($bev) { $this->writing = false; if ($this->finished) { if ($this->bev->output->length === 0) { $this->close(); } return; } if (!$this->ready) { $this->ready = true; while (!$this->onWriteOnce->isEmpty()) { try { $this->onWriteOnce->executeOne($this); } catch (\Exception $e) { Daemon::uncaughtExceptionHandler($e); } if (!$this->ready) { return; } } $this->alive = true; try { $this->onReady(); if ($this->wRead) { $this->wRead = false; $this->onRead(); } } catch (\Exception $e) { Daemon::uncaughtExceptionHandler($e); } } else { $this->onWriteOnce->executeAll($this); } try { $this->onWrite(); } catch (\Exception $e) { Daemon::uncaughtExceptionHandler($e); } }
[ "public", "function", "onWriteEv", "(", "$", "bev", ")", "{", "$", "this", "->", "writing", "=", "false", ";", "if", "(", "$", "this", "->", "finished", ")", "{", "if", "(", "$", "this", "->", "bev", "->", "output", "->", "length", "===", "0", ")...
Called when the connection is ready to accept new data @param object $bev EventBufferEvent @return void
[ "Called", "when", "the", "connection", "is", "ready", "to", "accept", "new", "data" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L825-L864
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.onStateEv
public function onStateEv($bev, $events) { if ($events & \EventBufferEvent::CONNECTED) { $this->onWriteEv($bev); } elseif ($events & \EventBufferEvent::TIMEOUT) { $this->timedout = true; $this->finish(); } elseif ($events & (\EventBufferEvent::ERROR | \EventBufferEvent::EOF)) { try { if ($this->finished) { return; } if ($events & \EventBufferEvent::ERROR) { $errno = \EventUtil::getLastSocketErrno(); if ($errno !== 0 && $errno !== 104) { $this->log('Socket error #' . $errno . ':' . \EventUtil::getLastSocketError()); } if ($this->ssl && $this->bev) { while ($err = $this->bev->sslError()) { $this->log('EventBufferEvent SSL error: ' . $err); } } } $this->finished = true; $this->onFinish(); $this->close(); } catch (\Exception $e) { Daemon::uncaughtExceptionHandler($e); } } }
php
public function onStateEv($bev, $events) { if ($events & \EventBufferEvent::CONNECTED) { $this->onWriteEv($bev); } elseif ($events & \EventBufferEvent::TIMEOUT) { $this->timedout = true; $this->finish(); } elseif ($events & (\EventBufferEvent::ERROR | \EventBufferEvent::EOF)) { try { if ($this->finished) { return; } if ($events & \EventBufferEvent::ERROR) { $errno = \EventUtil::getLastSocketErrno(); if ($errno !== 0 && $errno !== 104) { $this->log('Socket error #' . $errno . ':' . \EventUtil::getLastSocketError()); } if ($this->ssl && $this->bev) { while ($err = $this->bev->sslError()) { $this->log('EventBufferEvent SSL error: ' . $err); } } } $this->finished = true; $this->onFinish(); $this->close(); } catch (\Exception $e) { Daemon::uncaughtExceptionHandler($e); } } }
[ "public", "function", "onStateEv", "(", "$", "bev", ",", "$", "events", ")", "{", "if", "(", "$", "events", "&", "\\", "EventBufferEvent", "::", "CONNECTED", ")", "{", "$", "this", "->", "onWriteEv", "(", "$", "bev", ")", ";", "}", "elseif", "(", "...
Called when the connection state changed @param object $bev EventBufferEvent @param integer $events Events @return void
[ "Called", "when", "the", "connection", "state", "changed" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L872-L902
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.moveToBuffer
public function moveToBuffer(\EventBuffer $dest, $n) { if (!isset($this->bev)) { return false; } return $dest->appendFrom($this->bev->input, $n); }
php
public function moveToBuffer(\EventBuffer $dest, $n) { if (!isset($this->bev)) { return false; } return $dest->appendFrom($this->bev->input, $n); }
[ "public", "function", "moveToBuffer", "(", "\\", "EventBuffer", "$", "dest", ",", "$", "n", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "bev", ")", ")", "{", "return", "false", ";", "}", "return", "$", "dest", "->", "appendFrom", "("...
Moves arbitrary number of bytes from input buffer to given buffer @param \EventBuffer $dest Destination nuffer @param integer $n Max. number of bytes to move @return integer|false
[ "Moves", "arbitrary", "number", "of", "bytes", "from", "input", "buffer", "to", "given", "buffer" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L910-L916
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.writeFromBuffer
public function writeFromBuffer(\EventBuffer $src, $n) { if (!isset($this->bev)) { return false; } $this->writing = true; return $this->bev->output->appendFrom($src, $n); }
php
public function writeFromBuffer(\EventBuffer $src, $n) { if (!isset($this->bev)) { return false; } $this->writing = true; return $this->bev->output->appendFrom($src, $n); }
[ "public", "function", "writeFromBuffer", "(", "\\", "EventBuffer", "$", "src", ",", "$", "n", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "bev", ")", ")", "{", "return", "false", ";", "}", "$", "this", "->", "writing", "=", "true", ...
Moves arbitrary number of bytes from given buffer to output buffer @param \EventBuffer $src Source buffer @param integer $n Max. number of bytes to move @return integer|false
[ "Moves", "arbitrary", "number", "of", "bytes", "from", "given", "buffer", "to", "output", "buffer" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L924-L931
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.read
public function read($n) { if ($n <= 0) { return ''; } if (!isset($this->bev)) { return false; } $read = $this->bev->read($n); if ($read === null) { return false; } return $read; }
php
public function read($n) { if ($n <= 0) { return ''; } if (!isset($this->bev)) { return false; } $read = $this->bev->read($n); if ($read === null) { return false; } return $read; }
[ "public", "function", "read", "(", "$", "n", ")", "{", "if", "(", "$", "n", "<=", "0", ")", "{", "return", "''", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "bev", ")", ")", "{", "return", "false", ";", "}", "$", "read", "=",...
Read data from the connection's buffer @param integer $n Max. number of bytes to read @return string|false Readed data
[ "Read", "data", "from", "the", "connection", "s", "buffer" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L938-L951
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.readUnlimited
public function readUnlimited() { if (!isset($this->bev)) { return false; } $read = $this->bev->read($this->bev->input->length); if ($read === null) { return false; } return $read; }
php
public function readUnlimited() { if (!isset($this->bev)) { return false; } $read = $this->bev->read($this->bev->input->length); if ($read === null) { return false; } return $read; }
[ "public", "function", "readUnlimited", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "bev", ")", ")", "{", "return", "false", ";", "}", "$", "read", "=", "$", "this", "->", "bev", "->", "read", "(", "$", "this", "->", "bev", "...
Reads all data from the connection's buffer @return string Readed data
[ "Reads", "all", "data", "from", "the", "connection", "s", "buffer" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L957-L967
kakserpom/phpdaemon
PHPDaemon/Request/Generic.php
Generic.eventCall
public function eventCall($arg) { try { if ($this->state === Generic::STATE_FINISHED) { $this->finish(); $this->free(); return; } $this->state = Generic::STATE_RUNNING; $this->onWakeup(); $throw = false; try { $ret = $this->run(); if (($ret === Generic::STATE_FINISHED) || ($ret === null)) { $this->finish(); } elseif ($ret === Generic::STATE_WAITING) { $this->state = $ret; } } catch (RequestSleep $e) { $this->state = Generic::STATE_WAITING; } catch (RequestTerminated $e) { $this->state = Generic::STATE_FINISHED; } catch (\Exception $e) { if (!$this->handleException($e)) { $throw = true; } } if ($this->state === Generic::STATE_FINISHED) { $this->finish(); } $this->onSleep(); if ($throw) { throw $e; } } catch (\Exception $e) { Daemon::uncaughtExceptionHandler($e); $this->finish(); return; } if ($this->state === Generic::STATE_WAITING) { $this->ev->add($this->sleepTime); } }
php
public function eventCall($arg) { try { if ($this->state === Generic::STATE_FINISHED) { $this->finish(); $this->free(); return; } $this->state = Generic::STATE_RUNNING; $this->onWakeup(); $throw = false; try { $ret = $this->run(); if (($ret === Generic::STATE_FINISHED) || ($ret === null)) { $this->finish(); } elseif ($ret === Generic::STATE_WAITING) { $this->state = $ret; } } catch (RequestSleep $e) { $this->state = Generic::STATE_WAITING; } catch (RequestTerminated $e) { $this->state = Generic::STATE_FINISHED; } catch (\Exception $e) { if (!$this->handleException($e)) { $throw = true; } } if ($this->state === Generic::STATE_FINISHED) { $this->finish(); } $this->onSleep(); if ($throw) { throw $e; } } catch (\Exception $e) { Daemon::uncaughtExceptionHandler($e); $this->finish(); return; } if ($this->state === Generic::STATE_WAITING) { $this->ev->add($this->sleepTime); } }
[ "public", "function", "eventCall", "(", "$", "arg", ")", "{", "try", "{", "if", "(", "$", "this", "->", "state", "===", "Generic", "::", "STATE_FINISHED", ")", "{", "$", "this", "->", "finish", "(", ")", ";", "$", "this", "->", "free", "(", ")", ...
Event handler of Request, called by Evtimer @param $arg @return void
[ "Event", "handler", "of", "Request", "called", "by", "Evtimer" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Request/Generic.php#L203-L245
kakserpom/phpdaemon
PHPDaemon/Request/Generic.php
Generic.free
public function free() { if ($this->ev) { $this->ev->free(); $this->ev = null; } if (isset($this->upstream)) { $this->upstream->freeRequest($this); $this->upstream = null; } }
php
public function free() { if ($this->ev) { $this->ev->free(); $this->ev = null; } if (isset($this->upstream)) { $this->upstream->freeRequest($this); $this->upstream = null; } }
[ "public", "function", "free", "(", ")", "{", "if", "(", "$", "this", "->", "ev", ")", "{", "$", "this", "->", "ev", "->", "free", "(", ")", ";", "$", "this", "->", "ev", "=", "null", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "up...
Frees the request @return void
[ "Frees", "the", "request" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Request/Generic.php#L251-L261
kakserpom/phpdaemon
PHPDaemon/Request/Generic.php
Generic.setPriority
public function setPriority($p) { $this->priority = $p; if ($this->ev !== null) { $this->ev->priority = $p; } }
php
public function setPriority($p) { $this->priority = $p; if ($this->ev !== null) { $this->ev->priority = $p; } }
[ "public", "function", "setPriority", "(", "$", "p", ")", "{", "$", "this", "->", "priority", "=", "$", "p", ";", "if", "(", "$", "this", "->", "ev", "!==", "null", ")", "{", "$", "this", "->", "ev", "->", "priority", "=", "$", "p", ";", "}", ...
Sets the priority @param integer Priority @return void
[ "Sets", "the", "priority" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Request/Generic.php#L268-L274
kakserpom/phpdaemon
PHPDaemon/Request/Generic.php
Generic.preinit
protected function preinit($req) { if ($req === null) { $req = new \stdClass; $req->attrs = new \stdClass; } $this->attrs = $req->attrs; }
php
protected function preinit($req) { if ($req === null) { $req = new \stdClass; $req->attrs = new \stdClass; } $this->attrs = $req->attrs; }
[ "protected", "function", "preinit", "(", "$", "req", ")", "{", "if", "(", "$", "req", "===", "null", ")", "{", "$", "req", "=", "new", "\\", "stdClass", ";", "$", "req", "->", "attrs", "=", "new", "\\", "stdClass", ";", "}", "$", "this", "->", ...
Preparing before init @param object Source request @return void
[ "Preparing", "before", "init" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Request/Generic.php#L281-L289
kakserpom/phpdaemon
PHPDaemon/Request/Generic.php
Generic.getString
public static function getString(&$var, $values = null) { if (!is_string($var)) { $var = ''; } if ($values !== null) { return in_array($var, $values, true) ? $var : $values[0]; } return $var; }
php
public static function getString(&$var, $values = null) { if (!is_string($var)) { $var = ''; } if ($values !== null) { return in_array($var, $values, true) ? $var : $values[0]; } return $var; }
[ "public", "static", "function", "getString", "(", "&", "$", "var", ",", "$", "values", "=", "null", ")", "{", "if", "(", "!", "is_string", "(", "$", "var", ")", ")", "{", "$", "var", "=", "''", ";", "}", "if", "(", "$", "values", "!==", "null",...
Get string value from the given variable @param Reference of variable. @param array Optional. Possible values. @return string Value.
[ "Get", "string", "value", "from", "the", "given", "variable" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Request/Generic.php#L314-L324
kakserpom/phpdaemon
PHPDaemon/Request/Generic.php
Generic.getInteger
public static function getInteger(&$var, $values = null) { if (is_string($var) && ctype_digit($var)) { $var = (int)$var; } if (!is_int($var)) { return 0; } if ($values !== null) { return in_array($var, $values, true) ? $var : $values[0]; } return $var; }
php
public static function getInteger(&$var, $values = null) { if (is_string($var) && ctype_digit($var)) { $var = (int)$var; } if (!is_int($var)) { return 0; } if ($values !== null) { return in_array($var, $values, true) ? $var : $values[0]; } return $var; }
[ "public", "static", "function", "getInteger", "(", "&", "$", "var", ",", "$", "values", "=", "null", ")", "{", "if", "(", "is_string", "(", "$", "var", ")", "&&", "ctype_digit", "(", "$", "var", ")", ")", "{", "$", "var", "=", "(", "int", ")", ...
Get integer value from the given variable @param Reference of variable. @param array Optional. Possible values. @return string Value.
[ "Get", "integer", "value", "from", "the", "given", "variable" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Request/Generic.php#L360-L373
kakserpom/phpdaemon
PHPDaemon/Request/Generic.php
Generic.unregisterShutdownFunction
public function unregisterShutdownFunction($callback) { if (($k = array_search($callback, $this->shutdownFuncs)) !== false) { unset($this->shutdownFuncs[$k]); } }
php
public function unregisterShutdownFunction($callback) { if (($k = array_search($callback, $this->shutdownFuncs)) !== false) { unset($this->shutdownFuncs[$k]); } }
[ "public", "function", "unregisterShutdownFunction", "(", "$", "callback", ")", "{", "if", "(", "(", "$", "k", "=", "array_search", "(", "$", "callback", ",", "$", "this", "->", "shutdownFuncs", ")", ")", "!==", "false", ")", "{", "unset", "(", "$", "th...
Remove the given callback @param callable $callback @return void
[ "Remove", "the", "given", "callback" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Request/Generic.php#L398-L403
kakserpom/phpdaemon
PHPDaemon/Request/Generic.php
Generic.codepoint
public function codepoint($p) { if ($this->codepoint !== $p) { $this->codepoint = $p; return true; } return false; }
php
public function codepoint($p) { if ($this->codepoint !== $p) { $this->codepoint = $p; return true; } return false; }
[ "public", "function", "codepoint", "(", "$", "p", ")", "{", "if", "(", "$", "this", "->", "codepoint", "!==", "$", "p", ")", "{", "$", "this", "->", "codepoint", "=", "$", "p", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Helper for easy switching between several interruptable stages of request's execution @param string Name @return boolean Execute
[ "Helper", "for", "easy", "switching", "between", "several", "interruptable", "stages", "of", "request", "s", "execution" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Request/Generic.php#L410-L418
kakserpom/phpdaemon
PHPDaemon/Request/Generic.php
Generic.sleep
public function sleep($time = 0, $set = false) { if ($this->state === Generic::STATE_FINISHED) { return; } if ($this->state !== Generic::STATE_RUNNING) { $set = true; } $this->sleepTime = $time; if (!$set) { throw new RequestSleep; } else { $this->ev->del(); $this->ev->add($this->sleepTime); } $this->state = Generic::STATE_WAITING; }
php
public function sleep($time = 0, $set = false) { if ($this->state === Generic::STATE_FINISHED) { return; } if ($this->state !== Generic::STATE_RUNNING) { $set = true; } $this->sleepTime = $time; if (!$set) { throw new RequestSleep; } else { $this->ev->del(); $this->ev->add($this->sleepTime); } $this->state = Generic::STATE_WAITING; }
[ "public", "function", "sleep", "(", "$", "time", "=", "0", ",", "$", "set", "=", "false", ")", "{", "if", "(", "$", "this", "->", "state", "===", "Generic", "::", "STATE_FINISHED", ")", "{", "return", ";", "}", "if", "(", "$", "this", "->", "stat...
Delays the request execution for the given number of seconds @param integer $time Time to sleep in seconds @param boolean $set Set this parameter to true when use call it outside of Request->run() or if you don't want to interrupt execution now @throws RequestSleep @return void
[ "Delays", "the", "request", "execution", "for", "the", "given", "number", "of", "seconds" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Request/Generic.php#L428-L447
kakserpom/phpdaemon
PHPDaemon/Request/Generic.php
Generic.wakeup
public function wakeup() { if ($this->state === Generic::STATE_WAITING) { $this->ev->del(); $this->ev->add(0); } }
php
public function wakeup() { if ($this->state === Generic::STATE_WAITING) { $this->ev->del(); $this->ev->add(0); } }
[ "public", "function", "wakeup", "(", ")", "{", "if", "(", "$", "this", "->", "state", "===", "Generic", "::", "STATE_WAITING", ")", "{", "$", "this", "->", "ev", "->", "del", "(", ")", ";", "$", "this", "->", "ev", "->", "add", "(", "0", ")", "...
Cancel current sleep @return void
[ "Cancel", "current", "sleep" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Request/Generic.php#L468-L474
kakserpom/phpdaemon
PHPDaemon/Request/Generic.php
Generic.onWakeup
public function onWakeup() { $this->running = true; Daemon::$req = $this; Daemon::$context = $this; Daemon::$process->setState(Daemon::WSTATE_BUSY); }
php
public function onWakeup() { $this->running = true; Daemon::$req = $this; Daemon::$context = $this; Daemon::$process->setState(Daemon::WSTATE_BUSY); }
[ "public", "function", "onWakeup", "(", ")", "{", "$", "this", "->", "running", "=", "true", ";", "Daemon", "::", "$", "req", "=", "$", "this", ";", "Daemon", "::", "$", "context", "=", "$", "this", ";", "Daemon", "::", "$", "process", "->", "setSta...
Called when the request wakes up @return void
[ "Called", "when", "the", "request", "wakes", "up" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Request/Generic.php#L505-L511
kakserpom/phpdaemon
PHPDaemon/Request/Generic.php
Generic.onSleep
public function onSleep() { Daemon::$req = null; Daemon::$context = null; $this->running = false; Daemon::$process->setState(Daemon::WSTATE_IDLE); }
php
public function onSleep() { Daemon::$req = null; Daemon::$context = null; $this->running = false; Daemon::$process->setState(Daemon::WSTATE_IDLE); }
[ "public", "function", "onSleep", "(", ")", "{", "Daemon", "::", "$", "req", "=", "null", ";", "Daemon", "::", "$", "context", "=", "null", ";", "$", "this", "->", "running", "=", "false", ";", "Daemon", "::", "$", "process", "->", "setState", "(", ...
Called when the request starts sleep @return void
[ "Called", "when", "the", "request", "starts", "sleep" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Request/Generic.php#L517-L523
kakserpom/phpdaemon
PHPDaemon/Request/Generic.php
Generic.abort
public function abort() { if ($this->aborted) { return; } $this->aborted = true; $this->onWakeup(); $this->onAbort(); if ((ignore_user_abort() === 1) && (($this->state === Generic::STATE_RUNNING) || ($this->state === Generic::STATE_WAITING)) && !Daemon::$compatMode ) { $this->upstream->endRequest($this); } else { $this->finish(-1); } $this->onSleep(); }
php
public function abort() { if ($this->aborted) { return; } $this->aborted = true; $this->onWakeup(); $this->onAbort(); if ((ignore_user_abort() === 1) && (($this->state === Generic::STATE_RUNNING) || ($this->state === Generic::STATE_WAITING)) && !Daemon::$compatMode ) { $this->upstream->endRequest($this); } else { $this->finish(-1); } $this->onSleep(); }
[ "public", "function", "abort", "(", ")", "{", "if", "(", "$", "this", "->", "aborted", ")", "{", "return", ";", "}", "$", "this", "->", "aborted", "=", "true", ";", "$", "this", "->", "onWakeup", "(", ")", ";", "$", "this", "->", "onAbort", "(", ...
Aborts the request @return void
[ "Aborts", "the", "request" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Request/Generic.php#L529-L549
kakserpom/phpdaemon
PHPDaemon/Request/Generic.php
Generic.finish
public function finish($status = 0, $zombie = false) { if ($this->state === Generic::STATE_FINISHED) { return; } if (!$zombie) { $this->state = Generic::STATE_FINISHED; } if (!($r = $this->running)) { $this->onWakeup(); } while (($cb = array_shift($this->shutdownFuncs)) !== null) { try { $cb($this); } catch (\Exception $e) { Daemon::uncaughtExceptionHandler($e); // @TODO: break? } } if (!$r) { $this->onSleep(); } $this->event('finish'); $this->onFinish(); $this->cleanupEventHandlers(); if (Daemon::$compatMode) { return; } ++Daemon::$process->counterGC; if (Daemon::$compatMode) { return; } if (!Daemon::$obInStack) { // preventing recursion ob_flush(); } if ($status !== -1) { $appStatus = 0; $this->postFinishHandler(function () use ($appStatus, $status) { $this->upstream->endRequest($this, $appStatus, $status); $this->free(); }); } else { $this->free(); } }
php
public function finish($status = 0, $zombie = false) { if ($this->state === Generic::STATE_FINISHED) { return; } if (!$zombie) { $this->state = Generic::STATE_FINISHED; } if (!($r = $this->running)) { $this->onWakeup(); } while (($cb = array_shift($this->shutdownFuncs)) !== null) { try { $cb($this); } catch (\Exception $e) { Daemon::uncaughtExceptionHandler($e); // @TODO: break? } } if (!$r) { $this->onSleep(); } $this->event('finish'); $this->onFinish(); $this->cleanupEventHandlers(); if (Daemon::$compatMode) { return; } ++Daemon::$process->counterGC; if (Daemon::$compatMode) { return; } if (!Daemon::$obInStack) { // preventing recursion ob_flush(); } if ($status !== -1) { $appStatus = 0; $this->postFinishHandler(function () use ($appStatus, $status) { $this->upstream->endRequest($this, $appStatus, $status); $this->free(); }); } else { $this->free(); } }
[ "public", "function", "finish", "(", "$", "status", "=", "0", ",", "$", "zombie", "=", "false", ")", "{", "if", "(", "$", "this", "->", "state", "===", "Generic", "::", "STATE_FINISHED", ")", "{", "return", ";", "}", "if", "(", "!", "$", "zombie", ...
Finish the request @param integer Optional. Status. 0 - normal, -1 - abort, -2 - termination @param boolean Optional. Zombie. Default is false @return void
[ "Finish", "the", "request" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Request/Generic.php#L557-L611
kakserpom/phpdaemon
PHPDaemon/SockJS/Methods/XhrSend.php
XhrSend.run
public function run() { if ($this->stage++ > 0) { $this->header('500 Too Busy'); return; } if ($this->attrs->raw === '') { $this->header('500 Internal Server Error'); echo 'Payload expected.'; return; } if (!json_decode($this->attrs->raw, true)) { $this->header('500 Internal Server Error'); echo 'Broken JSON encoding.'; return; } $this->appInstance->publish('c2s:' . $this->sessId, $this->attrs->raw, function ($redis) { if (!$this->headers_sent) { if ($redis->result === 0) { $this->header('404 Not Found'); } else { $this->header('204 No Content'); } } $this->finish(); }); $this->sleep(10); }
php
public function run() { if ($this->stage++ > 0) { $this->header('500 Too Busy'); return; } if ($this->attrs->raw === '') { $this->header('500 Internal Server Error'); echo 'Payload expected.'; return; } if (!json_decode($this->attrs->raw, true)) { $this->header('500 Internal Server Error'); echo 'Broken JSON encoding.'; return; } $this->appInstance->publish('c2s:' . $this->sessId, $this->attrs->raw, function ($redis) { if (!$this->headers_sent) { if ($redis->result === 0) { $this->header('404 Not Found'); } else { $this->header('204 No Content'); } } $this->finish(); }); $this->sleep(10); }
[ "public", "function", "run", "(", ")", "{", "if", "(", "$", "this", "->", "stage", "++", ">", "0", ")", "{", "$", "this", "->", "header", "(", "'500 Too Busy'", ")", ";", "return", ";", "}", "if", "(", "$", "this", "->", "attrs", "->", "raw", "...
Called when request iterated @return void
[ "Called", "when", "request", "iterated" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Methods/XhrSend.php#L18-L45
kakserpom/phpdaemon
PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Basic/BasicReturnFrame.php
BasicReturnFrame.create
public static function create( $replyCode = null, $replyText = null, $exchange = null, $routingKey = null ) { $frame = new self(); if (null !== $replyCode) { $frame->replyCode = $replyCode; } if (null !== $replyText) { $frame->replyText = $replyText; } if (null !== $exchange) { $frame->exchange = $exchange; } if (null !== $routingKey) { $frame->routingKey = $routingKey; } return $frame; }
php
public static function create( $replyCode = null, $replyText = null, $exchange = null, $routingKey = null ) { $frame = new self(); if (null !== $replyCode) { $frame->replyCode = $replyCode; } if (null !== $replyText) { $frame->replyText = $replyText; } if (null !== $exchange) { $frame->exchange = $exchange; } if (null !== $routingKey) { $frame->routingKey = $routingKey; } return $frame; }
[ "public", "static", "function", "create", "(", "$", "replyCode", "=", "null", ",", "$", "replyText", "=", "null", ",", "$", "exchange", "=", "null", ",", "$", "routingKey", "=", "null", ")", "{", "$", "frame", "=", "new", "self", "(", ")", ";", "if...
shortstr
[ "shortstr" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Basic/BasicReturnFrame.php#L23-L43
kakserpom/phpdaemon
PHPDaemon/Examples/ExampleAsteriskClient.php
ExampleAsteriskClient.init
public function init() { if ($this->isEnabled()) { $this->asteriskclient = Pool::getInstance($this->config->asteriskclientname->value); } }
php
public function init() { if ($this->isEnabled()) { $this->asteriskclient = Pool::getInstance($this->config->asteriskclientname->value); } }
[ "public", "function", "init", "(", ")", "{", "if", "(", "$", "this", "->", "isEnabled", "(", ")", ")", "{", "$", "this", "->", "asteriskclient", "=", "Pool", "::", "getInstance", "(", "$", "this", "->", "config", "->", "asteriskclientname", "->", "valu...
Constructor. @return void
[ "Constructor", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Examples/ExampleAsteriskClient.php#L24-L29
kakserpom/phpdaemon
PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Queue/QueueDeleteFrame.php
QueueDeleteFrame.create
public static function create( $queue = null, $ifUnused = null, $ifEmpty = null, $nowait = null ) { $frame = new self(); if (null !== $queue) { $frame->queue = $queue; } if (null !== $ifUnused) { $frame->ifUnused = $ifUnused; } if (null !== $ifEmpty) { $frame->ifEmpty = $ifEmpty; } if (null !== $nowait) { $frame->nowait = $nowait; } return $frame; }
php
public static function create( $queue = null, $ifUnused = null, $ifEmpty = null, $nowait = null ) { $frame = new self(); if (null !== $queue) { $frame->queue = $queue; } if (null !== $ifUnused) { $frame->ifUnused = $ifUnused; } if (null !== $ifEmpty) { $frame->ifEmpty = $ifEmpty; } if (null !== $nowait) { $frame->nowait = $nowait; } return $frame; }
[ "public", "static", "function", "create", "(", "$", "queue", "=", "null", ",", "$", "ifUnused", "=", "null", ",", "$", "ifEmpty", "=", "null", ",", "$", "nowait", "=", "null", ")", "{", "$", "frame", "=", "new", "self", "(", ")", ";", "if", "(", ...
bit
[ "bit" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Queue/QueueDeleteFrame.php#L24-L44
kakserpom/phpdaemon
PHPDaemon/SockJS/Methods/Htmlfile.php
Htmlfile.sendFrame
public function sendFrame($frame) { $this->outputFrame("<script>\np(" . htmlspecialchars(json_encode($frame, JSON_UNESCAPED_SLASHES), ENT_NOQUOTES | ENT_HTML401) . ");\n</script>\r\n"); parent::sendFrame($frame); }
php
public function sendFrame($frame) { $this->outputFrame("<script>\np(" . htmlspecialchars(json_encode($frame, JSON_UNESCAPED_SLASHES), ENT_NOQUOTES | ENT_HTML401) . ");\n</script>\r\n"); parent::sendFrame($frame); }
[ "public", "function", "sendFrame", "(", "$", "frame", ")", "{", "$", "this", "->", "outputFrame", "(", "\"<script>\\np(\"", ".", "htmlspecialchars", "(", "json_encode", "(", "$", "frame", ",", "JSON_UNESCAPED_SLASHES", ")", ",", "ENT_NOQUOTES", "|", "ENT_HTML401...
Send frame @param string $frame @return void
[ "Send", "frame" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Methods/Htmlfile.php#L22-L27
kakserpom/phpdaemon
PHPDaemon/Clients/Redis/Examples/Multi.php
Multi.onReady
public function onReady() { $this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance(); $this->redis->multi(function ($multi) { // "OK" D('start multi: ' . $multi->result); $multi->set('test1', 'value1', function ($redis) use ($multi) { // "QUEUED" D('in multi 1: ' . $redis->result); $this->redis->set('test1', 'value1-new', function ($redis) { // "OK", not "QUEUED" D('out multi 1: ' . $redis->result); }); setTimeout(function ($timer) use ($multi) { // "QUEUED" $multi->set('test2', 'value2', function ($redis) use ($multi) { D('in multi 2: ' . $redis->result); $multi->exec(function ($redis) { D('exec'); D($redis->result); }); }); $timer->free(); }, 2e5); }); }); }
php
public function onReady() { $this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance(); $this->redis->multi(function ($multi) { // "OK" D('start multi: ' . $multi->result); $multi->set('test1', 'value1', function ($redis) use ($multi) { // "QUEUED" D('in multi 1: ' . $redis->result); $this->redis->set('test1', 'value1-new', function ($redis) { // "OK", not "QUEUED" D('out multi 1: ' . $redis->result); }); setTimeout(function ($timer) use ($multi) { // "QUEUED" $multi->set('test2', 'value2', function ($redis) use ($multi) { D('in multi 2: ' . $redis->result); $multi->exec(function ($redis) { D('exec'); D($redis->result); }); }); $timer->free(); }, 2e5); }); }); }
[ "public", "function", "onReady", "(", ")", "{", "$", "this", "->", "redis", "=", "\\", "PHPDaemon", "\\", "Clients", "\\", "Redis", "\\", "Pool", "::", "getInstance", "(", ")", ";", "$", "this", "->", "redis", "->", "multi", "(", "function", "(", "$"...
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/Clients/Redis/Examples/Multi.php#L24-L55
kakserpom/phpdaemon
PHPDaemon/Config/Entry/ArraySet.php
ArraySet.humanToPlain
public static function humanToPlain($value) { if (is_array($value)) { return $value; } $value = preg_replace_callback('~(".*?")|(\'.*?\')|(\s*,\s*)~s', function ($m) { if (!empty($m[3])) { return "\x00"; } if (!empty($m[2])) { return substr($m[2], 1, -1); } if (!empty($m[1])) { return substr($m[1], 1, -1); } return null; }, $value); return explode("\x00", $value); }
php
public static function humanToPlain($value) { if (is_array($value)) { return $value; } $value = preg_replace_callback('~(".*?")|(\'.*?\')|(\s*,\s*)~s', function ($m) { if (!empty($m[3])) { return "\x00"; } if (!empty($m[2])) { return substr($m[2], 1, -1); } if (!empty($m[1])) { return substr($m[1], 1, -1); } return null; }, $value); return explode("\x00", $value); }
[ "public", "static", "function", "humanToPlain", "(", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "return", "$", "value", ";", "}", "$", "value", "=", "preg_replace_callback", "(", "'~(\".*?\")|(\\'.*?\\')|(\\s*,\\s*)~s'", ...
Converts human-readable value to plain @param array|string $value @return array
[ "Converts", "human", "-", "readable", "value", "to", "plain" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Config/Entry/ArraySet.php#L20-L38
kakserpom/phpdaemon
PHPDaemon/XMLStream/XMLStreamObject.php
XMLStreamObject.printObj
public function printObj($depth = 0) { $s = str_repeat("\t", $depth) . $this->name . " " . $this->ns . ' ' . $this->data . "\n"; foreach ($this->subs as $sub) { $s .= $sub->printObj($depth + 1); } return $s; }
php
public function printObj($depth = 0) { $s = str_repeat("\t", $depth) . $this->name . " " . $this->ns . ' ' . $this->data . "\n"; foreach ($this->subs as $sub) { $s .= $sub->printObj($depth + 1); } return $s; }
[ "public", "function", "printObj", "(", "$", "depth", "=", "0", ")", "{", "$", "s", "=", "str_repeat", "(", "\"\\t\"", ",", "$", "depth", ")", ".", "$", "this", "->", "name", ".", "\" \"", ".", "$", "this", "->", "ns", ".", "' '", ".", "$", "thi...
Dump this XML Object to output. @param integer $depth
[ "Dump", "this", "XML", "Object", "to", "output", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/XMLStream/XMLStreamObject.php#L69-L76
kakserpom/phpdaemon
PHPDaemon/XMLStream/XMLStreamObject.php
XMLStreamObject.toString
public function toString($str = '') { $str .= "<{$this->name} xmlns='{$this->ns}' "; foreach ($this->attrs as $key => $value) { if ($key !== 'xmlns') { $value = htmlspecialchars($value); $str .= "$key='$value' "; } } $str .= ">"; foreach ($this->subs as $sub) { $str .= $sub->toString(); } $body = htmlspecialchars($this->data); $str .= "$body</{$this->name}>"; return $str; }
php
public function toString($str = '') { $str .= "<{$this->name} xmlns='{$this->ns}' "; foreach ($this->attrs as $key => $value) { if ($key !== 'xmlns') { $value = htmlspecialchars($value); $str .= "$key='$value' "; } } $str .= ">"; foreach ($this->subs as $sub) { $str .= $sub->toString(); } $body = htmlspecialchars($this->data); $str .= "$body</{$this->name}>"; return $str; }
[ "public", "function", "toString", "(", "$", "str", "=", "''", ")", "{", "$", "str", ".=", "\"<{$this->name} xmlns='{$this->ns}' \"", ";", "foreach", "(", "$", "this", "->", "attrs", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "key",...
Return this XML Object in xml notation @param string $str
[ "Return", "this", "XML", "Object", "in", "xml", "notation" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/XMLStream/XMLStreamObject.php#L83-L99
kakserpom/phpdaemon
PHPDaemon/XMLStream/XMLStreamObject.php
XMLStreamObject.hasSub
public function hasSub($name, $ns = null) { foreach ($this->subs as $sub) { if (($name === "*" or $sub->name === $name) and ($ns === null or $sub->ns === $ns)) { return true; } } return false; }
php
public function hasSub($name, $ns = null) { foreach ($this->subs as $sub) { if (($name === "*" or $sub->name === $name) and ($ns === null or $sub->ns === $ns)) { return true; } } return false; }
[ "public", "function", "hasSub", "(", "$", "name", ",", "$", "ns", "=", "null", ")", "{", "foreach", "(", "$", "this", "->", "subs", "as", "$", "sub", ")", "{", "if", "(", "(", "$", "name", "===", "\"*\"", "or", "$", "sub", "->", "name", "===", ...
Has this XML Object the given sub? @param string $name @return boolean
[ "Has", "this", "XML", "Object", "the", "given", "sub?" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/XMLStream/XMLStreamObject.php#L107-L115
kakserpom/phpdaemon
PHPDaemon/XMLStream/XMLStreamObject.php
XMLStreamObject.sub
public function sub($name, $attrs = null, $ns = null) { //@TODO: attrs is ignored foreach ($this->subs as $sub) { if ($sub->name === $name and ($ns === null or $sub->ns === $ns)) { return $sub; } } return null; }
php
public function sub($name, $attrs = null, $ns = null) { //@TODO: attrs is ignored foreach ($this->subs as $sub) { if ($sub->name === $name and ($ns === null or $sub->ns === $ns)) { return $sub; } } return null; }
[ "public", "function", "sub", "(", "$", "name", ",", "$", "attrs", "=", "null", ",", "$", "ns", "=", "null", ")", "{", "//@TODO: attrs is ignored", "foreach", "(", "$", "this", "->", "subs", "as", "$", "sub", ")", "{", "if", "(", "$", "sub", "->", ...
Return a sub @param string $name @param string $attrs @param string $ns
[ "Return", "a", "sub" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/XMLStream/XMLStreamObject.php#L124-L133
kakserpom/phpdaemon
PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Channel/ChannelOpenFrame.php
ChannelOpenFrame.create
public static function create( $outOfBand = null ) { $frame = new self(); if (null !== $outOfBand) { $frame->outOfBand = $outOfBand; } return $frame; }
php
public static function create( $outOfBand = null ) { $frame = new self(); if (null !== $outOfBand) { $frame->outOfBand = $outOfBand; } return $frame; }
[ "public", "static", "function", "create", "(", "$", "outOfBand", "=", "null", ")", "{", "$", "frame", "=", "new", "self", "(", ")", ";", "if", "(", "null", "!==", "$", "outOfBand", ")", "{", "$", "frame", "->", "outOfBand", "=", "$", "outOfBand", "...
shortstr
[ "shortstr" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Channel/ChannelOpenFrame.php#L20-L31
kakserpom/phpdaemon
PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Basic/BasicGetEmptyFrame.php
BasicGetEmptyFrame.create
public static function create( $clusterId = null ) { $frame = new self(); if (null !== $clusterId) { $frame->clusterId = $clusterId; } return $frame; }
php
public static function create( $clusterId = null ) { $frame = new self(); if (null !== $clusterId) { $frame->clusterId = $clusterId; } return $frame; }
[ "public", "static", "function", "create", "(", "$", "clusterId", "=", "null", ")", "{", "$", "frame", "=", "new", "self", "(", ")", ";", "if", "(", "null", "!==", "$", "clusterId", ")", "{", "$", "frame", "->", "clusterId", "=", "$", "clusterId", "...
shortstr
[ "shortstr" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Basic/BasicGetEmptyFrame.php#L20-L31
kakserpom/phpdaemon
PHPDaemon/Core/Debug.php
Debug.exportBytes
public static function exportBytes($str, $all = false) { return preg_replace_callback( '~' . ($all ? '.' : '[^A-Za-z\d\.\{\}$<>:;\-_/\\\\=+]') . '~s', function ($m) use ($all) { if (!$all) { if ($m[0] === "\r") { return "\n" . '\r'; } if ($m[0] === "\n") { return '\n'; } } return sprintf('\x%02x', ord($m[0])); }, $str ); }
php
public static function exportBytes($str, $all = false) { return preg_replace_callback( '~' . ($all ? '.' : '[^A-Za-z\d\.\{\}$<>:;\-_/\\\\=+]') . '~s', function ($m) use ($all) { if (!$all) { if ($m[0] === "\r") { return "\n" . '\r'; } if ($m[0] === "\n") { return '\n'; } } return sprintf('\x%02x', ord($m[0])); }, $str ); }
[ "public", "static", "function", "exportBytes", "(", "$", "str", ",", "$", "all", "=", "false", ")", "{", "return", "preg_replace_callback", "(", "'~'", ".", "(", "$", "all", "?", "'.'", ":", "'[^A-Za-z\\d\\.\\{\\}$<>:;\\-_/\\\\\\\\=+]'", ")", ".", "'~s'", ",...
Export binary data @param string $str String @param boolean $all Whether to replace all of chars with escaped sequences @return string Escaped string
[ "Export", "binary", "data" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/Debug.php#L20-L39
kakserpom/phpdaemon
PHPDaemon/Core/Debug.php
Debug.proxy
public static function proxy($cb, $name = null) { static $i = 0; $n = ++$i; Daemon::log('Debug::proxy #' . $n . ': SPAWNED (' . json_encode($name) . ')'); return function (...$args) use ($cb, $name, $n) { Daemon::log('Debug::proxy #' . $n . ': CALLED (' . json_encode($name) . ')'); $cb(...$args); }; }
php
public static function proxy($cb, $name = null) { static $i = 0; $n = ++$i; Daemon::log('Debug::proxy #' . $n . ': SPAWNED (' . json_encode($name) . ')'); return function (...$args) use ($cb, $name, $n) { Daemon::log('Debug::proxy #' . $n . ': CALLED (' . json_encode($name) . ')'); $cb(...$args); }; }
[ "public", "static", "function", "proxy", "(", "$", "cb", ",", "$", "name", "=", "null", ")", "{", "static", "$", "i", "=", "0", ";", "$", "n", "=", "++", "$", "i", ";", "Daemon", "::", "log", "(", "'Debug::proxy #'", ".", "$", "n", ".", "': SPA...
Returns a proxy callback function with logging for debugging purposes @param callable $cb Callback @param mixed $name Data @return callable
[ "Returns", "a", "proxy", "callback", "function", "with", "logging", "for", "debugging", "purposes" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/Debug.php#L67-L76
kakserpom/phpdaemon
PHPDaemon/Core/Debug.php
Debug.dump
public static function dump(...$args) { ob_start(); foreach ($args as $v) { var_dump($v); } $dump = ob_get_contents(); ob_end_clean(); return $dump; }
php
public static function dump(...$args) { ob_start(); foreach ($args as $v) { var_dump($v); } $dump = ob_get_contents(); ob_end_clean(); return $dump; }
[ "public", "static", "function", "dump", "(", "...", "$", "args", ")", "{", "ob_start", "(", ")", ";", "foreach", "(", "$", "args", "as", "$", "v", ")", "{", "var_dump", "(", "$", "v", ")", ";", "}", "$", "dump", "=", "ob_get_contents", "(", ")", ...
Wrapper of var_dump @return string Result of var_dump()
[ "Wrapper", "of", "var_dump" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/Debug.php#L82-L94
kakserpom/phpdaemon
PHPDaemon/Core/Debug.php
Debug.zdump
public static function zdump(...$args) { ob_start(); foreach ($args as $v) { debug_zval_dump($v); } $dump = ob_get_contents(); ob_end_clean(); return $dump; }
php
public static function zdump(...$args) { ob_start(); foreach ($args as $v) { debug_zval_dump($v); } $dump = ob_get_contents(); ob_end_clean(); return $dump; }
[ "public", "static", "function", "zdump", "(", "...", "$", "args", ")", "{", "ob_start", "(", ")", ";", "foreach", "(", "$", "args", "as", "$", "v", ")", "{", "debug_zval_dump", "(", "$", "v", ")", ";", "}", "$", "dump", "=", "ob_get_contents", "(",...
Wrapper of debug_zval_dump @return string Result of debug_zval_dump()
[ "Wrapper", "of", "debug_zval_dump" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/Debug.php#L114-L126
kakserpom/phpdaemon
PHPDaemon/Core/Debug.php
Debug.backtrace
public static function backtrace($bool = false) { if (Daemon::$obInStack || $bool) { try { throw new \Exception; } catch (\Exception $e) { $trace = $e->getTraceAsString(); $e = explode("\n", $trace); array_shift($e); array_shift($e); return implode("\n", $e); } } ob_start(); debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $trace = ob_get_contents(); ob_end_clean(); $e = explode("\n", $trace); array_shift($e); return implode("\n", $e); }
php
public static function backtrace($bool = false) { if (Daemon::$obInStack || $bool) { try { throw new \Exception; } catch (\Exception $e) { $trace = $e->getTraceAsString(); $e = explode("\n", $trace); array_shift($e); array_shift($e); return implode("\n", $e); } } ob_start(); debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $trace = ob_get_contents(); ob_end_clean(); $e = explode("\n", $trace); array_shift($e); return implode("\n", $e); }
[ "public", "static", "function", "backtrace", "(", "$", "bool", "=", "false", ")", "{", "if", "(", "Daemon", "::", "$", "obInStack", "||", "$", "bool", ")", "{", "try", "{", "throw", "new", "\\", "Exception", ";", "}", "catch", "(", "\\", "Exception",...
Returns textual backtrace @return string
[ "Returns", "textual", "backtrace" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/Debug.php#L132-L153
kakserpom/phpdaemon
PHPDaemon/Clients/Valve/Connection.php
Connection.requestPlayers
public function requestPlayers($cb) { $this->request('challenge', null, function ($conn, $result) use ($cb) { if (is_array($result)) { $cb($conn, $result); return; } $conn->request('players', $result, $cb); }); }
php
public function requestPlayers($cb) { $this->request('challenge', null, function ($conn, $result) use ($cb) { if (is_array($result)) { $cb($conn, $result); return; } $conn->request('players', $result, $cb); }); }
[ "public", "function", "requestPlayers", "(", "$", "cb", ")", "{", "$", "this", "->", "request", "(", "'challenge'", ",", "null", ",", "function", "(", "$", "conn", ",", "$", "result", ")", "use", "(", "$", "cb", ")", "{", "if", "(", "is_array", "("...
Sends a request of type 'players' @param callable $cb Callback @callback $cb ( ) @return void
[ "Sends", "a", "request", "of", "type", "players" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Valve/Connection.php#L26-L35
kakserpom/phpdaemon
PHPDaemon/Clients/Valve/Connection.php
Connection.request
public function request($type, $data = null, $cb = null) { $packet = "\xFF\xFF\xFF\xFF"; if ($type === 'ping') { $packet .= Pool::A2A_PING; } elseif ($type === 'challenge') { //$packet .= ValveClient::A2S_SERVERQUERY_GETCHALLENGE; $packet .= Pool::A2S_PLAYER . "\xFF\xFF\xFF\xFF"; } elseif ($type === 'info') { $packet .= Pool::A2S_INFO . "Source Engine Query\x00"; //"\xFF\xFF\xFF\xFFdetails\x00" } elseif ($type === 'players') { if ($data === null) { $data = "\xFF\xFF\xFF\xFF"; } $packet .= Pool::A2S_PLAYER . $data; } else { return null; } $this->onResponse->push($cb); $this->setFree(false); //Daemon::log('packet: '.Debug::exportBytes($packet, true)); $this->write($packet); }
php
public function request($type, $data = null, $cb = null) { $packet = "\xFF\xFF\xFF\xFF"; if ($type === 'ping') { $packet .= Pool::A2A_PING; } elseif ($type === 'challenge') { //$packet .= ValveClient::A2S_SERVERQUERY_GETCHALLENGE; $packet .= Pool::A2S_PLAYER . "\xFF\xFF\xFF\xFF"; } elseif ($type === 'info') { $packet .= Pool::A2S_INFO . "Source Engine Query\x00"; //"\xFF\xFF\xFF\xFFdetails\x00" } elseif ($type === 'players') { if ($data === null) { $data = "\xFF\xFF\xFF\xFF"; } $packet .= Pool::A2S_PLAYER . $data; } else { return null; } $this->onResponse->push($cb); $this->setFree(false); //Daemon::log('packet: '.Debug::exportBytes($packet, true)); $this->write($packet); }
[ "public", "function", "request", "(", "$", "type", ",", "$", "data", "=", "null", ",", "$", "cb", "=", "null", ")", "{", "$", "packet", "=", "\"\\xFF\\xFF\\xFF\\xFF\"", ";", "if", "(", "$", "type", "===", "'ping'", ")", "{", "$", "packet", ".=", "P...
Sends a request @param string $type Type of request @param string $data Data @param callable $cb Callback @callback $cb ( ) @return void
[ "Sends", "a", "request" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Valve/Connection.php#L56-L79
kakserpom/phpdaemon
PHPDaemon/Clients/Valve/Connection.php
Connection.onRead
protected function onRead() { start: if ($this->getInputLength() < 5) { return; } /* @TODO: refactoring Binary::* to support direct buffer calls */ $pct = $this->read(4096); $h = Binary::getDWord($pct); if ($h !== 0xFFFFFFFF) { $this->finish(); return; } $type = Binary::getChar($pct); if (($type === Pool::S2A_INFO) || ($type === Pool::S2A_INFO_SOURCE)) { $result = self::parseInfo($pct, $type); } elseif ($type === Pool::S2A_PLAYER) { $result = self::parsePlayers($pct); } elseif ($type === Pool::S2A_SERVERQUERY_GETCHALLENGE) { $result = mb_orig_substr($pct, 0, 4); $pct = mb_orig_substr($pct, 5); } elseif ($type === Pool::S2A_PONG) { $result = true; } else { $result = null; } $this->onResponse->executeOne($this, $result); $this->checkFree(); goto start; }
php
protected function onRead() { start: if ($this->getInputLength() < 5) { return; } /* @TODO: refactoring Binary::* to support direct buffer calls */ $pct = $this->read(4096); $h = Binary::getDWord($pct); if ($h !== 0xFFFFFFFF) { $this->finish(); return; } $type = Binary::getChar($pct); if (($type === Pool::S2A_INFO) || ($type === Pool::S2A_INFO_SOURCE)) { $result = self::parseInfo($pct, $type); } elseif ($type === Pool::S2A_PLAYER) { $result = self::parsePlayers($pct); } elseif ($type === Pool::S2A_SERVERQUERY_GETCHALLENGE) { $result = mb_orig_substr($pct, 0, 4); $pct = mb_orig_substr($pct, 5); } elseif ($type === Pool::S2A_PONG) { $result = true; } else { $result = null; } $this->onResponse->executeOne($this, $result); $this->checkFree(); goto start; }
[ "protected", "function", "onRead", "(", ")", "{", "start", ":", "if", "(", "$", "this", "->", "getInputLength", "(", ")", "<", "5", ")", "{", "return", ";", "}", "/* @TODO: refactoring Binary::* to support direct buffer calls */", "$", "pct", "=", "$", "this",...
Called when new data received @return void
[ "Called", "when", "new", "data", "received" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Valve/Connection.php#L85-L114
kakserpom/phpdaemon
PHPDaemon/Clients/Valve/Connection.php
Connection.parsePlayers
public static function parsePlayers(&$st) { $playersn = Binary::getByte($st); $players = []; for ($i = 1; $i < $playersn; ++$i) { $n = Binary::getByte($st); $name = Binary::getString($st); $score = Binary::getDWord($st, true); if (mb_orig_strlen($st) === 0) { break; } $u = unpack('f', mb_orig_substr($st, 0, 4)); $st = mb_orig_substr($st, 4); $seconds = $u[1]; if ($seconds === -1) { continue; } $players[] = [ 'name' => Encoding::toUTF8($name), 'score' => $score, 'seconds' => $seconds, 'joinedts' => microtime(true) - $seconds, 'spm' => $score / ($seconds / 60), ]; } return $players; }
php
public static function parsePlayers(&$st) { $playersn = Binary::getByte($st); $players = []; for ($i = 1; $i < $playersn; ++$i) { $n = Binary::getByte($st); $name = Binary::getString($st); $score = Binary::getDWord($st, true); if (mb_orig_strlen($st) === 0) { break; } $u = unpack('f', mb_orig_substr($st, 0, 4)); $st = mb_orig_substr($st, 4); $seconds = $u[1]; if ($seconds === -1) { continue; } $players[] = [ 'name' => Encoding::toUTF8($name), 'score' => $score, 'seconds' => $seconds, 'joinedts' => microtime(true) - $seconds, 'spm' => $score / ($seconds / 60), ]; } return $players; }
[ "public", "static", "function", "parsePlayers", "(", "&", "$", "st", ")", "{", "$", "playersn", "=", "Binary", "::", "getByte", "(", "$", "st", ")", ";", "$", "players", "=", "[", "]", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<", ...
Parses response to 'players' command into structure @param string &$st Data @return array Structure
[ "Parses", "response", "to", "players", "command", "into", "structure" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Valve/Connection.php#L121-L147
kakserpom/phpdaemon
PHPDaemon/Clients/Valve/Connection.php
Connection.parseInfo
public static function parseInfo(&$st, $type) { $info = []; if ($type === Pool::S2A_INFO) { $info['proto'] = Binary::getByte($st); $info['hostname'] = Binary::getString($st); $info['map'] = Binary::getString($st); $info['gamedir'] = Binary::getString($st); $info['gamedescr'] = Binary::getString($st); $info['steamid'] = Binary::getWord($st); $info['playersnum'] = Binary::getByte($st); $info['playersmax'] = Binary::getByte($st); $info['botcount'] = Binary::getByte($st); $info['servertype'] = Binary::getChar($st); $info['serveros'] = Binary::getChar($st); $info['passworded'] = Binary::getByte($st); $info['secure'] = Binary::getByte($st); } elseif ($type === Pool::S2A_INFO_SOURCE) { $info['srvaddress'] = Binary::getString($st); $info['hostname'] = Binary::getString($st); $info['map'] = Binary::getString($st); $info['gamedir'] = Binary::getString($st); $info['gamedescr'] = Binary::getString($st); $info['playersnum'] = Binary::getByte($st); $info['playersmax'] = Binary::getByte($st); $info['proto'] = Binary::getByte($st); $info['servertype'] = Binary::getChar($st); $info['serveros'] = Binary::getChar($st); $info['passworded'] = Binary::getByte($st); $info['modded'] = Binary::getByte($st); if ($info['modded']) { $info['mod_website'] = Binary::getString($st); $info['mod_downloadserver'] = Binary::getString($st); $info['mod_unused'] = Binary::getString($st); $info['mod_version'] = Binary::getDWord($st, true); $info['mod_size'] = Binary::getDWord($st); $info['mod_serverside'] = Binary::getByte($st); $info['mod_customdll'] = Binary::getByte($st); } $info['secure'] = Binary::getByte($st); $info['botsnum'] = Binary::getByte($st); } foreach ($info as &$val) { if (is_string($val)) { $val = Encoding::toUTF8($val); } } return $info; }
php
public static function parseInfo(&$st, $type) { $info = []; if ($type === Pool::S2A_INFO) { $info['proto'] = Binary::getByte($st); $info['hostname'] = Binary::getString($st); $info['map'] = Binary::getString($st); $info['gamedir'] = Binary::getString($st); $info['gamedescr'] = Binary::getString($st); $info['steamid'] = Binary::getWord($st); $info['playersnum'] = Binary::getByte($st); $info['playersmax'] = Binary::getByte($st); $info['botcount'] = Binary::getByte($st); $info['servertype'] = Binary::getChar($st); $info['serveros'] = Binary::getChar($st); $info['passworded'] = Binary::getByte($st); $info['secure'] = Binary::getByte($st); } elseif ($type === Pool::S2A_INFO_SOURCE) { $info['srvaddress'] = Binary::getString($st); $info['hostname'] = Binary::getString($st); $info['map'] = Binary::getString($st); $info['gamedir'] = Binary::getString($st); $info['gamedescr'] = Binary::getString($st); $info['playersnum'] = Binary::getByte($st); $info['playersmax'] = Binary::getByte($st); $info['proto'] = Binary::getByte($st); $info['servertype'] = Binary::getChar($st); $info['serveros'] = Binary::getChar($st); $info['passworded'] = Binary::getByte($st); $info['modded'] = Binary::getByte($st); if ($info['modded']) { $info['mod_website'] = Binary::getString($st); $info['mod_downloadserver'] = Binary::getString($st); $info['mod_unused'] = Binary::getString($st); $info['mod_version'] = Binary::getDWord($st, true); $info['mod_size'] = Binary::getDWord($st); $info['mod_serverside'] = Binary::getByte($st); $info['mod_customdll'] = Binary::getByte($st); } $info['secure'] = Binary::getByte($st); $info['botsnum'] = Binary::getByte($st); } foreach ($info as &$val) { if (is_string($val)) { $val = Encoding::toUTF8($val); } } return $info; }
[ "public", "static", "function", "parseInfo", "(", "&", "$", "st", ",", "$", "type", ")", "{", "$", "info", "=", "[", "]", ";", "if", "(", "$", "type", "===", "Pool", "::", "S2A_INFO", ")", "{", "$", "info", "[", "'proto'", "]", "=", "Binary", "...
Parses response to 'info' command into structure @param string &$st Data @param string $type Type of request @return array Structure
[ "Parses", "response", "to", "info", "command", "into", "structure" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Valve/Connection.php#L155-L203
kakserpom/phpdaemon
PHPDaemon/Servers/Socks/SlaveConnection.php
SlaveConnection.onRead
public function onRead() { if (!$this->client) { return; } do { $this->client->writeFromBuffer($this->bev->input, $this->bev->input->length); } while ($this->bev->input->length > 0); }
php
public function onRead() { if (!$this->client) { return; } do { $this->client->writeFromBuffer($this->bev->input, $this->bev->input->length); } while ($this->bev->input->length > 0); }
[ "public", "function", "onRead", "(", ")", "{", "if", "(", "!", "$", "this", "->", "client", ")", "{", "return", ";", "}", "do", "{", "$", "this", "->", "client", "->", "writeFromBuffer", "(", "$", "this", "->", "bev", "->", "input", ",", "$", "th...
Called when new data received. @return void
[ "Called", "when", "new", "data", "received", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/Socks/SlaveConnection.php#L25-L33
kakserpom/phpdaemon
PHPDaemon/Clients/HTTP/Examples/SimpleRequest.php
SimpleRequest.init
public function init() { try { $this->header('Content-Type: text/html'); } catch (\Exception $e) { } $this->appInstance->httpclient->get( 'http://www.google.com/robots.txt', function ($conn, $success) { echo $conn->body; $this->finish(); } ); // setting timeout $this->sleep(5, true); }
php
public function init() { try { $this->header('Content-Type: text/html'); } catch (\Exception $e) { } $this->appInstance->httpclient->get( 'http://www.google.com/robots.txt', function ($conn, $success) { echo $conn->body; $this->finish(); } ); // setting timeout $this->sleep(5, true); }
[ "public", "function", "init", "(", ")", "{", "try", "{", "$", "this", "->", "header", "(", "'Content-Type: text/html'", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "}", "$", "this", "->", "appInstance", "->", "httpclient", "->",...
Constructor @return void
[ "Constructor" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/HTTP/Examples/SimpleRequest.php#L12-L29
kakserpom/phpdaemon
PHPDaemon/Network/Client.php
Client.applyConfig
protected function applyConfig() { parent::applyConfig(); if (isset($this->config->servers)) { $servers = array_filter(array_map('trim', explode(',', $this->config->servers->value)), 'mb_orig_strlen'); $this->servers = []; foreach ($servers as $s) { $this->addServer($s); } } if (isset($this->config->maxconnperserv)) { $this->maxConnPerServ = $this->config->maxconnperserv->value; } }
php
protected function applyConfig() { parent::applyConfig(); if (isset($this->config->servers)) { $servers = array_filter(array_map('trim', explode(',', $this->config->servers->value)), 'mb_orig_strlen'); $this->servers = []; foreach ($servers as $s) { $this->addServer($s); } } if (isset($this->config->maxconnperserv)) { $this->maxConnPerServ = $this->config->maxconnperserv->value; } }
[ "protected", "function", "applyConfig", "(", ")", "{", "parent", "::", "applyConfig", "(", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "config", "->", "servers", ")", ")", "{", "$", "servers", "=", "array_filter", "(", "array_map", "(", "'tri...
Applies config @return void
[ "Applies", "config" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Client.php#L74-L87
kakserpom/phpdaemon
PHPDaemon/Network/Client.php
Client.getConnection
public function getConnection($url = null, $cb = null, $pri = 0) { if (!is_string($url) && $url !== null && $cb === null) { // if called getConnection(function....) $cb = $url; $url = null; } if ($url === null) { if (isset($this->config->server->value)) { $url = $this->config->server->value; } elseif (isset($this->servers) && sizeof($this->servers)) { $url = array_rand($this->servers); } else { if ($cb) { $cb(false); } return false; } } start: $conn = false; if (isset($this->servConn[$url])) { $storage = $this->servConn[$url]; $free = $this->servConnFree[$url]; if ($free->count() > 0) { $conn = $free->getFirst(); if (!$conn->isConnected() || $conn->isFinished()) { $free->detach($conn); goto start; } if ($this->acquireOnGet) { $free->detach($conn); } } elseif ($storage->count() >= $this->maxConnPerServ) { if (!isset($this->pending[$url])) { $this->pending[$url] = new PriorityQueueCallbacks; } $this->pending[$url]->enqueue($cb, $pri); return true; } if ($conn) { if ($cb !== null) { $conn->onConnected($cb); } return true; } } else { $this->servConn[$url] = new ObjectStorage; $this->servConnFree[$url] = new ObjectStorage; } //Daemon::log($url . "\n" . Debug::dump($this->finished) . "\n" . Debug::backtrace(true)); $conn = $this->connect($url, $cb); if (!$conn || $conn->isFinished()) { return false; } $this->servConn[$url]->attach($conn); return true; }
php
public function getConnection($url = null, $cb = null, $pri = 0) { if (!is_string($url) && $url !== null && $cb === null) { // if called getConnection(function....) $cb = $url; $url = null; } if ($url === null) { if (isset($this->config->server->value)) { $url = $this->config->server->value; } elseif (isset($this->servers) && sizeof($this->servers)) { $url = array_rand($this->servers); } else { if ($cb) { $cb(false); } return false; } } start: $conn = false; if (isset($this->servConn[$url])) { $storage = $this->servConn[$url]; $free = $this->servConnFree[$url]; if ($free->count() > 0) { $conn = $free->getFirst(); if (!$conn->isConnected() || $conn->isFinished()) { $free->detach($conn); goto start; } if ($this->acquireOnGet) { $free->detach($conn); } } elseif ($storage->count() >= $this->maxConnPerServ) { if (!isset($this->pending[$url])) { $this->pending[$url] = new PriorityQueueCallbacks; } $this->pending[$url]->enqueue($cb, $pri); return true; } if ($conn) { if ($cb !== null) { $conn->onConnected($cb); } return true; } } else { $this->servConn[$url] = new ObjectStorage; $this->servConnFree[$url] = new ObjectStorage; } //Daemon::log($url . "\n" . Debug::dump($this->finished) . "\n" . Debug::backtrace(true)); $conn = $this->connect($url, $cb); if (!$conn || $conn->isFinished()) { return false; } $this->servConn[$url]->attach($conn); return true; }
[ "public", "function", "getConnection", "(", "$", "url", "=", "null", ",", "$", "cb", "=", "null", ",", "$", "pri", "=", "0", ")", "{", "if", "(", "!", "is_string", "(", "$", "url", ")", "&&", "$", "url", "!==", "null", "&&", "$", "cb", "===", ...
Returns available connection from the pool @param string $url Address @param callback $cb onConnected @param integer $pri Optional. Priority @call ( callable $cb ) @call ( string $url = null, callable $cb = null, integer $pri = 0 ) @return boolean Success|Connection
[ "Returns", "available", "connection", "from", "the", "pool" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Client.php#L109-L167
kakserpom/phpdaemon
PHPDaemon/Network/Client.php
Client.markConnFree
public function markConnFree(ClientConnection $conn, $url) { if (!isset($this->servConnFree[$url])) { return; } $this->servConnFree[$url]->attach($conn); }
php
public function markConnFree(ClientConnection $conn, $url) { if (!isset($this->servConnFree[$url])) { return; } $this->servConnFree[$url]->attach($conn); }
[ "public", "function", "markConnFree", "(", "ClientConnection", "$", "conn", ",", "$", "url", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "servConnFree", "[", "$", "url", "]", ")", ")", "{", "return", ";", "}", "$", "this", "->", "ser...
Mark connection as free @param ClientConnection $conn Connection @param string $url URL @return void
[ "Mark", "connection", "as", "free" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Client.php#L186-L192
kakserpom/phpdaemon
PHPDaemon/Network/Client.php
Client.markConnBusy
public function markConnBusy(ClientConnection $conn, $url) { if (!isset($this->servConnFree[$url])) { return; } $this->servConnFree[$url]->detach($conn); }
php
public function markConnBusy(ClientConnection $conn, $url) { if (!isset($this->servConnFree[$url])) { return; } $this->servConnFree[$url]->detach($conn); }
[ "public", "function", "markConnBusy", "(", "ClientConnection", "$", "conn", ",", "$", "url", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "servConnFree", "[", "$", "url", "]", ")", ")", "{", "return", ";", "}", "$", "this", "->", "ser...
Mark connection as busy @param ClientConnection $conn Connection @param string $url URL @return void
[ "Mark", "connection", "as", "busy" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Client.php#L200-L206
kakserpom/phpdaemon
PHPDaemon/Network/Client.php
Client.detachConnFromUrl
public function detachConnFromUrl(ClientConnection $conn, $url) { if (isset($this->servConnFree[$url])) { $this->servConnFree[$url]->detach($conn); } if (isset($this->servConn[$url])) { $this->servConn[$url]->detach($conn); } }
php
public function detachConnFromUrl(ClientConnection $conn, $url) { if (isset($this->servConnFree[$url])) { $this->servConnFree[$url]->detach($conn); } if (isset($this->servConn[$url])) { $this->servConn[$url]->detach($conn); } }
[ "public", "function", "detachConnFromUrl", "(", "ClientConnection", "$", "conn", ",", "$", "url", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "servConnFree", "[", "$", "url", "]", ")", ")", "{", "$", "this", "->", "servConnFree", "[", "$", ...
Detaches connection from URL @param ClientConnection $conn Connection @param string $url URL @return void
[ "Detaches", "connection", "from", "URL" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Client.php#L214-L222
kakserpom/phpdaemon
PHPDaemon/Network/Client.php
Client.touchPending
public function touchPending($url) { while (isset($this->pending[$url]) && !$this->pending[$url]->isEmpty()) { if (true === $this->getConnection($url, $this->pending[$url]->dequeue())) { return; } } }
php
public function touchPending($url) { while (isset($this->pending[$url]) && !$this->pending[$url]->isEmpty()) { if (true === $this->getConnection($url, $this->pending[$url]->dequeue())) { return; } } }
[ "public", "function", "touchPending", "(", "$", "url", ")", "{", "while", "(", "isset", "(", "$", "this", "->", "pending", "[", "$", "url", "]", ")", "&&", "!", "$", "this", "->", "pending", "[", "$", "url", "]", "->", "isEmpty", "(", ")", ")", ...
Touch pending "requests for connection" @param string $url URL @return void
[ "Touch", "pending", "requests", "for", "connection" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Client.php#L229-L236
kakserpom/phpdaemon
PHPDaemon/Network/Client.php
Client.getConnectionByKey
public function getConnectionByKey($key, $cb = null) { if (is_object($key)) { return $key->onConnected($cb); } srand(crc32($key)); $addr = array_rand($this->servers); srand(); return $this->getConnection($addr, $cb); }
php
public function getConnectionByKey($key, $cb = null) { if (is_object($key)) { return $key->onConnected($cb); } srand(crc32($key)); $addr = array_rand($this->servers); srand(); return $this->getConnection($addr, $cb); }
[ "public", "function", "getConnectionByKey", "(", "$", "key", ",", "$", "cb", "=", "null", ")", "{", "if", "(", "is_object", "(", "$", "key", ")", ")", "{", "return", "$", "key", "->", "onConnected", "(", "$", "cb", ")", ";", "}", "srand", "(", "c...
Returns available connection from the pool by key @param string $key Key @param callable $cb Callback @callback $cb ( ) @return boolean Success
[ "Returns", "available", "connection", "from", "the", "pool", "by", "key" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Client.php#L245-L254
kakserpom/phpdaemon
PHPDaemon/Network/Client.php
Client.requestByServer
public function requestByServer($server, $data, $onResponse = null) { $this->getConnection($server, function ($conn) use ($data, $onResponse) { if (!$conn->isConnected()) { return; } $conn->onResponse($onResponse); $conn->write($data); }); return true; }
php
public function requestByServer($server, $data, $onResponse = null) { $this->getConnection($server, function ($conn) use ($data, $onResponse) { if (!$conn->isConnected()) { return; } $conn->onResponse($onResponse); $conn->write($data); }); return true; }
[ "public", "function", "requestByServer", "(", "$", "server", ",", "$", "data", ",", "$", "onResponse", "=", "null", ")", "{", "$", "this", "->", "getConnection", "(", "$", "server", ",", "function", "(", "$", "conn", ")", "use", "(", "$", "data", ","...
Sends a request to arbitrary server @param string $server Server @param string $data Data @param callable $onResponse Called when the request complete @callback $onResponse ( ) @return boolean Success
[ "Sends", "a", "request", "to", "arbitrary", "server" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Client.php#L275-L285
kakserpom/phpdaemon
PHPDaemon/Network/Client.php
Client.requestByKey
public function requestByKey($key, $data, $onResponse = null) { $this->getConnectionByKey($key, function ($conn) use ($data, $onResponse) { if (!$conn->isConnected()) { return; } $conn->onResponse($onResponse); $conn->write($data); }); return true; }
php
public function requestByKey($key, $data, $onResponse = null) { $this->getConnectionByKey($key, function ($conn) use ($data, $onResponse) { if (!$conn->isConnected()) { return; } $conn->onResponse($onResponse); $conn->write($data); }); return true; }
[ "public", "function", "requestByKey", "(", "$", "key", ",", "$", "data", ",", "$", "onResponse", "=", "null", ")", "{", "$", "this", "->", "getConnectionByKey", "(", "$", "key", ",", "function", "(", "$", "conn", ")", "use", "(", "$", "data", ",", ...
Sends a request to server according to the key @param string $key Key @param string $data Data @param callable $onResponse Callback called when the request complete @callback $onResponse ( ) @return boolean Success
[ "Sends", "a", "request", "to", "server", "according", "to", "the", "key" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Client.php#L295-L305
kakserpom/phpdaemon
PHPDaemon/Applications/CGIRequest.php
CGIRequest.init
public function init() { $this->header('Content-Type: text/html'); // default header. $this->proc = new \PHPDaemon\Core\ShellCommand(); $this->proc->readPacketSize = $this->appInstance->readPacketSize; $this->proc->onReadData([$this, 'onReadData']); $this->proc->onWrite([$this, 'onWrite']); $this->proc->binPath = $this->appInstance->binPath; $this->proc->chroot = $this->appInstance->chroot; if (isset($this->attrs->server['BINPATH'])) { if (isset($this->appInstance->binAliases[$this->attrs->server['BINPATH']])) { $this->proc->binPath = $this->appInstance->binAliases[$this->attrs->server['BINPATH']]; } elseif ($this->appInstance->config->allowoverridebinpath->value) { $this->proc->binPath = $this->attrs->server['BINPATH']; } } if (isset($this->attrs->server['CHROOT']) && $this->appInstance->config->allowoverridechroot->value) { $this->proc->chroot = $this->attrs->server['CHROOT']; } if (isset($this->attrs->server['SETUSER']) && $this->appInstance->config->allowoverrideuser->value) { $this->proc->setUser = $this->attrs->server['SETUSER']; } if (isset($this->attrs->server['SETGROUP']) && $this->appInstance->config->allowoverridegroup->value) { $this->proc->setGroup = $this->attrs->server['SETGROUP']; } if (isset($this->attrs->server['CWD']) && $this->appInstance->config->allowoverridecwd->value) { $this->proc->cwd = $this->attrs->server['CWD']; } elseif ($this->appInstance->config->cwd->value !== null) { $this->proc->cwd = $this->appInstance->config->cwd->value; } else { $this->proc->cwd = dirname($this->attrs->server['SCRIPT_FILENAME']); } $this->proc->setArgs([$this->attrs->server['SCRIPT_FILENAME']]); $this->proc->setEnv($this->attrs->server); $this->proc->execute(); }
php
public function init() { $this->header('Content-Type: text/html'); // default header. $this->proc = new \PHPDaemon\Core\ShellCommand(); $this->proc->readPacketSize = $this->appInstance->readPacketSize; $this->proc->onReadData([$this, 'onReadData']); $this->proc->onWrite([$this, 'onWrite']); $this->proc->binPath = $this->appInstance->binPath; $this->proc->chroot = $this->appInstance->chroot; if (isset($this->attrs->server['BINPATH'])) { if (isset($this->appInstance->binAliases[$this->attrs->server['BINPATH']])) { $this->proc->binPath = $this->appInstance->binAliases[$this->attrs->server['BINPATH']]; } elseif ($this->appInstance->config->allowoverridebinpath->value) { $this->proc->binPath = $this->attrs->server['BINPATH']; } } if (isset($this->attrs->server['CHROOT']) && $this->appInstance->config->allowoverridechroot->value) { $this->proc->chroot = $this->attrs->server['CHROOT']; } if (isset($this->attrs->server['SETUSER']) && $this->appInstance->config->allowoverrideuser->value) { $this->proc->setUser = $this->attrs->server['SETUSER']; } if (isset($this->attrs->server['SETGROUP']) && $this->appInstance->config->allowoverridegroup->value) { $this->proc->setGroup = $this->attrs->server['SETGROUP']; } if (isset($this->attrs->server['CWD']) && $this->appInstance->config->allowoverridecwd->value) { $this->proc->cwd = $this->attrs->server['CWD']; } elseif ($this->appInstance->config->cwd->value !== null) { $this->proc->cwd = $this->appInstance->config->cwd->value; } else { $this->proc->cwd = dirname($this->attrs->server['SCRIPT_FILENAME']); } $this->proc->setArgs([$this->attrs->server['SCRIPT_FILENAME']]); $this->proc->setEnv($this->attrs->server); $this->proc->execute(); }
[ "public", "function", "init", "(", ")", "{", "$", "this", "->", "header", "(", "'Content-Type: text/html'", ")", ";", "// default header.", "$", "this", "->", "proc", "=", "new", "\\", "PHPDaemon", "\\", "Core", "\\", "ShellCommand", "(", ")", ";", "$", ...
Constructor. @return void
[ "Constructor", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Applications/CGIRequest.php#L28-L70
kakserpom/phpdaemon
PHPDaemon/Applications/CGIRequest.php
CGIRequest.run
public function run() { if (!$this->proc) { $this->out('Couldn\'t execute CGI proccess.'); $this->finish(); return; } if (!$this->proc->eof()) { $this->sleep(); } }
php
public function run() { if (!$this->proc) { $this->out('Couldn\'t execute CGI proccess.'); $this->finish(); return; } if (!$this->proc->eof()) { $this->sleep(); } }
[ "public", "function", "run", "(", ")", "{", "if", "(", "!", "$", "this", "->", "proc", ")", "{", "$", "this", "->", "out", "(", "'Couldn\\'t execute CGI proccess.'", ")", ";", "$", "this", "->", "finish", "(", ")", ";", "return", ";", "}", "if", "(...
Called when request iterated. @return void
[ "Called", "when", "request", "iterated", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Applications/CGIRequest.php#L76-L86
kakserpom/phpdaemon
PHPDaemon/Applications/CGIRequest.php
CGIRequest.stdin
public function stdin($c) { if ($c === '') { $this->onWrite($this->proc); } else { $this->proc->write($c); } }
php
public function stdin($c) { if ($c === '') { $this->onWrite($this->proc); } else { $this->proc->write($c); } }
[ "public", "function", "stdin", "(", "$", "c", ")", "{", "if", "(", "$", "c", "===", "''", ")", "{", "$", "this", "->", "onWrite", "(", "$", "this", "->", "proc", ")", ";", "}", "else", "{", "$", "this", "->", "proc", "->", "write", "(", "$", ...
Called when new piece of request's body is received. @param string $c Piece of request's body. @return void
[ "Called", "when", "new", "piece", "of", "request", "s", "body", "is", "received", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Applications/CGIRequest.php#L115-L122
kakserpom/phpdaemon
PHPDaemon/Applications/CGIRequest.php
CGIRequest.onWrite
public function onWrite($process) { if ($this->attrs->stdin_done && ($this->proc->writeState === false)) { $this->proc->closeWrite(); } }
php
public function onWrite($process) { if ($this->attrs->stdin_done && ($this->proc->writeState === false)) { $this->proc->closeWrite(); } }
[ "public", "function", "onWrite", "(", "$", "process", ")", "{", "if", "(", "$", "this", "->", "attrs", "->", "stdin_done", "&&", "(", "$", "this", "->", "proc", "->", "writeState", "===", "false", ")", ")", "{", "$", "this", "->", "proc", "->", "cl...
Called when the request aborted. @param \PHPDaemon\Core\ShellCommand $process @return void
[ "Called", "when", "the", "request", "aborted", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Applications/CGIRequest.php#L129-L134
kakserpom/phpdaemon
PHPDaemon/BoundSocket/Generic.php
Generic.importParams
protected function importParams() { foreach ($this->uri['params'] as $key => $val) { if (isset($this->{$key}) && is_bool($this->{$key})) { $this->{$key} = (bool)$val; continue; } if (!property_exists($this, $key)) { Daemon::log(get_class($this) . ': unrecognized setting \'' . $key . '\''); continue; } $this->{$key} = $val; } if (property_exists($this, 'port') && !isset($this->port)) { if (isset($this->uri['port'])) { $this->port = $this->uri['port']; } elseif ($this->defaultPort) { $this->port = $this->defaultPort; } } if (property_exists($this, 'host') && !isset($this->host)) { if (isset($this->uri['host'])) { $this->host = $this->uri['host']; } } if (!$this->ctxname) { return; } if (!isset(Daemon::$config->{'TransportContext:' . $this->ctxname})) { Daemon::log(get_class($this) . ': undefined transport context \'' . $this->ctxname . '\''); return; } $ctx = Daemon::$config->{'TransportContext:' . $this->ctxname}; foreach ($ctx as $key => $entry) { $value = ($entry instanceof \PHPDaemon\Config\Entry\Generic) ? $entry->value : $entry; if (isset($this->{$key}) && is_bool($this->{$key})) { $this->{$key} = (bool)$value; continue; } if (!property_exists($this, $key)) { Daemon::log(get_class($this) . ': unrecognized setting in transport context \'' . $this->ctxname . '\': \'' . $key . '\''); continue; } $this->{$key} = $value; } }
php
protected function importParams() { foreach ($this->uri['params'] as $key => $val) { if (isset($this->{$key}) && is_bool($this->{$key})) { $this->{$key} = (bool)$val; continue; } if (!property_exists($this, $key)) { Daemon::log(get_class($this) . ': unrecognized setting \'' . $key . '\''); continue; } $this->{$key} = $val; } if (property_exists($this, 'port') && !isset($this->port)) { if (isset($this->uri['port'])) { $this->port = $this->uri['port']; } elseif ($this->defaultPort) { $this->port = $this->defaultPort; } } if (property_exists($this, 'host') && !isset($this->host)) { if (isset($this->uri['host'])) { $this->host = $this->uri['host']; } } if (!$this->ctxname) { return; } if (!isset(Daemon::$config->{'TransportContext:' . $this->ctxname})) { Daemon::log(get_class($this) . ': undefined transport context \'' . $this->ctxname . '\''); return; } $ctx = Daemon::$config->{'TransportContext:' . $this->ctxname}; foreach ($ctx as $key => $entry) { $value = ($entry instanceof \PHPDaemon\Config\Entry\Generic) ? $entry->value : $entry; if (isset($this->{$key}) && is_bool($this->{$key})) { $this->{$key} = (bool)$value; continue; } if (!property_exists($this, $key)) { Daemon::log(get_class($this) . ': unrecognized setting in transport context \'' . $this->ctxname . '\': \'' . $key . '\''); continue; } $this->{$key} = $value; } }
[ "protected", "function", "importParams", "(", ")", "{", "foreach", "(", "$", "this", "->", "uri", "[", "'params'", "]", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "{", "$", "key", "}", ")", "&&", "...
Import parameters @return void
[ "Import", "parameters" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/BoundSocket/Generic.php#L203-L248
kakserpom/phpdaemon
PHPDaemon/BoundSocket/Generic.php
Generic.initSecureContext
protected function initSecureContext() { if (!\EventUtil::sslRandPoll()) { Daemon::$process->log(get_class($this->pool) . ': EventUtil::sslRandPoll failed'); $this->erroneous = true; return; } if (!FileSystem::checkFileReadable($this->certfile) || !FileSystem::checkFileReadable($this->pkfile)) { Daemon::log('Couldn\'t read ' . $this->certfile . ' or ' . $this->pkfile . ' file. To generate a key' . PHP_EOL . 'and self-signed certificate, run' . PHP_EOL . ' openssl genrsa -out ' . escapeshellarg($this->pkfile) . ' 2048' . PHP_EOL . ' openssl req -new -key ' . escapeshellarg($this->pkfile) . ' -out cert.req' . PHP_EOL . ' openssl x509 -req -days 365 -in cert.req -signkey ' . escapeshellarg($this->pkfile) . ' -out ' . escapeshellarg($this->certfile)); return; } $params = [ \EventSslContext::OPT_LOCAL_CERT => $this->certfile, \EventSslContext::OPT_LOCAL_PK => $this->pkfile, \EventSslContext::OPT_VERIFY_PEER => $this->verifypeer, \EventSslContext::OPT_ALLOW_SELF_SIGNED => $this->allowselfsigned, ]; if ($this->passphrase !== null) { $params[\EventSslContext::OPT_PASSPHRASE] = $this->passphrase; } if ($this->verifydepth !== null) { $params[\EventSslContext::OPT_VERIFY_DEPTH] = $this->verifydepth; } if ($this->cafile !== null) { $params[\EventSslContext::OPT_CA_FILE] = $this->cafile; } if ($this->tls === true) { $method = \EventSslContext::TLS_SERVER_METHOD; } elseif ($this->tls === 'v11') { $method = \EventSslContext::TLSv11_SERVER_METHOD; } elseif ($this->tls === 'v12') { $method = \EventSslContext::TLSv12_SERVER_METHOD; } elseif ($this->ssl === 'v3' || $this->ssl === true || $this->ssl === '1') { $method = \EventSslContext::SSLv3_SERVER_METHOD; } elseif ($this->ssl === 'v2') { $method = \EventSslContext::SSLv2_SERVER_METHOD; } elseif ($this->ssl === 'v23') { $method = \EventSslContext::SSLv23_SERVER_METHOD; } elseif ($this->ssl) { Daemon::log(get_class($this) . ': unrecognized SSL version \'' . $this->ssl . '\''); return; } else { return; } $this->ctx = new \EventSslContext($method, $params); }
php
protected function initSecureContext() { if (!\EventUtil::sslRandPoll()) { Daemon::$process->log(get_class($this->pool) . ': EventUtil::sslRandPoll failed'); $this->erroneous = true; return; } if (!FileSystem::checkFileReadable($this->certfile) || !FileSystem::checkFileReadable($this->pkfile)) { Daemon::log('Couldn\'t read ' . $this->certfile . ' or ' . $this->pkfile . ' file. To generate a key' . PHP_EOL . 'and self-signed certificate, run' . PHP_EOL . ' openssl genrsa -out ' . escapeshellarg($this->pkfile) . ' 2048' . PHP_EOL . ' openssl req -new -key ' . escapeshellarg($this->pkfile) . ' -out cert.req' . PHP_EOL . ' openssl x509 -req -days 365 -in cert.req -signkey ' . escapeshellarg($this->pkfile) . ' -out ' . escapeshellarg($this->certfile)); return; } $params = [ \EventSslContext::OPT_LOCAL_CERT => $this->certfile, \EventSslContext::OPT_LOCAL_PK => $this->pkfile, \EventSslContext::OPT_VERIFY_PEER => $this->verifypeer, \EventSslContext::OPT_ALLOW_SELF_SIGNED => $this->allowselfsigned, ]; if ($this->passphrase !== null) { $params[\EventSslContext::OPT_PASSPHRASE] = $this->passphrase; } if ($this->verifydepth !== null) { $params[\EventSslContext::OPT_VERIFY_DEPTH] = $this->verifydepth; } if ($this->cafile !== null) { $params[\EventSslContext::OPT_CA_FILE] = $this->cafile; } if ($this->tls === true) { $method = \EventSslContext::TLS_SERVER_METHOD; } elseif ($this->tls === 'v11') { $method = \EventSslContext::TLSv11_SERVER_METHOD; } elseif ($this->tls === 'v12') { $method = \EventSslContext::TLSv12_SERVER_METHOD; } elseif ($this->ssl === 'v3' || $this->ssl === true || $this->ssl === '1') { $method = \EventSslContext::SSLv3_SERVER_METHOD; } elseif ($this->ssl === 'v2') { $method = \EventSslContext::SSLv2_SERVER_METHOD; } elseif ($this->ssl === 'v23') { $method = \EventSslContext::SSLv23_SERVER_METHOD; } elseif ($this->ssl) { Daemon::log(get_class($this) . ': unrecognized SSL version \'' . $this->ssl . '\''); return; } else { return; } $this->ctx = new \EventSslContext($method, $params); }
[ "protected", "function", "initSecureContext", "(", ")", "{", "if", "(", "!", "\\", "EventUtil", "::", "sslRandPoll", "(", ")", ")", "{", "Daemon", "::", "$", "process", "->", "log", "(", "get_class", "(", "$", "this", "->", "pool", ")", ".", "': EventU...
Initialize SSL/TLS context @return void
[ "Initialize", "SSL", "/", "TLS", "context" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/BoundSocket/Generic.php#L254-L304
kakserpom/phpdaemon
PHPDaemon/BoundSocket/Generic.php
Generic.attachTo
public function attachTo(\PHPDaemon\Network\Pool $pool) { $this->pool = $pool; $this->pool->attachBound($this); }
php
public function attachTo(\PHPDaemon\Network\Pool $pool) { $this->pool = $pool; $this->pool->attachBound($this); }
[ "public", "function", "attachTo", "(", "\\", "PHPDaemon", "\\", "Network", "\\", "Pool", "$", "pool", ")", "{", "$", "this", "->", "pool", "=", "$", "pool", ";", "$", "this", "->", "pool", "->", "attachBound", "(", "$", "this", ")", ";", "}" ]
Attach to ConnectionPool @param ConnectionPool @return void
[ "Attach", "to", "ConnectionPool" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/BoundSocket/Generic.php#L311-L315
kakserpom/phpdaemon
PHPDaemon/BoundSocket/Generic.php
Generic.enable
public function enable() { if ($this->enabled) { return; } if (!$this->fd) { return; } $this->enabled = true; if ($this->ev === null) { if ($this->eventLoop === null) { $this->eventLoop = EventLoop::$instance; } $this->ev = $this->eventLoop->listener( [$this, 'onAcceptEv'], null, \EventListener::OPT_CLOSE_ON_FREE | \EventListener::OPT_REUSEABLE, -1, $this->fd ); $this->onBound(); } else { $this->ev->enable(); } }
php
public function enable() { if ($this->enabled) { return; } if (!$this->fd) { return; } $this->enabled = true; if ($this->ev === null) { if ($this->eventLoop === null) { $this->eventLoop = EventLoop::$instance; } $this->ev = $this->eventLoop->listener( [$this, 'onAcceptEv'], null, \EventListener::OPT_CLOSE_ON_FREE | \EventListener::OPT_REUSEABLE, -1, $this->fd ); $this->onBound(); } else { $this->ev->enable(); } }
[ "public", "function", "enable", "(", ")", "{", "if", "(", "$", "this", "->", "enabled", ")", "{", "return", ";", "}", "if", "(", "!", "$", "this", "->", "fd", ")", "{", "return", ";", "}", "$", "this", "->", "enabled", "=", "true", ";", "if", ...
Enable socket events @return void
[ "Enable", "socket", "events" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/BoundSocket/Generic.php#L341-L365
kakserpom/phpdaemon
PHPDaemon/BoundSocket/Generic.php
Generic.disable
public function disable() { if (!$this->enabled) { return; } $this->enabled = false; if ($this->ev instanceof \Event) { $this->ev->del(); } elseif ($this->ev instanceof \EventListener) { $this->ev->disable(); } }
php
public function disable() { if (!$this->enabled) { return; } $this->enabled = false; if ($this->ev instanceof \Event) { $this->ev->del(); } elseif ($this->ev instanceof \EventListener) { $this->ev->disable(); } }
[ "public", "function", "disable", "(", ")", "{", "if", "(", "!", "$", "this", "->", "enabled", ")", "{", "return", ";", "}", "$", "this", "->", "enabled", "=", "false", ";", "if", "(", "$", "this", "->", "ev", "instanceof", "\\", "Event", ")", "{"...
Disable all events of sockets @return void
[ "Disable", "all", "events", "of", "sockets" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/BoundSocket/Generic.php#L398-L409
kakserpom/phpdaemon
PHPDaemon/BoundSocket/Generic.php
Generic.close
public function close() { if (isset($this->ev)) { $this->ev = null; } if ($this->pid !== posix_getpid()) { // preventing closing pre-bound sockets in workers return; } if (is_resource($this->fd)) { socket_close($this->fd); } }
php
public function close() { if (isset($this->ev)) { $this->ev = null; } if ($this->pid !== posix_getpid()) { // preventing closing pre-bound sockets in workers return; } if (is_resource($this->fd)) { socket_close($this->fd); } }
[ "public", "function", "close", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "ev", ")", ")", "{", "$", "this", "->", "ev", "=", "null", ";", "}", "if", "(", "$", "this", "->", "pid", "!==", "posix_getpid", "(", ")", ")", "{", "//...
Close each of binded sockets. @return void
[ "Close", "each", "of", "binded", "sockets", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/BoundSocket/Generic.php#L415-L426
kakserpom/phpdaemon
PHPDaemon/BoundSocket/Generic.php
Generic.netMatch
public static function netMatch($CIDR, $IP) { /* TODO: IPV6 */ if (is_array($CIDR)) { foreach ($CIDR as &$v) { if (self::netMatch($v, $IP)) { return true; } } return false; } $e = explode('/', $CIDR, 2); if (!isset($e[1])) { return $e[0] === $IP; } return (ip2long($IP) & ~((1 << (32 - $e[1])) - 1)) === ip2long($e[0]); }
php
public static function netMatch($CIDR, $IP) { /* TODO: IPV6 */ if (is_array($CIDR)) { foreach ($CIDR as &$v) { if (self::netMatch($v, $IP)) { return true; } } return false; } $e = explode('/', $CIDR, 2); if (!isset($e[1])) { return $e[0] === $IP; } return (ip2long($IP) & ~((1 << (32 - $e[1])) - 1)) === ip2long($e[0]); }
[ "public", "static", "function", "netMatch", "(", "$", "CIDR", ",", "$", "IP", ")", "{", "/* TODO: IPV6 */", "if", "(", "is_array", "(", "$", "CIDR", ")", ")", "{", "foreach", "(", "$", "CIDR", "as", "&", "$", "v", ")", "{", "if", "(", "self", "::...
Checks if the CIDR-mask matches the IP @param string CIDR-mask @param string IP @return boolean Result
[ "Checks", "if", "the", "CIDR", "-", "mask", "matches", "the", "IP" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/BoundSocket/Generic.php#L460-L480
kakserpom/phpdaemon
PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Basic/BasicDeliverFrame.php
BasicDeliverFrame.create
public static function create( $consumerTag = null, $deliveryTag = null, $redelivered = null, $exchange = null, $routingKey = null ) { $frame = new self(); if (null !== $consumerTag) { $frame->consumerTag = $consumerTag; } if (null !== $deliveryTag) { $frame->deliveryTag = $deliveryTag; } if (null !== $redelivered) { $frame->redelivered = $redelivered; } if (null !== $exchange) { $frame->exchange = $exchange; } if (null !== $routingKey) { $frame->routingKey = $routingKey; } return $frame; }
php
public static function create( $consumerTag = null, $deliveryTag = null, $redelivered = null, $exchange = null, $routingKey = null ) { $frame = new self(); if (null !== $consumerTag) { $frame->consumerTag = $consumerTag; } if (null !== $deliveryTag) { $frame->deliveryTag = $deliveryTag; } if (null !== $redelivered) { $frame->redelivered = $redelivered; } if (null !== $exchange) { $frame->exchange = $exchange; } if (null !== $routingKey) { $frame->routingKey = $routingKey; } return $frame; }
[ "public", "static", "function", "create", "(", "$", "consumerTag", "=", "null", ",", "$", "deliveryTag", "=", "null", ",", "$", "redelivered", "=", "null", ",", "$", "exchange", "=", "null", ",", "$", "routingKey", "=", "null", ")", "{", "$", "frame", ...
shortstr
[ "shortstr" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Basic/BasicDeliverFrame.php#L25-L48
kakserpom/phpdaemon
PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Queue/QueuePurgeFrame.php
QueuePurgeFrame.create
public static function create( $queue = null, $nowait = null ) { $frame = new self(); if (null !== $queue) { $frame->queue = $queue; } if (null !== $nowait) { $frame->nowait = $nowait; } return $frame; }
php
public static function create( $queue = null, $nowait = null ) { $frame = new self(); if (null !== $queue) { $frame->queue = $queue; } if (null !== $nowait) { $frame->nowait = $nowait; } return $frame; }
[ "public", "static", "function", "create", "(", "$", "queue", "=", "null", ",", "$", "nowait", "=", "null", ")", "{", "$", "frame", "=", "new", "self", "(", ")", ";", "if", "(", "null", "!==", "$", "queue", ")", "{", "$", "frame", "->", "queue", ...
bit
[ "bit" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Queue/QueuePurgeFrame.php#L22-L36
kakserpom/phpdaemon
PHPDaemon/Clients/Redis/Examples/Simple.php
Simple.onReady
public function onReady() { $this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance(); /*$this->redis->eval("return {'a','b','c', {'d','e','f', {'g','h','i'}} }",0, function($redis) { Daemon::log(Debug::dump($redis->result)); });*/ $this->redis->subscribe('te3st', function ($redis) { Daemon::log(Debug::dump($redis->result)); }); $this->redis->psubscribe('test*', function ($redis) { Daemon::log(Debug::dump($redis->result)); }); }
php
public function onReady() { $this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance(); /*$this->redis->eval("return {'a','b','c', {'d','e','f', {'g','h','i'}} }",0, function($redis) { Daemon::log(Debug::dump($redis->result)); });*/ $this->redis->subscribe('te3st', function ($redis) { Daemon::log(Debug::dump($redis->result)); }); $this->redis->psubscribe('test*', function ($redis) { Daemon::log(Debug::dump($redis->result)); }); }
[ "public", "function", "onReady", "(", ")", "{", "$", "this", "->", "redis", "=", "\\", "PHPDaemon", "\\", "Clients", "\\", "Redis", "\\", "Pool", "::", "getInstance", "(", ")", ";", "/*$this->redis->eval(\"return {'a','b','c', {'d','e','f', {'g','h','i'}} }\",0, funct...
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/Clients/Redis/Examples/Simple.php#L24-L39
kakserpom/phpdaemon
PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Connection/ConnectionSecureOkFrame.php
ConnectionSecureOkFrame.create
public static function create( $response = null ) { $frame = new self(); if (null !== $response) { $frame->response = $response; } return $frame; }
php
public static function create( $response = null ) { $frame = new self(); if (null !== $response) { $frame->response = $response; } return $frame; }
[ "public", "static", "function", "create", "(", "$", "response", "=", "null", ")", "{", "$", "frame", "=", "new", "self", "(", ")", ";", "if", "(", "null", "!==", "$", "response", ")", "{", "$", "frame", "->", "response", "=", "$", "response", ";", ...
longstr
[ "longstr" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Connection/ConnectionSecureOkFrame.php#L20-L31
kakserpom/phpdaemon
PHPDaemon/Config/Parser.php
Parser.parse
public static function parse($file, $target, $included = false) { if (in_array($file, static::$stack)) { throw new InfiniteRecursion; } static::$stack[] = $file; $parser = new static($file, $target, $included); array_pop(static::$stack); return $parser; }
php
public static function parse($file, $target, $included = false) { if (in_array($file, static::$stack)) { throw new InfiniteRecursion; } static::$stack[] = $file; $parser = new static($file, $target, $included); array_pop(static::$stack); return $parser; }
[ "public", "static", "function", "parse", "(", "$", "file", ",", "$", "target", ",", "$", "included", "=", "false", ")", "{", "if", "(", "in_array", "(", "$", "file", ",", "static", "::", "$", "stack", ")", ")", "{", "throw", "new", "InfiniteRecursion...
Parse config file @param string File path @param _Object Target @param boolean Included? Default is false @return \PHPDaemon\Config\Parser
[ "Parse", "config", "file" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Config/Parser.php#L142-L152
kakserpom/phpdaemon
PHPDaemon/Config/Parser.php
Parser.purgeScope
protected function purgeScope($scope) { foreach ($scope as $name => $obj) { if ($obj instanceof Generic) { if ($obj->source === 'config' && ($obj->revision < $this->revision)) { if (!$obj->resetToDefault()) { unset($scope->{$name}); } } } elseif ($obj instanceof Section) { if ($obj->source === 'config' && ($obj->revision < $this->revision)) { if ($obj->count() === 0) { unset($scope->{$name}); } elseif (isset($obj->enable)) { $obj->enable->setValue(false); } } } } }
php
protected function purgeScope($scope) { foreach ($scope as $name => $obj) { if ($obj instanceof Generic) { if ($obj->source === 'config' && ($obj->revision < $this->revision)) { if (!$obj->resetToDefault()) { unset($scope->{$name}); } } } elseif ($obj instanceof Section) { if ($obj->source === 'config' && ($obj->revision < $this->revision)) { if ($obj->count() === 0) { unset($scope->{$name}); } elseif (isset($obj->enable)) { $obj->enable->setValue(false); } } } } }
[ "protected", "function", "purgeScope", "(", "$", "scope", ")", "{", "foreach", "(", "$", "scope", "as", "$", "name", "=>", "$", "obj", ")", "{", "if", "(", "$", "obj", "instanceof", "Generic", ")", "{", "if", "(", "$", "obj", "->", "source", "===",...
Removes old config parts after updating. @return void
[ "Removes", "old", "config", "parts", "after", "updating", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Config/Parser.php#L457-L476
kakserpom/phpdaemon
PHPDaemon/Config/Parser.php
Parser.raiseError
public function raiseError($msg, $level = 'emerg', $line = null, $col = null) { if ($level === 'emerg') { $this->erroneous = true; } if ($line === null) { $line = $this->line; } if ($col === null) { $col = $this->col - 1; } Daemon::log('[conf#' . $level . '][' . $this->file . ' L:' . $line . ' C: ' . $col . '] ' . $msg); }
php
public function raiseError($msg, $level = 'emerg', $line = null, $col = null) { if ($level === 'emerg') { $this->erroneous = true; } if ($line === null) { $line = $this->line; } if ($col === null) { $col = $this->col - 1; } Daemon::log('[conf#' . $level . '][' . $this->file . ' L:' . $line . ' C: ' . $col . '] ' . $msg); }
[ "public", "function", "raiseError", "(", "$", "msg", ",", "$", "level", "=", "'emerg'", ",", "$", "line", "=", "null", ",", "$", "col", "=", "null", ")", "{", "if", "(", "$", "level", "===", "'emerg'", ")", "{", "$", "this", "->", "erroneous", "=...
Raises error message. @param string Message. @param string Level. @param string $msg @return void
[ "Raises", "error", "message", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Config/Parser.php#L496-L509
kakserpom/phpdaemon
PHPDaemon/Config/Parser.php
Parser.getCurrentChar
protected function getCurrentChar() { $c = substr($this->data, $this->p, 1); if ($c === "\n") { ++$this->line; $this->col = 1; } else { ++$this->col; } return $c; }
php
protected function getCurrentChar() { $c = substr($this->data, $this->p, 1); if ($c === "\n") { ++$this->line; $this->col = 1; } else { ++$this->col; } return $c; }
[ "protected", "function", "getCurrentChar", "(", ")", "{", "$", "c", "=", "substr", "(", "$", "this", "->", "data", ",", "$", "this", "->", "p", ",", "1", ")", ";", "if", "(", "$", "c", "===", "\"\\n\"", ")", "{", "++", "$", "this", "->", "line"...
Current character. @return string Character.
[ "Current", "character", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Config/Parser.php#L525-L537
kakserpom/phpdaemon
PHPDaemon/FS/FileWatcher.php
FileWatcher.watch
public function watch() { if ($this->inotify) { $events = inotify_read($this->inotify); if (!$events) { return; } foreach ($events as $ev) { $path = $this->descriptors[$ev['wd']]; if (!isset($this->files[$path])) { continue; } $this->onFileChanged($path); } } else { static $hash = []; foreach ($this->files as $path => $v) { if (!file_exists($path)) { // file can be deleted unset($this->files[$path]); continue; } $mt = filemtime($path); if (isset($hash[$path]) && ($mt > $hash[$path])) { $this->onFileChanged($path); } $hash[$path] = $mt; } } }
php
public function watch() { if ($this->inotify) { $events = inotify_read($this->inotify); if (!$events) { return; } foreach ($events as $ev) { $path = $this->descriptors[$ev['wd']]; if (!isset($this->files[$path])) { continue; } $this->onFileChanged($path); } } else { static $hash = []; foreach ($this->files as $path => $v) { if (!file_exists($path)) { // file can be deleted unset($this->files[$path]); continue; } $mt = filemtime($path); if (isset($hash[$path]) && ($mt > $hash[$path])) { $this->onFileChanged($path); } $hash[$path] = $mt; } } }
[ "public", "function", "watch", "(", ")", "{", "if", "(", "$", "this", "->", "inotify", ")", "{", "$", "events", "=", "inotify_read", "(", "$", "this", "->", "inotify", ")", ";", "if", "(", "!", "$", "events", ")", "{", "return", ";", "}", "foreac...
Check the file system, triggered by timer @return void
[ "Check", "the", "file", "system", "triggered", "by", "timer" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileWatcher.php#L58-L91
kakserpom/phpdaemon
PHPDaemon/FS/FileWatcher.php
FileWatcher.onFileChanged
public function onFileChanged($path) { if (!Daemon::lintFile($path)) { Daemon::log(__METHOD__ . ': Detected parse error in ' . $path); return; } foreach ($this->files[$path] as $cb) { if (is_callable($cb) || is_array($cb)) { $cb($path); } elseif (!Daemon::$process->IPCManager->importFile($cb, $path)) { $this->rmWatch($path, $cb); } } }
php
public function onFileChanged($path) { if (!Daemon::lintFile($path)) { Daemon::log(__METHOD__ . ': Detected parse error in ' . $path); return; } foreach ($this->files[$path] as $cb) { if (is_callable($cb) || is_array($cb)) { $cb($path); } elseif (!Daemon::$process->IPCManager->importFile($cb, $path)) { $this->rmWatch($path, $cb); } } }
[ "public", "function", "onFileChanged", "(", "$", "path", ")", "{", "if", "(", "!", "Daemon", "::", "lintFile", "(", "$", "path", ")", ")", "{", "Daemon", "::", "log", "(", "__METHOD__", ".", "': Detected parse error in '", ".", "$", "path", ")", ";", "...
Called when file $path is changed @param string $path Path @return void
[ "Called", "when", "file", "$path", "is", "changed" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileWatcher.php#L98-L111
kakserpom/phpdaemon
PHPDaemon/FS/FileWatcher.php
FileWatcher.rmWatch
public function rmWatch($path, $cb) { $path = realpath($path); if (!isset($this->files[$path])) { return false; } if (($k = array_search($cb, $this->files[$path], true)) !== false) { unset($this->files[$path][$k]); } if (sizeof($this->files[$path]) === 0) { if ($this->inotify) { if (($descriptor = array_search($path, $this->descriptors)) !== false) { inotify_rm_watch($this->inotify, $cb); } } unset($this->files[$path]); } return true; }
php
public function rmWatch($path, $cb) { $path = realpath($path); if (!isset($this->files[$path])) { return false; } if (($k = array_search($cb, $this->files[$path], true)) !== false) { unset($this->files[$path][$k]); } if (sizeof($this->files[$path]) === 0) { if ($this->inotify) { if (($descriptor = array_search($path, $this->descriptors)) !== false) { inotify_rm_watch($this->inotify, $cb); } } unset($this->files[$path]); } return true; }
[ "public", "function", "rmWatch", "(", "$", "path", ",", "$", "cb", ")", "{", "$", "path", "=", "realpath", "(", "$", "path", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "files", "[", "$", "path", "]", ")", ")", "{", "return", "...
Cancels your subscription on object in FS @param string $path Path @param mixed $cb Callback @return boolean
[ "Cancels", "your", "subscription", "on", "object", "in", "FS" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileWatcher.php#L119-L138
kakserpom/phpdaemon
PHPDaemon/FS/FileWatcher.php
FileWatcher.addWatch
public function addWatch($path, $cb, $flags = null) { $path = realpath($path); if (!isset($this->files[$path])) { $this->files[$path] = []; if ($this->inotify) { $this->descriptors[inotify_add_watch($this->inotify, $path, $flags ?: IN_MODIFY)] = $path; } } $this->files[$path][] = $cb; Timer::setTimeout('fileWatcher'); return true; }
php
public function addWatch($path, $cb, $flags = null) { $path = realpath($path); if (!isset($this->files[$path])) { $this->files[$path] = []; if ($this->inotify) { $this->descriptors[inotify_add_watch($this->inotify, $path, $flags ?: IN_MODIFY)] = $path; } } $this->files[$path][] = $cb; Timer::setTimeout('fileWatcher'); return true; }
[ "public", "function", "addWatch", "(", "$", "path", ",", "$", "cb", ",", "$", "flags", "=", "null", ")", "{", "$", "path", "=", "realpath", "(", "$", "path", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "files", "[", "$", "path", ...
Adds your subscription on object in FS @param string $path Path @param mixed $cb Callback @param integer $flags Look inotify_add_watch() @return true
[ "Adds", "your", "subscription", "on", "object", "in", "FS" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileWatcher.php#L147-L159
kakserpom/phpdaemon
PHPDaemon/SockJS/Examples/Simple.php
Simple.onReady
public function onReady() { \PHPDaemon\Servers\WebSocket\Pool::getInstance()->addRoute( '/sockjs', function ($client) { return new SimpleRoute($client, $this); } ); }
php
public function onReady() { \PHPDaemon\Servers\WebSocket\Pool::getInstance()->addRoute( '/sockjs', function ($client) { return new SimpleRoute($client, $this); } ); }
[ "public", "function", "onReady", "(", ")", "{", "\\", "PHPDaemon", "\\", "Servers", "\\", "WebSocket", "\\", "Pool", "::", "getInstance", "(", ")", "->", "addRoute", "(", "'/sockjs'", ",", "function", "(", "$", "client", ")", "{", "return", "new", "Simpl...
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/SockJS/Examples/Simple.php#L38-L46
kakserpom/phpdaemon
PHPDaemon/Clients/Mongo/Pool.php
Pool.getAuthKey
public static function getAuthKey($username, $password, $nonce) { return md5($nonce . $username . md5($username . ':mongo:' . $password)); }
php
public static function getAuthKey($username, $password, $nonce) { return md5($nonce . $username . md5($username . ':mongo:' . $password)); }
[ "public", "static", "function", "getAuthKey", "(", "$", "username", ",", "$", "password", ",", "$", "nonce", ")", "{", "return", "md5", "(", "$", "nonce", ".", "$", "username", ".", "md5", "(", "$", "username", ".", "':mongo:'", ".", "$", "password", ...
Generates auth. key @param string $username Username @param string $password Password @param string $nonce Nonce @return string MD5 hash
[ "Generates", "auth", ".", "key" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Mongo/Pool.php#L135-L138
kakserpom/phpdaemon
PHPDaemon/Clients/Mongo/Pool.php
Pool.addServer
public function addServer($url, $weight = null, $mock = null) { $this->servers[$url] = $weight; }
php
public function addServer($url, $weight = null, $mock = null) { $this->servers[$url] = $weight; }
[ "public", "function", "addServer", "(", "$", "url", ",", "$", "weight", "=", "null", ",", "$", "mock", "=", "null", ")", "{", "$", "this", "->", "servers", "[", "$", "url", "]", "=", "$", "weight", ";", "}" ]
Adds mongo server @param string $url URL @param integer $weight Weight @param mixed $mock @deprecated @return void
[ "Adds", "mongo", "server" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Mongo/Pool.php#L147-L150
kakserpom/phpdaemon
PHPDaemon/Clients/Mongo/Pool.php
Pool.request
public function request($opcode, $data, $reply = false, $conn = null, $sentcb = null) { $cb = $this->requestCbProducer($opcode, $data, $reply, $sentcb); if (is_object($conn) && ($conn instanceof Connection)) { if ($conn->isFinished()) { throw new ConnectionFinished; } $cb($conn); } elseif ($this->finished) { $cb(false); } else { $this->getConnectionRR($cb); } }
php
public function request($opcode, $data, $reply = false, $conn = null, $sentcb = null) { $cb = $this->requestCbProducer($opcode, $data, $reply, $sentcb); if (is_object($conn) && ($conn instanceof Connection)) { if ($conn->isFinished()) { throw new ConnectionFinished; } $cb($conn); } elseif ($this->finished) { $cb(false); } else { $this->getConnectionRR($cb); } }
[ "public", "function", "request", "(", "$", "opcode", ",", "$", "data", ",", "$", "reply", "=", "false", ",", "$", "conn", "=", "null", ",", "$", "sentcb", "=", "null", ")", "{", "$", "cb", "=", "$", "this", "->", "requestCbProducer", "(", "$", "o...
Gets the key @param integer $opcode Opcode (see constants above) @param string $data Data @param boolean $reply Is an answer expected? @param Connection $conn Connection. Optional @param callable $sentcb Sent callback @callback $sentcb ( ) @throws ConnectionFinished @return void
[ "Gets", "the", "key" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Mongo/Pool.php#L163-L176
kakserpom/phpdaemon
PHPDaemon/Clients/Mongo/Pool.php
Pool.findAll
public function findAll($p, $cb) { $this->find($p, function ($cursor) use ($cb) { if (!$cursor->isFinished()) { $cursor->getMore(); } else { $cb($cursor); } }); }
php
public function findAll($p, $cb) { $this->find($p, function ($cursor) use ($cb) { if (!$cursor->isFinished()) { $cursor->getMore(); } else { $cb($cursor); } }); }
[ "public", "function", "findAll", "(", "$", "p", ",", "$", "cb", ")", "{", "$", "this", "->", "find", "(", "$", "p", ",", "function", "(", "$", "cursor", ")", "use", "(", "$", "cb", ")", "{", "if", "(", "!", "$", "cursor", "->", "isFinished", ...
Finds objects in collection and fires callback when got all objects @param array $p Hash of properties (offset, limit, opts, tailable, await, where, col, fields, sort, hint, explain, snapshot, orderby, parse_oplog) @param callable $cb Callback called when response received @callback $cb ( ) @return void
[ "Finds", "objects", "in", "collection", "and", "fires", "callback", "when", "got", "all", "objects" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Mongo/Pool.php#L220-L229
kakserpom/phpdaemon
PHPDaemon/Clients/Mongo/Pool.php
Pool.find
public function find($p, $cb) { if (!isset($p['offset'])) { $p['offset'] = 0; } if (!isset($p['limit'])) { $p['limit'] = 0; } if (!isset($p['opts'])) { $p['opts'] = '0'; } if (isset($p['tailable']) && $p['tailable']) { $p['opts'] = '01000' . (isset($p['await']) && $p['await'] ? '1' : '0') . '00'; } if (!isset($p['where'])) { $p['where'] = []; } $this->_params($p); $o = []; $s = false; foreach ($p as $k => $v) { if (($k === 'sort') || ($k === 'hint') || ($k === 'explain') || ($k === 'snapshot')) { if (!$s) { $s = true; } if ($k === 'sort') { $o['orderby'] = $v; } elseif ($k === 'parse_oplog') { } elseif ($k === 'rp') { $o['$readPreference'] = $v; } else { $o[$k] = $v; } } } if ($s) { $o['query'] = $p['where']; } else { $o = $p['where']; } if (empty($o['orderby'])) { unset($o['orderby']); } if ($this->safeMode) { static::safeModeEnc($o); } try { $bson = bson_encode($o); if (isset($p['parse_oplog'])) { $bson = str_replace("\x11\$gt", "\x09\$gt", $bson); } $cb = CallbackWrapper::wrap($cb); $this->request( self::OP_QUERY, chr(bindec(strrev($p['opts']))) . "\x00\x00\x00" . $p['col'] . "\x00" . pack('VV', $p['offset'], $p['limit']) . $bson . (isset($p['fields']) ? bson_encode($p['fields']) : ''), true, null, function ($conn, $reqId = null) use ($p, $cb) { if (!$conn) { !$cb || $cb(['$err' => 'Connection error.']); return; } $conn->requests[$reqId] = [$p['col'], $cb, false, isset($p['parse_oplog']), isset($p['tailable'])]; } ); } catch (\MongoException $e) { Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString()); if ($cb !== null) { $cb([ '$err' => $e->getMessage(), '$query' => $o, '$fields' => isset($p['fields']) ? $p['fields'] : null ]); } } }
php
public function find($p, $cb) { if (!isset($p['offset'])) { $p['offset'] = 0; } if (!isset($p['limit'])) { $p['limit'] = 0; } if (!isset($p['opts'])) { $p['opts'] = '0'; } if (isset($p['tailable']) && $p['tailable']) { $p['opts'] = '01000' . (isset($p['await']) && $p['await'] ? '1' : '0') . '00'; } if (!isset($p['where'])) { $p['where'] = []; } $this->_params($p); $o = []; $s = false; foreach ($p as $k => $v) { if (($k === 'sort') || ($k === 'hint') || ($k === 'explain') || ($k === 'snapshot')) { if (!$s) { $s = true; } if ($k === 'sort') { $o['orderby'] = $v; } elseif ($k === 'parse_oplog') { } elseif ($k === 'rp') { $o['$readPreference'] = $v; } else { $o[$k] = $v; } } } if ($s) { $o['query'] = $p['where']; } else { $o = $p['where']; } if (empty($o['orderby'])) { unset($o['orderby']); } if ($this->safeMode) { static::safeModeEnc($o); } try { $bson = bson_encode($o); if (isset($p['parse_oplog'])) { $bson = str_replace("\x11\$gt", "\x09\$gt", $bson); } $cb = CallbackWrapper::wrap($cb); $this->request( self::OP_QUERY, chr(bindec(strrev($p['opts']))) . "\x00\x00\x00" . $p['col'] . "\x00" . pack('VV', $p['offset'], $p['limit']) . $bson . (isset($p['fields']) ? bson_encode($p['fields']) : ''), true, null, function ($conn, $reqId = null) use ($p, $cb) { if (!$conn) { !$cb || $cb(['$err' => 'Connection error.']); return; } $conn->requests[$reqId] = [$p['col'], $cb, false, isset($p['parse_oplog']), isset($p['tailable'])]; } ); } catch (\MongoException $e) { Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString()); if ($cb !== null) { $cb([ '$err' => $e->getMessage(), '$query' => $o, '$fields' => isset($p['fields']) ? $p['fields'] : null ]); } } }
[ "public", "function", "find", "(", "$", "p", ",", "$", "cb", ")", "{", "if", "(", "!", "isset", "(", "$", "p", "[", "'offset'", "]", ")", ")", "{", "$", "p", "[", "'offset'", "]", "=", "0", ";", "}", "if", "(", "!", "isset", "(", "$", "p"...
Finds objects in collection @param array $p Hash of properties (offset, limit, opts, tailable, await, where, col, fields, sort, hint, explain, snapshot, orderby, parse_oplog) @param callable $cb Callback called when response received @callback $cb ( ) @return void
[ "Finds", "objects", "in", "collection" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Mongo/Pool.php#L238-L327
kakserpom/phpdaemon
PHPDaemon/Clients/Mongo/Pool.php
Pool.findOne
public function findOne($p, $cb) { if (isset($p['cachekey'])) { $db = $this; $this->cache->get($p['cachekey'], function ($r) use ($db, $p, $cb) { if ($r->result !== null) { $cb(bson_decode($r->result)); } else { unset($p['cachekey']); $db->findOne($p, $cb); } }); return; } if (!isset($p['where'])) { $p['where'] = []; } $this->_params($p); $o = []; $s = false; foreach ($p as $k => $v) { if (($k === 'sort') || ($k === 'hint') || ($k === 'explain') || ($k === 'snapshot')) { if (!$s) { $s = true; } if ($k === 'sort') { $o['orderby'] = $v; } elseif ($k === 'parse_oplog') { } elseif ($k === 'rp') { $o['$readPreference'] = $v; } else { $o[$k] = $v; } } } if (empty($o['orderby'])) { unset($o['orderby']); } if ($s) { $o['query'] = $p['where']; } else { $o = $p['where']; } $cb = CallbackWrapper::wrap($cb); if ($this->safeMode) { static::safeModeEnc($o); } try { $this->request( self::OP_QUERY, pack('V', $p['opts']) . $p['col'] . "\x00" . pack('VV', $p['offset'], -1) . bson_encode($o) . (isset($p['fields']) ? bson_encode($p['fields']) : ''), true, null, function ($conn, $reqId = null) use ($p, $cb) { if (!$conn) { !$cb || $cb(['$err' => 'Connection error.']); return; } $conn->requests[$reqId] = [$p['col'], $cb, true]; } ); } catch (\MongoException $e) { Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString()); if ($cb !== null) { $cb([ '$err' => $e->getMessage(), '$query' => $o, '$fields' => isset($p['fields']) ? $p['fields'] : null ]); } } }
php
public function findOne($p, $cb) { if (isset($p['cachekey'])) { $db = $this; $this->cache->get($p['cachekey'], function ($r) use ($db, $p, $cb) { if ($r->result !== null) { $cb(bson_decode($r->result)); } else { unset($p['cachekey']); $db->findOne($p, $cb); } }); return; } if (!isset($p['where'])) { $p['where'] = []; } $this->_params($p); $o = []; $s = false; foreach ($p as $k => $v) { if (($k === 'sort') || ($k === 'hint') || ($k === 'explain') || ($k === 'snapshot')) { if (!$s) { $s = true; } if ($k === 'sort') { $o['orderby'] = $v; } elseif ($k === 'parse_oplog') { } elseif ($k === 'rp') { $o['$readPreference'] = $v; } else { $o[$k] = $v; } } } if (empty($o['orderby'])) { unset($o['orderby']); } if ($s) { $o['query'] = $p['where']; } else { $o = $p['where']; } $cb = CallbackWrapper::wrap($cb); if ($this->safeMode) { static::safeModeEnc($o); } try { $this->request( self::OP_QUERY, pack('V', $p['opts']) . $p['col'] . "\x00" . pack('VV', $p['offset'], -1) . bson_encode($o) . (isset($p['fields']) ? bson_encode($p['fields']) : ''), true, null, function ($conn, $reqId = null) use ($p, $cb) { if (!$conn) { !$cb || $cb(['$err' => 'Connection error.']); return; } $conn->requests[$reqId] = [$p['col'], $cb, true]; } ); } catch (\MongoException $e) { Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString()); if ($cb !== null) { $cb([ '$err' => $e->getMessage(), '$query' => $o, '$fields' => isset($p['fields']) ? $p['fields'] : null ]); } } }
[ "public", "function", "findOne", "(", "$", "p", ",", "$", "cb", ")", "{", "if", "(", "isset", "(", "$", "p", "[", "'cachekey'", "]", ")", ")", "{", "$", "db", "=", "$", "this", ";", "$", "this", "->", "cache", "->", "get", "(", "$", "p", "[...
Finds one object in collection @param array $p Hash of properties (offset, opts, where, col, fields, sort, hint, explain, snapshot, orderby, parse_oplog) @param callable $cb Callback called when response received @callback $cb ( ) @return void
[ "Finds", "one", "object", "in", "collection" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Mongo/Pool.php#L336-L414
kakserpom/phpdaemon
PHPDaemon/Clients/Mongo/Pool.php
Pool.findCount
public function findCount($p, $cb) { if (!isset($p['offset'])) { $p['offset'] = 0; } if (!isset($p['limit'])) { $p['limit'] = -1; } if (!isset($p['opts'])) { $p['opts'] = 0; } if (!isset($p['where'])) { $p['where'] = []; } if (mb_orig_strpos($p['col'], '.') === false) { $p['col'] = $this->dbname . '.' . $p['col']; } $e = explode('.', $p['col'], 2); $query = [ 'count' => $e[1], 'query' => $p['where'], 'fields' => ['_id' => 1], ]; if (isset($p[$k = 'rp'])) { $v = $p[$k]; if (is_string($v)) { $v = ['mode' => $v]; } $query['$readPreference'] = $v; } if (is_string($p['where'])) { $query['where'] = new \MongoCode($p['where']); } elseif (is_object($p['where']) || sizeof($p['where'])) { $query['query'] = $p['where']; } $cb = CallbackWrapper::wrap($cb); if ($this->safeMode) { static::safeModeEnc($query); } try { $this->request( self::OP_QUERY, pack('V', $p['opts']) . $e[0] . '.$cmd' . "\x00" . pack('VV', $p['offset'], $p['limit']) . bson_encode($query) . (isset($p['fields']) ? bson_encode($p['fields']) : ''), true, null, function ($conn, $reqId = null) use ($p, $cb) { if (!$conn) { !$cb || $cb(['$err' => 'Connection error.']); return; } $conn->requests[$reqId] = [$p['col'], $cb, true]; } ); } catch (\MongoException $e) { Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString()); if ($cb !== null) { $cb([ '$err' => $e->getMessage(), '$query' => $query, '$fields' => isset($p['fields']) ? $p['fields'] : null ]); } } }
php
public function findCount($p, $cb) { if (!isset($p['offset'])) { $p['offset'] = 0; } if (!isset($p['limit'])) { $p['limit'] = -1; } if (!isset($p['opts'])) { $p['opts'] = 0; } if (!isset($p['where'])) { $p['where'] = []; } if (mb_orig_strpos($p['col'], '.') === false) { $p['col'] = $this->dbname . '.' . $p['col']; } $e = explode('.', $p['col'], 2); $query = [ 'count' => $e[1], 'query' => $p['where'], 'fields' => ['_id' => 1], ]; if (isset($p[$k = 'rp'])) { $v = $p[$k]; if (is_string($v)) { $v = ['mode' => $v]; } $query['$readPreference'] = $v; } if (is_string($p['where'])) { $query['where'] = new \MongoCode($p['where']); } elseif (is_object($p['where']) || sizeof($p['where'])) { $query['query'] = $p['where']; } $cb = CallbackWrapper::wrap($cb); if ($this->safeMode) { static::safeModeEnc($query); } try { $this->request( self::OP_QUERY, pack('V', $p['opts']) . $e[0] . '.$cmd' . "\x00" . pack('VV', $p['offset'], $p['limit']) . bson_encode($query) . (isset($p['fields']) ? bson_encode($p['fields']) : ''), true, null, function ($conn, $reqId = null) use ($p, $cb) { if (!$conn) { !$cb || $cb(['$err' => 'Connection error.']); return; } $conn->requests[$reqId] = [$p['col'], $cb, true]; } ); } catch (\MongoException $e) { Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString()); if ($cb !== null) { $cb([ '$err' => $e->getMessage(), '$query' => $query, '$fields' => isset($p['fields']) ? $p['fields'] : null ]); } } }
[ "public", "function", "findCount", "(", "$", "p", ",", "$", "cb", ")", "{", "if", "(", "!", "isset", "(", "$", "p", "[", "'offset'", "]", ")", ")", "{", "$", "p", "[", "'offset'", "]", "=", "0", ";", "}", "if", "(", "!", "isset", "(", "$", ...
Counts objects in collection @param array $p Hash of properties (offset, limit, opts, where, col) @param callable $cb Callback called when response received @callback $cb ( ) @return void
[ "Counts", "objects", "in", "collection" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Mongo/Pool.php#L423-L495
kakserpom/phpdaemon
PHPDaemon/Clients/Mongo/Pool.php
Pool.auth
public function auth($p, $cb) { if (!isset($p['opts'])) { $p['opts'] = 0; } $query = [ 'authenticate' => 1, 'user' => $p['user'], 'nonce' => $p['nonce'], 'key' => self::getAuthKey($p['user'], $p['password'], $p['nonce']), ]; if ($this->safeMode) { static::safeModeEnc($query); } try { $this->request( self::OP_QUERY, pack('V', $p['opts']) . $p['dbname'] . '.$cmd' . "\x00" . pack('VV', 0, -1) . bson_encode($query) . (isset($p['fields']) ? bson_encode($p['fields']) : ''), true, null, function ($conn, $reqId = null) use ($p, $cb) { if (!$conn) { !$cb || $cb(['$err' => 'Connection error.']); return; } $conn->requests[$reqId] = [$p['dbname'], $cb, true]; } ); } catch (\MongoException $e) { Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString()); if ($cb !== null) { $cb([ '$err' => $e->getMessage(), '$query' => $query, '$fields' => isset($p['fields']) ? $p['fields'] : null ]); } } }
php
public function auth($p, $cb) { if (!isset($p['opts'])) { $p['opts'] = 0; } $query = [ 'authenticate' => 1, 'user' => $p['user'], 'nonce' => $p['nonce'], 'key' => self::getAuthKey($p['user'], $p['password'], $p['nonce']), ]; if ($this->safeMode) { static::safeModeEnc($query); } try { $this->request( self::OP_QUERY, pack('V', $p['opts']) . $p['dbname'] . '.$cmd' . "\x00" . pack('VV', 0, -1) . bson_encode($query) . (isset($p['fields']) ? bson_encode($p['fields']) : ''), true, null, function ($conn, $reqId = null) use ($p, $cb) { if (!$conn) { !$cb || $cb(['$err' => 'Connection error.']); return; } $conn->requests[$reqId] = [$p['dbname'], $cb, true]; } ); } catch (\MongoException $e) { Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString()); if ($cb !== null) { $cb([ '$err' => $e->getMessage(), '$query' => $query, '$fields' => isset($p['fields']) ? $p['fields'] : null ]); } } }
[ "public", "function", "auth", "(", "$", "p", ",", "$", "cb", ")", "{", "if", "(", "!", "isset", "(", "$", "p", "[", "'opts'", "]", ")", ")", "{", "$", "p", "[", "'opts'", "]", "=", "0", ";", "}", "$", "query", "=", "[", "'authenticate'", "=...
Sends authenciation packet @param array $p Hash of properties (dbname, user, password, nonce) @param callable $cb Callback called when response received @callback $cb ( ) @return void
[ "Sends", "authenciation", "packet" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Mongo/Pool.php#L504-L544
kakserpom/phpdaemon
PHPDaemon/Clients/Mongo/Pool.php
Pool.ensureIndex
public function ensureIndex($ns, $keys, $options = [], $cb = null) { $e = explode('.', $ns, 2); $doc = [ 'ns' => $ns, 'key' => $keys, 'name' => isset($options['name']) ? $options['name'] : $this->getIndexName($keys), ]; if (isset($options['unique'])) { $doc['unique'] = $options['unique']; } if (isset($options['sparse'])) { $doc['sparse'] = $options['sparse']; } if (isset($options['version'])) { $doc['v'] = $options['version']; } if (isset($options['background'])) { $doc['background'] = $options['background']; } if (isset($options['ttl'])) { $doc['expireAfterSeconds'] = $options['ttl']; } $this->getCollection($e[0] . '.system.indexes')->insert($doc, $cb); }
php
public function ensureIndex($ns, $keys, $options = [], $cb = null) { $e = explode('.', $ns, 2); $doc = [ 'ns' => $ns, 'key' => $keys, 'name' => isset($options['name']) ? $options['name'] : $this->getIndexName($keys), ]; if (isset($options['unique'])) { $doc['unique'] = $options['unique']; } if (isset($options['sparse'])) { $doc['sparse'] = $options['sparse']; } if (isset($options['version'])) { $doc['v'] = $options['version']; } if (isset($options['background'])) { $doc['background'] = $options['background']; } if (isset($options['ttl'])) { $doc['expireAfterSeconds'] = $options['ttl']; } $this->getCollection($e[0] . '.system.indexes')->insert($doc, $cb); }
[ "public", "function", "ensureIndex", "(", "$", "ns", ",", "$", "keys", ",", "$", "options", "=", "[", "]", ",", "$", "cb", "=", "null", ")", "{", "$", "e", "=", "explode", "(", "'.'", ",", "$", "ns", ",", "2", ")", ";", "$", "doc", "=", "["...
Ensure index @param string $ns Collection @param array $keys Keys @param array $options Optional. Options @param callable $cb Optional. Callback called when response received @callback $cb ( ) @return void
[ "Ensure", "index" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Mongo/Pool.php#L616-L640
kakserpom/phpdaemon
PHPDaemon/Clients/Mongo/Pool.php
Pool.lastError
public function lastError($db, $cb, $params = [], $conn = null) { $e = explode('.', $db, 2); $params['getlasterror'] = 1; $cb = CallbackWrapper::wrap($cb); try { $this->request( self::OP_QUERY, pack('V', 0) . $e[0] . '.$cmd' . "\x00" . pack('VV', 0, -1) . bson_encode($params), true, $conn, function ($conn, $reqId = null) use ($db, $cb) { if (!$conn) { !$cb || $cb(['$err' => 'Connection error.']); return; } $conn->requests[$reqId] = [$db, $cb, true]; } ); } catch (\MongoException $e) { Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString()); if ($cb !== null) { $cb(['$err' => $e->getMessage()]); } } }
php
public function lastError($db, $cb, $params = [], $conn = null) { $e = explode('.', $db, 2); $params['getlasterror'] = 1; $cb = CallbackWrapper::wrap($cb); try { $this->request( self::OP_QUERY, pack('V', 0) . $e[0] . '.$cmd' . "\x00" . pack('VV', 0, -1) . bson_encode($params), true, $conn, function ($conn, $reqId = null) use ($db, $cb) { if (!$conn) { !$cb || $cb(['$err' => 'Connection error.']); return; } $conn->requests[$reqId] = [$db, $cb, true]; } ); } catch (\MongoException $e) { Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString()); if ($cb !== null) { $cb(['$err' => $e->getMessage()]); } } }
[ "public", "function", "lastError", "(", "$", "db", ",", "$", "cb", ",", "$", "params", "=", "[", "]", ",", "$", "conn", "=", "null", ")", "{", "$", "e", "=", "explode", "(", "'.'", ",", "$", "db", ",", "2", ")", ";", "$", "params", "[", "'g...
Gets last error @param string $db Dbname @param callable $cb Callback called when response received @param array $params Parameters. @param Connection $conn Connection. Optional @callback $cb ( ) @return void
[ "Gets", "last", "error" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Mongo/Pool.php#L651-L677
kakserpom/phpdaemon
PHPDaemon/Clients/Mongo/Pool.php
Pool.evaluate
public function evaluate($code, $cb) { $p = []; if (!isset($p['offset'])) { $p['offset'] = 0; } if (!isset($p['limit'])) { $p['limit'] = -1; } if (!isset($p['opts'])) { $p['opts'] = 0; } if (!isset($p['db'])) { $p['db'] = $this->dbname; } $cb = CallbackWrapper::wrap($cb); try { $this->request( self::OP_QUERY, pack('V', $p['opts']) . $p['db'] . '.$cmd' . "\x00" . pack('VV', $p['offset'], $p['limit']) . bson_encode(['$eval' => new \MongoCode($code)]) . (isset($p['fields']) ? bson_encode($p['fields']) : ''), true, null, function ($conn, $reqId = null) use ($p, $cb) { if (!$conn) { !$cb || $cb(['$err' => 'Connection error.']); return; } $conn->requests[$reqId] = [$p['db'], $cb, true]; } ); } catch (\MongoException $e) { Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString()); if ($cb !== null) { $cb([ '$err' => $e->getMessage(), '$query' => $query, '$fields' => isset($p['fields']) ? $p['fields'] : null ]); } } }
php
public function evaluate($code, $cb) { $p = []; if (!isset($p['offset'])) { $p['offset'] = 0; } if (!isset($p['limit'])) { $p['limit'] = -1; } if (!isset($p['opts'])) { $p['opts'] = 0; } if (!isset($p['db'])) { $p['db'] = $this->dbname; } $cb = CallbackWrapper::wrap($cb); try { $this->request( self::OP_QUERY, pack('V', $p['opts']) . $p['db'] . '.$cmd' . "\x00" . pack('VV', $p['offset'], $p['limit']) . bson_encode(['$eval' => new \MongoCode($code)]) . (isset($p['fields']) ? bson_encode($p['fields']) : ''), true, null, function ($conn, $reqId = null) use ($p, $cb) { if (!$conn) { !$cb || $cb(['$err' => 'Connection error.']); return; } $conn->requests[$reqId] = [$p['db'], $cb, true]; } ); } catch (\MongoException $e) { Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString()); if ($cb !== null) { $cb([ '$err' => $e->getMessage(), '$query' => $query, '$fields' => isset($p['fields']) ? $p['fields'] : null ]); } } }
[ "public", "function", "evaluate", "(", "$", "code", ",", "$", "cb", ")", "{", "$", "p", "=", "[", "]", ";", "if", "(", "!", "isset", "(", "$", "p", "[", "'offset'", "]", ")", ")", "{", "$", "p", "[", "'offset'", "]", "=", "0", ";", "}", "...
Evaluates a code on the server side @param string $code Code @param callable $cb Callback called when response received @callback $cb ( ) @return void
[ "Evaluates", "a", "code", "on", "the", "server", "side" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Mongo/Pool.php#L775-L822
kakserpom/phpdaemon
PHPDaemon/Clients/Mongo/Pool.php
Pool.distinct
public function distinct($p, $cb) { $this->_params($p); $e = explode('.', $p['col'], 2); $query = [ 'distinct' => $e[1], 'key' => $p['key'], ]; if (isset($p[$k = 'rp'])) { $v = $p[$k]; if (is_string($v)) { $v = ['mode' => $v]; } $query['$readPreference'] = $v; } if (isset($p['where'])) { $query['query'] = $p['where']; } $cb = CallbackWrapper::wrap($cb); $this->request( self::OP_QUERY, pack('V', $p['opts']) . $e[0] . '.$cmd' . "\x00" . pack('VV', $p['offset'], $p['limit']) . bson_encode($query) . (isset($p['fields']) ? bson_encode($p['fields']) : ''), true, null, function ($conn, $reqId = null) use ($p, $cb) { if (!$conn) { !$cb || $cb(['$err' => 'Connection error.']); return; } $conn->requests[$reqId] = [$p['col'], $cb, true]; } ); }
php
public function distinct($p, $cb) { $this->_params($p); $e = explode('.', $p['col'], 2); $query = [ 'distinct' => $e[1], 'key' => $p['key'], ]; if (isset($p[$k = 'rp'])) { $v = $p[$k]; if (is_string($v)) { $v = ['mode' => $v]; } $query['$readPreference'] = $v; } if (isset($p['where'])) { $query['query'] = $p['where']; } $cb = CallbackWrapper::wrap($cb); $this->request( self::OP_QUERY, pack('V', $p['opts']) . $e[0] . '.$cmd' . "\x00" . pack('VV', $p['offset'], $p['limit']) . bson_encode($query) . (isset($p['fields']) ? bson_encode($p['fields']) : ''), true, null, function ($conn, $reqId = null) use ($p, $cb) { if (!$conn) { !$cb || $cb(['$err' => 'Connection error.']); return; } $conn->requests[$reqId] = [$p['col'], $cb, true]; } ); }
[ "public", "function", "distinct", "(", "$", "p", ",", "$", "cb", ")", "{", "$", "this", "->", "_params", "(", "$", "p", ")", ";", "$", "e", "=", "explode", "(", "'.'", ",", "$", "p", "[", "'col'", "]", ",", "2", ")", ";", "$", "query", "=",...
Returns distinct values of the property @param array $p Hash of properties (offset, limit, opts, key, col, where) @param callable $cb Callback called when response received @callback $cb ( ) @return void
[ "Returns", "distinct", "values", "of", "the", "property" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Mongo/Pool.php#L831-L868
kakserpom/phpdaemon
PHPDaemon/Clients/Mongo/Pool.php
Pool._paramFields
protected function _paramFields($f) { if (is_string($f)) { $f = array_map('trim', explode(',', $f)); } if (!is_array($f) || sizeof($f) === 0) { return null; } if (!isset($f[0])) { return $f; } $p = []; foreach ($f as $k) { $p[$k] = 1; } return $p; }
php
protected function _paramFields($f) { if (is_string($f)) { $f = array_map('trim', explode(',', $f)); } if (!is_array($f) || sizeof($f) === 0) { return null; } if (!isset($f[0])) { return $f; } $p = []; foreach ($f as $k) { $p[$k] = 1; } return $p; }
[ "protected", "function", "_paramFields", "(", "$", "f", ")", "{", "if", "(", "is_string", "(", "$", "f", ")", ")", "{", "$", "f", "=", "array_map", "(", "'trim'", ",", "explode", "(", "','", ",", "$", "f", ")", ")", ";", "}", "if", "(", "!", ...
[_paramFields description] @param mixed $f @return array
[ "[", "_paramFields", "description", "]" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Mongo/Pool.php#L875-L891
kakserpom/phpdaemon
PHPDaemon/Clients/Mongo/Pool.php
Pool._params
protected function _params(&$p) { foreach ($p as $k => &$v) { if ($k === 'fields' || $k === 'sort') { $v = $this->_paramFields($v); } elseif ($k === 'where') { if (is_string($v)) { $v = new \MongoCode($v); } } elseif ($k === 'reduce') { if (is_string($v)) { $v = new \MongoCode($v); } } elseif ($k === 'rp') { if (is_string($v)) { $v = ['mode' => $v]; } } } if (!isset($p['offset'])) { $p['offset'] = 0; } if (!isset($p['limit'])) { $p['limit'] = -1; } if (!isset($p['opts'])) { $p['opts'] = 0; } if (!isset($p['key'])) { $p['key'] = ''; } if (mb_orig_strpos($p['col'], '.') === false) { $p['col'] = $this->dbname . '.' . $p['col']; } }
php
protected function _params(&$p) { foreach ($p as $k => &$v) { if ($k === 'fields' || $k === 'sort') { $v = $this->_paramFields($v); } elseif ($k === 'where') { if (is_string($v)) { $v = new \MongoCode($v); } } elseif ($k === 'reduce') { if (is_string($v)) { $v = new \MongoCode($v); } } elseif ($k === 'rp') { if (is_string($v)) { $v = ['mode' => $v]; } } } if (!isset($p['offset'])) { $p['offset'] = 0; } if (!isset($p['limit'])) { $p['limit'] = -1; } if (!isset($p['opts'])) { $p['opts'] = 0; } if (!isset($p['key'])) { $p['key'] = ''; } if (mb_orig_strpos($p['col'], '.') === false) { $p['col'] = $this->dbname . '.' . $p['col']; } }
[ "protected", "function", "_params", "(", "&", "$", "p", ")", "{", "foreach", "(", "$", "p", "as", "$", "k", "=>", "&", "$", "v", ")", "{", "if", "(", "$", "k", "===", "'fields'", "||", "$", "k", "===", "'sort'", ")", "{", "$", "v", "=", "$"...
[_params description] @param array &$p @return void
[ "[", "_params", "description", "]" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Mongo/Pool.php#L898-L937
kakserpom/phpdaemon
PHPDaemon/Clients/Mongo/Pool.php
Pool.findAndModify
public function findAndModify($p, $cb) { $this->_params($p); $e = explode('.', $p['col'], 2); $query = [ 'findAndModify' => $e[1], ]; if (isset($p[$k = 'rp'])) { $v = $p[$k]; if (is_string($v)) { $v = ['mode' => $v]; } $query['$readPreference'] = $v; } if (isset($p['sort'])) { $query['sort'] = $p['sort']; } if (isset($p['update'])) { $query['update'] = $p['update']; } if (isset($p['new'])) { $query['new'] = (boolean)$p['new']; } if (isset($p['remove'])) { $query['remove'] = (boolean)$p['remove']; } if (isset($p['upsert'])) { $query['upsert'] = (boolean)$p['upsert']; } if (isset($p['where'])) { $query['query'] = $p['where']; } elseif (isset($p['query'])) { $query['query'] = $p['query']; } if ($this->safeMode) { static::safeModeEnc($query); } $cb = CallbackWrapper::wrap($cb); try { $this->request( self::OP_QUERY, pack('V', $p['opts']) . $e[0] . '.$cmd' . "\x00" . pack('VV', $p['offset'], $p['limit']) . bson_encode($query) . (isset($p['fields']) ? bson_encode($p['fields']) : ''), true, null, function ($conn, $reqId = null) use ($p, $cb) { if (!$conn) { !$cb || $cb(['$err' => 'Connection error.']); return; } $conn->requests[$reqId] = [$p['col'], $cb, true]; } ); } catch (\MongoException $e) { Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString()); if ($cb !== null) { $cb([ '$err' => $e->getMessage(), '$query' => $query, '$fields' => isset($p['fields']) ? $p['fields'] : null ]); } } }
php
public function findAndModify($p, $cb) { $this->_params($p); $e = explode('.', $p['col'], 2); $query = [ 'findAndModify' => $e[1], ]; if (isset($p[$k = 'rp'])) { $v = $p[$k]; if (is_string($v)) { $v = ['mode' => $v]; } $query['$readPreference'] = $v; } if (isset($p['sort'])) { $query['sort'] = $p['sort']; } if (isset($p['update'])) { $query['update'] = $p['update']; } if (isset($p['new'])) { $query['new'] = (boolean)$p['new']; } if (isset($p['remove'])) { $query['remove'] = (boolean)$p['remove']; } if (isset($p['upsert'])) { $query['upsert'] = (boolean)$p['upsert']; } if (isset($p['where'])) { $query['query'] = $p['where']; } elseif (isset($p['query'])) { $query['query'] = $p['query']; } if ($this->safeMode) { static::safeModeEnc($query); } $cb = CallbackWrapper::wrap($cb); try { $this->request( self::OP_QUERY, pack('V', $p['opts']) . $e[0] . '.$cmd' . "\x00" . pack('VV', $p['offset'], $p['limit']) . bson_encode($query) . (isset($p['fields']) ? bson_encode($p['fields']) : ''), true, null, function ($conn, $reqId = null) use ($p, $cb) { if (!$conn) { !$cb || $cb(['$err' => 'Connection error.']); return; } $conn->requests[$reqId] = [$p['col'], $cb, true]; } ); } catch (\MongoException $e) { Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString()); if ($cb !== null) { $cb([ '$err' => $e->getMessage(), '$query' => $query, '$fields' => isset($p['fields']) ? $p['fields'] : null ]); } } }
[ "public", "function", "findAndModify", "(", "$", "p", ",", "$", "cb", ")", "{", "$", "this", "->", "_params", "(", "$", "p", ")", ";", "$", "e", "=", "explode", "(", "'.'", ",", "$", "p", "[", "'col'", "]", ",", "2", ")", ";", "$", "query", ...
Find and modify @param array $p Hash of properties @param callable $cb Callback called when response received @callback $cb ( ) @return void
[ "Find", "and", "modify" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Mongo/Pool.php#L946-L1012
kakserpom/phpdaemon
PHPDaemon/Clients/Mongo/Pool.php
Pool.aggregate
public function aggregate($p, $cb) { $this->_params($p); $e = explode('.', $p['col'], 2); $query = [ 'aggregate' => $e[1] ]; if (isset($p['rp'])) { $query['$readPreference'] = $p['rp']; unset($p['rp']); } foreach ($p as $k => $v) { if (substr($k, 0, 1) === '$' || $k === 'pipeline') { $query[$k] = $v; } } $cb = CallbackWrapper::wrap($cb); try { $this->request( self::OP_QUERY, pack('V', $p['opts']) . $e[0] . '.$cmd' . "\x00" . pack('VV', $p['offset'], $p['limit']) . bson_encode($query) . (isset($p['fields']) ? bson_encode($p['fields']) : ''), true, null, function ($conn, $reqId = null) use ($p, $cb) { if (!$conn) { !$cb || $cb(['$err' => 'Connection error.']); return; } $conn->requests[$reqId] = [$p['col'], $cb, false]; } ); } catch (\MongoException $e) { Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString()); if ($cb !== null) { $cb([ '$err' => $e->getMessage(), '$query' => $query, '$fields' => isset($p['fields']) ? $p['fields'] : null ]); } } }
php
public function aggregate($p, $cb) { $this->_params($p); $e = explode('.', $p['col'], 2); $query = [ 'aggregate' => $e[1] ]; if (isset($p['rp'])) { $query['$readPreference'] = $p['rp']; unset($p['rp']); } foreach ($p as $k => $v) { if (substr($k, 0, 1) === '$' || $k === 'pipeline') { $query[$k] = $v; } } $cb = CallbackWrapper::wrap($cb); try { $this->request( self::OP_QUERY, pack('V', $p['opts']) . $e[0] . '.$cmd' . "\x00" . pack('VV', $p['offset'], $p['limit']) . bson_encode($query) . (isset($p['fields']) ? bson_encode($p['fields']) : ''), true, null, function ($conn, $reqId = null) use ($p, $cb) { if (!$conn) { !$cb || $cb(['$err' => 'Connection error.']); return; } $conn->requests[$reqId] = [$p['col'], $cb, false]; } ); } catch (\MongoException $e) { Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString()); if ($cb !== null) { $cb([ '$err' => $e->getMessage(), '$query' => $query, '$fields' => isset($p['fields']) ? $p['fields'] : null ]); } } }
[ "public", "function", "aggregate", "(", "$", "p", ",", "$", "cb", ")", "{", "$", "this", "->", "_params", "(", "$", "p", ")", ";", "$", "e", "=", "explode", "(", "'.'", ",", "$", "p", "[", "'col'", "]", ",", "2", ")", ";", "$", "query", "="...
Aggregate function @param array $p Hash of properties (offset, limit, opts, key, col) @param callable $cb Callback called when response received @callback $cb ( ) @return void
[ "Aggregate", "function" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Mongo/Pool.php#L1097-L1141
kakserpom/phpdaemon
PHPDaemon/Clients/Mongo/Pool.php
Pool.update
public function update($col, $cond, $data, $flags = 0, $cb = null, $params = []) { if (mb_orig_strpos($col, '.') === false) { $col = $this->dbname . '.' . $col; } if (is_string($cond)) { $cond = new \MongoCode($cond); } if ($flags) { //if (!isset($data['_id'])) {$data['_id'] = new MongoId();} } if ($this->safeMode) { static::safeModeEnc($cond); static::safeModeEnc($data); } $this->request( self::OP_UPDATE, "\x00\x00\x00\x00" . $col . "\x00" . pack('V', $flags) . bson_encode($cond) . bson_encode($data), false, null, function ($conn, $reqId = null) use ($cb, $col, $params) { if (!$conn) { !$cb || $cb(['$err' => 'Connection error.']); return; } if ($cb !== null) { $this->lastError($col, $cb, $params, $conn); } } ); }
php
public function update($col, $cond, $data, $flags = 0, $cb = null, $params = []) { if (mb_orig_strpos($col, '.') === false) { $col = $this->dbname . '.' . $col; } if (is_string($cond)) { $cond = new \MongoCode($cond); } if ($flags) { //if (!isset($data['_id'])) {$data['_id'] = new MongoId();} } if ($this->safeMode) { static::safeModeEnc($cond); static::safeModeEnc($data); } $this->request( self::OP_UPDATE, "\x00\x00\x00\x00" . $col . "\x00" . pack('V', $flags) . bson_encode($cond) . bson_encode($data), false, null, function ($conn, $reqId = null) use ($cb, $col, $params) { if (!$conn) { !$cb || $cb(['$err' => 'Connection error.']); return; } if ($cb !== null) { $this->lastError($col, $cb, $params, $conn); } } ); }
[ "public", "function", "update", "(", "$", "col", ",", "$", "cond", ",", "$", "data", ",", "$", "flags", "=", "0", ",", "$", "cb", "=", "null", ",", "$", "params", "=", "[", "]", ")", "{", "if", "(", "mb_orig_strpos", "(", "$", "col", ",", "'....
Updates one object in collection @param string $col Collection's name @param array $cond Conditions @param array $data Data @param integer $flags Optional. Flags @param callable $cb Optional. Callback @param array $params Optional. Parameters @callback $cb ( ) @return void
[ "Updates", "one", "object", "in", "collection" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Mongo/Pool.php#L1154-L1187
kakserpom/phpdaemon
PHPDaemon/Clients/Mongo/Pool.php
Pool.updateOne
public function updateOne($col, $cond, $data, $cb = null, $params = []) { $this->update($col, $cond, $data, 0, $cb, $params); }
php
public function updateOne($col, $cond, $data, $cb = null, $params = []) { $this->update($col, $cond, $data, 0, $cb, $params); }
[ "public", "function", "updateOne", "(", "$", "col", ",", "$", "cond", ",", "$", "data", ",", "$", "cb", "=", "null", ",", "$", "params", "=", "[", "]", ")", "{", "$", "this", "->", "update", "(", "$", "col", ",", "$", "cond", ",", "$", "data"...
Updates one object in collection @param string $col Collection's name @param array $cond Conditions @param array $data Data @param callable $cb Optional. Callback @param array $params Optional. Parameters @callback $cb ( ) @return void
[ "Updates", "one", "object", "in", "collection" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Mongo/Pool.php#L1199-L1202
kakserpom/phpdaemon
PHPDaemon/Clients/Mongo/Pool.php
Pool.upsert
public function upsert($col, $cond, $data, $multi = false, $cb = null, $params = []) { $this->update($col, $cond, $data, $multi ? 3 : 1, $cb, $params); }
php
public function upsert($col, $cond, $data, $multi = false, $cb = null, $params = []) { $this->update($col, $cond, $data, $multi ? 3 : 1, $cb, $params); }
[ "public", "function", "upsert", "(", "$", "col", ",", "$", "cond", ",", "$", "data", ",", "$", "multi", "=", "false", ",", "$", "cb", "=", "null", ",", "$", "params", "=", "[", "]", ")", "{", "$", "this", "->", "update", "(", "$", "col", ",",...
Upserts an object (updates if exists, insert if not exists) @param string $col Collection's name @param array $cond Conditions @param array $data Data @param boolean $multi Optional. Multi @param callable $cb Optional. Callback @param array $params Optional. Parameters @callback $cb ( ) @return void
[ "Upserts", "an", "object", "(", "updates", "if", "exists", "insert", "if", "not", "exists", ")" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Mongo/Pool.php#L1230-L1233