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/FS/FileSystem.php
FileSystem.tempnamHandler
protected static function tempnamHandler($dir, $prefix, $cb, &$tries) { $cb = CallbackWrapper::forceWrap($cb); if (++$tries >= 3) { $cb(false); return; } $path = FileSystem::genRndTempnam($dir, $prefix); FileSystem::open($path, 'x+!', function ($file) use ($dir, $prefix, $cb, &$tries) { if (!$file) { static::tempnamHandler($dir, $prefix, $cb, $tries); return; } $cb($file); }); }
php
protected static function tempnamHandler($dir, $prefix, $cb, &$tries) { $cb = CallbackWrapper::forceWrap($cb); if (++$tries >= 3) { $cb(false); return; } $path = FileSystem::genRndTempnam($dir, $prefix); FileSystem::open($path, 'x+!', function ($file) use ($dir, $prefix, $cb, &$tries) { if (!$file) { static::tempnamHandler($dir, $prefix, $cb, $tries); return; } $cb($file); }); }
[ "protected", "static", "function", "tempnamHandler", "(", "$", "dir", ",", "$", "prefix", ",", "$", "cb", ",", "&", "$", "tries", ")", "{", "$", "cb", "=", "CallbackWrapper", "::", "forceWrap", "(", "$", "cb", ")", ";", "if", "(", "++", "$", "tries...
Generates closure tempnam handler @param $dir @param $prefix @param $cb @param $tries
[ "Generates", "closure", "tempnam", "handler" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L615-L630
kakserpom/phpdaemon
PHPDaemon/FS/FileSystem.php
FileSystem.tempnam
public static function tempnam($dir, $prefix, $cb) { $cb = CallbackWrapper::forceWrap($cb); if (!FileSystem::$supported) { FileSystem::open(tempnam($dir, $prefix), 'w!', $cb); } $tries = 0; static::tempnamHandler($dir, $prefix, $cb, $tries); }
php
public static function tempnam($dir, $prefix, $cb) { $cb = CallbackWrapper::forceWrap($cb); if (!FileSystem::$supported) { FileSystem::open(tempnam($dir, $prefix), 'w!', $cb); } $tries = 0; static::tempnamHandler($dir, $prefix, $cb, $tries); }
[ "public", "static", "function", "tempnam", "(", "$", "dir", ",", "$", "prefix", ",", "$", "cb", ")", "{", "$", "cb", "=", "CallbackWrapper", "::", "forceWrap", "(", "$", "cb", ")", ";", "if", "(", "!", "FileSystem", "::", "$", "supported", ")", "{"...
Obtain exclusive temporary file @param string $dir Directory @param string $prefix Prefix @param callable $cb Callback (File) @return resource
[ "Obtain", "exclusive", "temporary", "file" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L639-L647
kakserpom/phpdaemon
PHPDaemon/FS/FileSystem.php
FileSystem.open
public static function open($path, $flags, $cb, $mode = null, $pri = EIO_PRI_DEFAULT) { $cb = CallbackWrapper::forceWrap($cb); if (!FileSystem::$supported) { $mode = File::convertFlags($flags, true); $fd = fopen($path, $mode); if (!$fd) { $cb(false); return false; } $file = new File($fd, $path); $cb($file); return true; } $fdCacheKey = $path . "\x00" . $flags; $noncache = mb_orig_strpos($flags, '!') !== false; $flags = File::convertFlags($flags); if (!$noncache && ($item = FileSystem::$fdCache->get($fdCacheKey))) { // cache hit $file = $item->getValue(); if ($file === null) { // operation in progress $item->addListener($cb); } else { // hit $cb($file); } return null; } elseif (!$noncache) { $item = FileSystem::$fdCache->put($fdCacheKey, null); $item->addListener($cb); } return eio_open($path, $flags, $mode, $pri, function ($path, $fd) use ($cb, $flags, $fdCacheKey, $noncache) { if ($fd === -1) { if ($noncache) { $cb(false); } else { FileSystem::$fdCache->put($fdCacheKey, false, self::$badFDttl); } return; } $file = new File($fd, $path); $file->append = ($flags | EIO_O_APPEND) === $flags; if ($file->append) { $file->stat(function ($file, $stat) use ($cb, $noncache, $fdCacheKey) { $file->offset = $stat['size']; if (!$noncache) { $file->fdCacheKey = $fdCacheKey; FileSystem::$fdCache->put($fdCacheKey, $file); } else { $cb($file); } }); } else { if (!$noncache) { $file->fdCacheKey = $fdCacheKey; FileSystem::$fdCache->put($fdCacheKey, $file); } else { $cb($file); } } }, $path); }
php
public static function open($path, $flags, $cb, $mode = null, $pri = EIO_PRI_DEFAULT) { $cb = CallbackWrapper::forceWrap($cb); if (!FileSystem::$supported) { $mode = File::convertFlags($flags, true); $fd = fopen($path, $mode); if (!$fd) { $cb(false); return false; } $file = new File($fd, $path); $cb($file); return true; } $fdCacheKey = $path . "\x00" . $flags; $noncache = mb_orig_strpos($flags, '!') !== false; $flags = File::convertFlags($flags); if (!$noncache && ($item = FileSystem::$fdCache->get($fdCacheKey))) { // cache hit $file = $item->getValue(); if ($file === null) { // operation in progress $item->addListener($cb); } else { // hit $cb($file); } return null; } elseif (!$noncache) { $item = FileSystem::$fdCache->put($fdCacheKey, null); $item->addListener($cb); } return eio_open($path, $flags, $mode, $pri, function ($path, $fd) use ($cb, $flags, $fdCacheKey, $noncache) { if ($fd === -1) { if ($noncache) { $cb(false); } else { FileSystem::$fdCache->put($fdCacheKey, false, self::$badFDttl); } return; } $file = new File($fd, $path); $file->append = ($flags | EIO_O_APPEND) === $flags; if ($file->append) { $file->stat(function ($file, $stat) use ($cb, $noncache, $fdCacheKey) { $file->offset = $stat['size']; if (!$noncache) { $file->fdCacheKey = $fdCacheKey; FileSystem::$fdCache->put($fdCacheKey, $file); } else { $cb($file); } }); } else { if (!$noncache) { $file->fdCacheKey = $fdCacheKey; FileSystem::$fdCache->put($fdCacheKey, $file); } else { $cb($file); } } }, $path); }
[ "public", "static", "function", "open", "(", "$", "path", ",", "$", "flags", ",", "$", "cb", ",", "$", "mode", "=", "null", ",", "$", "pri", "=", "EIO_PRI_DEFAULT", ")", "{", "$", "cb", "=", "CallbackWrapper", "::", "forceWrap", "(", "$", "cb", ")"...
Open file @param string $path Path @param string $flags Flags @param callable $cb Callback (File) @param integer $mode Mode (see EIO_S_I* constants) @param integer $pri Priority @return resource
[ "Open", "file" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L658-L717
kakserpom/phpdaemon
PHPDaemon/Core/CallbackWrapper.php
CallbackWrapper.wrap
public static function wrap($cb, $timeout = null, $ctx = false) { if ($cb instanceof CallbackWrapper || ((Daemon::$context === null) && ($timeout === null))) { return $cb; } if ($cb === null) { return null; } return new static($cb, $timeout, $ctx !== false ? $ctx : Daemon::$context); }
php
public static function wrap($cb, $timeout = null, $ctx = false) { if ($cb instanceof CallbackWrapper || ((Daemon::$context === null) && ($timeout === null))) { return $cb; } if ($cb === null) { return null; } return new static($cb, $timeout, $ctx !== false ? $ctx : Daemon::$context); }
[ "public", "static", "function", "wrap", "(", "$", "cb", ",", "$", "timeout", "=", "null", ",", "$", "ctx", "=", "false", ")", "{", "if", "(", "$", "cb", "instanceof", "CallbackWrapper", "||", "(", "(", "Daemon", "::", "$", "context", "===", "null", ...
Wraps callback @static @param callable $cb @param double $timeout = null @return \Closure
[ "Wraps", "callback" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/CallbackWrapper.php#L108-L117
kakserpom/phpdaemon
PHPDaemon/Core/CallbackWrapper.php
CallbackWrapper.forceWrap
public static function forceWrap($cb, $timeout = null) { if ($cb instanceof CallbackWrapper) { return $cb; } if ($cb === null) { return null; } return new static($cb, $timeout, Daemon::$context); }
php
public static function forceWrap($cb, $timeout = null) { if ($cb instanceof CallbackWrapper) { return $cb; } if ($cb === null) { return null; } return new static($cb, $timeout, Daemon::$context); }
[ "public", "static", "function", "forceWrap", "(", "$", "cb", ",", "$", "timeout", "=", "null", ")", "{", "if", "(", "$", "cb", "instanceof", "CallbackWrapper", ")", "{", "return", "$", "cb", ";", "}", "if", "(", "$", "cb", "===", "null", ")", "{", ...
Wraps callback even without context @static @param callable $cb @param double $timeout = null @return CallbackWrapper|null
[ "Wraps", "callback", "even", "without", "context" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/CallbackWrapper.php#L126-L135
kakserpom/phpdaemon
PHPDaemon/Core/CallbackWrapper.php
CallbackWrapper.cancel
public function cancel() { $this->cb = null; $this->context = null; if ($this->timer !== null) { Timer::remove($this->timer); $this->timer = null; } }
php
public function cancel() { $this->cb = null; $this->context = null; if ($this->timer !== null) { Timer::remove($this->timer); $this->timer = null; } }
[ "public", "function", "cancel", "(", ")", "{", "$", "this", "->", "cb", "=", "null", ";", "$", "this", "->", "context", "=", "null", ";", "if", "(", "$", "this", "->", "timer", "!==", "null", ")", "{", "Timer", "::", "remove", "(", "$", "this", ...
Cancel @return void
[ "Cancel" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/CallbackWrapper.php#L149-L157
kakserpom/phpdaemon
PHPDaemon/Examples/ExampleWithMongo.php
ExampleWithMongoRequest.init
public function init() { $job = $this->job = new \PHPDaemon\Core\ComplexJob(function ($job) { // called when job is done $job->keep(); // prevent cleaning up results $this->wakeup(); // wake up the request immediately }); $collection = $this->appInstance->mongo->{'testdb.testcollection'}; $collection->insert(['a' => microtime(true)]); // just pushing something $job('testquery', function ($name, $job) use ($collection) { // registering job named 'testquery' $collection->findOne(function ($result) use ($name, $job) { // calling Mongo findOne $job->setResult($name, $result); }, ['sort' => ['$natural' => -1]]); }); $job(); // let the fun begin $this->sleep(1, true); // setting timeout }
php
public function init() { $job = $this->job = new \PHPDaemon\Core\ComplexJob(function ($job) { // called when job is done $job->keep(); // prevent cleaning up results $this->wakeup(); // wake up the request immediately }); $collection = $this->appInstance->mongo->{'testdb.testcollection'}; $collection->insert(['a' => microtime(true)]); // just pushing something $job('testquery', function ($name, $job) use ($collection) { // registering job named 'testquery' $collection->findOne(function ($result) use ($name, $job) { // calling Mongo findOne $job->setResult($name, $result); }, ['sort' => ['$natural' => -1]]); }); $job(); // let the fun begin $this->sleep(1, true); // setting timeout }
[ "public", "function", "init", "(", ")", "{", "$", "job", "=", "$", "this", "->", "job", "=", "new", "\\", "PHPDaemon", "\\", "Core", "\\", "ComplexJob", "(", "function", "(", "$", "job", ")", "{", "// called when job is done", "$", "job", "->", "keep",...
Constructor. @return void
[ "Constructor", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Examples/ExampleWithMongo.php#L44-L67
kakserpom/phpdaemon
PHPDaemon/Examples/ExampleWithMongo.php
ExampleWithMongoRequest.run
public function run() { try { $this->header('Content-Type: text/html'); } catch (\Exception $e) { } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Example with Mongo</title> </head> <body> <?php if ($r = $this->job->getResult('testquery')) { echo '<h1>It works! Be happy! ;-)</h1>Result of query: <pre>'; var_dump($r); echo '</pre>'; } else { echo '<h1>Something went wrong! We have no result.</h1>'; } echo '<br />Request (http) took: ' . round(microtime(true) - $this->attrs->server['REQUEST_TIME_FLOAT'], 6); ?> </body> </html> <?php }
php
public function run() { try { $this->header('Content-Type: text/html'); } catch (\Exception $e) { } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Example with Mongo</title> </head> <body> <?php if ($r = $this->job->getResult('testquery')) { echo '<h1>It works! Be happy! ;-)</h1>Result of query: <pre>'; var_dump($r); echo '</pre>'; } else { echo '<h1>Something went wrong! We have no result.</h1>'; } echo '<br />Request (http) took: ' . round(microtime(true) - $this->attrs->server['REQUEST_TIME_FLOAT'], 6); ?> </body> </html> <?php }
[ "public", "function", "run", "(", ")", "{", "try", "{", "$", "this", "->", "header", "(", "'Content-Type: text/html'", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "}", "?>\n <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional/...
Called when request iterated. @return integer Status.
[ "Called", "when", "request", "iterated", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Examples/ExampleWithMongo.php#L73-L102
kakserpom/phpdaemon
PHPDaemon/Clients/ICMP/Pool.php
Pool.sendPing
public function sendPing($host, $cb) { $this->connect('raw://' . $host, function ($conn) use ($cb) { $conn->sendEcho($cb); }); }
php
public function sendPing($host, $cb) { $this->connect('raw://' . $host, function ($conn) use ($cb) { $conn->sendEcho($cb); }); }
[ "public", "function", "sendPing", "(", "$", "host", ",", "$", "cb", ")", "{", "$", "this", "->", "connect", "(", "'raw://'", ".", "$", "host", ",", "function", "(", "$", "conn", ")", "use", "(", "$", "cb", ")", "{", "$", "conn", "->", "sendEcho",...
Establishes connection @param string $host Address @param callable $cb Callback @callback $cb ( )
[ "Establishes", "connection" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/ICMP/Pool.php#L20-L25
kakserpom/phpdaemon
PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Exchange/ExchangeBindFrame.php
ExchangeBindFrame.create
public static function create( $destination = null, $source = null, $routingKey = null, $nowait = null, $arguments = null ) { $frame = new self(); if (null !== $destination) { $frame->destination = $destination; } if (null !== $source) { $frame->source = $source; } if (null !== $routingKey) { $frame->routingKey = $routingKey; } if (null !== $nowait) { $frame->nowait = $nowait; } if (null !== $arguments) { $frame->arguments = $arguments; } return $frame; }
php
public static function create( $destination = null, $source = null, $routingKey = null, $nowait = null, $arguments = null ) { $frame = new self(); if (null !== $destination) { $frame->destination = $destination; } if (null !== $source) { $frame->source = $source; } if (null !== $routingKey) { $frame->routingKey = $routingKey; } if (null !== $nowait) { $frame->nowait = $nowait; } if (null !== $arguments) { $frame->arguments = $arguments; } return $frame; }
[ "public", "static", "function", "create", "(", "$", "destination", "=", "null", ",", "$", "source", "=", "null", ",", "$", "routingKey", "=", "null", ",", "$", "nowait", "=", "null", ",", "$", "arguments", "=", "null", ")", "{", "$", "frame", "=", ...
table
[ "table" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Exchange/ExchangeBindFrame.php#L25-L48
kakserpom/phpdaemon
PHPDaemon/Clients/Gibson/Connection.php
Connection.onRead
protected function onRead() { start: if ($this->state === static::STATE_STANDBY) { if (($hdr = $this->readExact(2)) === false) { return; // not enough data } $u = unpack('S', $hdr); $this->responseCode = $u[1]; $this->state = static::STATE_PACKET_HDR; } if ($this->state === static::STATE_PACKET_HDR) { if ($this->responseCode === static::REPL_KVAL) { $this->result = []; if (($hdr = $this->readExact(9)) === false) { return; // not enough data } $this->encoding = Binary::getByte($hdr); $this->responseLength = Binary::getDword($hdr, true) - 4; $this->totalNum = Binary::getDword($hdr, true); $this->readedNum = 0; $this->state = static::STATE_PACKET_DATA; } else { if (($hdr = $this->lookExact(5)) === false) { return; // not enough data } $this->encoding = Binary::getByte($hdr); $pl = Binary::getDword($hdr, true); if ($this->getInputLength() < 5 + $pl) { return; // not enough data } $this->drain(5); $this->responseLength = $pl; if ($this->responseLength > $this->pool->maxAllowedPacket) { $this->log('max-allowed-packet (' . $this->pool->config->maxallowedpacket->getHumanValue() . ') exceed, aborting connection'); $this->finish(); return; } if ($this->responseCode === static::REPL_ERR_NOT_FOUND) { $this->drain($this->responseLength); $this->result = null; $this->isFinal = true; $this->totalNum = 0; $this->readedNum = 0; $this->executeCb(); } elseif ($this->responseCode === static::REPL_OK) { $this->drain($this->responseLength); $this->result = true; $this->isFinal = true; $this->totalNum = 0; $this->readedNum = 0; $this->executeCb(); } elseif (($this->responseCode === static::REPL_ERR_MEM) || ($this->responseCode === static::REPL_ERR_NAN) || ($this->responseCode === static::REPL_ERR_LOCKED) ) { $this->drain($this->responseLength); $this->result = false; $this->isFinal = true; $this->totalNum = 0; $this->readedNum = 0; $this->executeCb(); } else { if ($this->responseCode === static::REPL_KVAL && $this->totalNum <= 0) { $this->drain($this->responseLength); $this->isFinal = true; $this->totalNum = 0; $this->readedNum = 0; $this->result = []; $this->executeCb(); } else { $this->state = static::STATE_PACKET_DATA; } } } } if ($this->state === static::STATE_PACKET_DATA) { if ($this->responseCode === static::REPL_KVAL) { $keyAdded = false; nextElement: $l = $this->getInputLength(); if ($l < 9) { goto cursorCall; } if (($hdr = $this->lookExact($o = 4)) === false) { goto cursorCall; } $keyLen = Binary::getDword($hdr, true); if (($key = $this->lookExact($keyLen, $o)) === false) { goto cursorCall; } $o += $keyLen; if (($encoding = $this->lookExact(1, $o)) === false) { goto cursorCall; } $encoding = ord($encoding); ++$o; if (($hdr = $this->lookExact(4, $o)) === false) { goto cursorCall; } $o += 4; $valLen = Binary::getDword($hdr, true); if ($o + $valLen > $l) { goto cursorCall; } $this->drain($o); if ($encoding === static::GB_ENC_NUMBER) { $val = $this->read($valLen); $this->result[$key] = $valLen === 8 ? Binary::getQword($val, true) : Binary::getDword($val, true); } else { $this->result[$key] = $this->read($valLen); } $keyAdded = true; if (++$this->readedNum >= $this->totalNum) { $this->isFinal = true; $this->executeCb(); goto start; } else { goto nextElement; } cursorCall: if ($keyAdded) { $this->onResponse->executeAndKeepOne($this); } return; } else { if (($this->result = $this->readExact($this->responseLength)) === false) { $this->setWatermark($this->responseLength); return; } $this->setWatermark(2, $this->pool->maxAllowedPacket); if ($this->encoding === static::GB_ENC_NUMBER) { $this->result = $this->responseLength === 8 ? Binary::getQword($this->result, true) : Binary::getDword($this->result, true); } $this->isFinal = true; $this->totalNum = 1; $this->readedNum = 1; $this->executeCb(); } } goto start; }
php
protected function onRead() { start: if ($this->state === static::STATE_STANDBY) { if (($hdr = $this->readExact(2)) === false) { return; // not enough data } $u = unpack('S', $hdr); $this->responseCode = $u[1]; $this->state = static::STATE_PACKET_HDR; } if ($this->state === static::STATE_PACKET_HDR) { if ($this->responseCode === static::REPL_KVAL) { $this->result = []; if (($hdr = $this->readExact(9)) === false) { return; // not enough data } $this->encoding = Binary::getByte($hdr); $this->responseLength = Binary::getDword($hdr, true) - 4; $this->totalNum = Binary::getDword($hdr, true); $this->readedNum = 0; $this->state = static::STATE_PACKET_DATA; } else { if (($hdr = $this->lookExact(5)) === false) { return; // not enough data } $this->encoding = Binary::getByte($hdr); $pl = Binary::getDword($hdr, true); if ($this->getInputLength() < 5 + $pl) { return; // not enough data } $this->drain(5); $this->responseLength = $pl; if ($this->responseLength > $this->pool->maxAllowedPacket) { $this->log('max-allowed-packet (' . $this->pool->config->maxallowedpacket->getHumanValue() . ') exceed, aborting connection'); $this->finish(); return; } if ($this->responseCode === static::REPL_ERR_NOT_FOUND) { $this->drain($this->responseLength); $this->result = null; $this->isFinal = true; $this->totalNum = 0; $this->readedNum = 0; $this->executeCb(); } elseif ($this->responseCode === static::REPL_OK) { $this->drain($this->responseLength); $this->result = true; $this->isFinal = true; $this->totalNum = 0; $this->readedNum = 0; $this->executeCb(); } elseif (($this->responseCode === static::REPL_ERR_MEM) || ($this->responseCode === static::REPL_ERR_NAN) || ($this->responseCode === static::REPL_ERR_LOCKED) ) { $this->drain($this->responseLength); $this->result = false; $this->isFinal = true; $this->totalNum = 0; $this->readedNum = 0; $this->executeCb(); } else { if ($this->responseCode === static::REPL_KVAL && $this->totalNum <= 0) { $this->drain($this->responseLength); $this->isFinal = true; $this->totalNum = 0; $this->readedNum = 0; $this->result = []; $this->executeCb(); } else { $this->state = static::STATE_PACKET_DATA; } } } } if ($this->state === static::STATE_PACKET_DATA) { if ($this->responseCode === static::REPL_KVAL) { $keyAdded = false; nextElement: $l = $this->getInputLength(); if ($l < 9) { goto cursorCall; } if (($hdr = $this->lookExact($o = 4)) === false) { goto cursorCall; } $keyLen = Binary::getDword($hdr, true); if (($key = $this->lookExact($keyLen, $o)) === false) { goto cursorCall; } $o += $keyLen; if (($encoding = $this->lookExact(1, $o)) === false) { goto cursorCall; } $encoding = ord($encoding); ++$o; if (($hdr = $this->lookExact(4, $o)) === false) { goto cursorCall; } $o += 4; $valLen = Binary::getDword($hdr, true); if ($o + $valLen > $l) { goto cursorCall; } $this->drain($o); if ($encoding === static::GB_ENC_NUMBER) { $val = $this->read($valLen); $this->result[$key] = $valLen === 8 ? Binary::getQword($val, true) : Binary::getDword($val, true); } else { $this->result[$key] = $this->read($valLen); } $keyAdded = true; if (++$this->readedNum >= $this->totalNum) { $this->isFinal = true; $this->executeCb(); goto start; } else { goto nextElement; } cursorCall: if ($keyAdded) { $this->onResponse->executeAndKeepOne($this); } return; } else { if (($this->result = $this->readExact($this->responseLength)) === false) { $this->setWatermark($this->responseLength); return; } $this->setWatermark(2, $this->pool->maxAllowedPacket); if ($this->encoding === static::GB_ENC_NUMBER) { $this->result = $this->responseLength === 8 ? Binary::getQword($this->result, true) : Binary::getDword($this->result, true); } $this->isFinal = true; $this->totalNum = 1; $this->readedNum = 1; $this->executeCb(); } } goto start; }
[ "protected", "function", "onRead", "(", ")", "{", "start", ":", "if", "(", "$", "this", "->", "state", "===", "static", "::", "STATE_STANDBY", ")", "{", "if", "(", "(", "$", "hdr", "=", "$", "this", "->", "readExact", "(", "2", ")", ")", "===", "...
onRead @return void
[ "onRead" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Gibson/Connection.php#L125-L271
kakserpom/phpdaemon
PHPDaemon/Core/AppResolver.php
AppResolver.preload
public function preload($privileged = false) { foreach (Daemon::$config as $fullname => $section) { if (!$section instanceof Config\Section) { continue; } if (isset($section->limitinstances)) { continue; } if ((isset($section->enable) && $section->enable->value) || (!isset($section->enable) && !isset($section->disable)) ) { if (mb_orig_strpos($fullname, ':') === false) { $fullname .= ':'; } list($appName, $instance) = explode(':', $fullname, 2); $appNameLower = strtolower($appName); if ($appNameLower !== 'pool' && $privileged && (!isset($section->privileged) || !$section->privileged->value)) { continue; } if (isset(Daemon::$appInstances[$appNameLower][$instance])) { continue; } $this->getInstance($appName, $instance, true, true); } } }
php
public function preload($privileged = false) { foreach (Daemon::$config as $fullname => $section) { if (!$section instanceof Config\Section) { continue; } if (isset($section->limitinstances)) { continue; } if ((isset($section->enable) && $section->enable->value) || (!isset($section->enable) && !isset($section->disable)) ) { if (mb_orig_strpos($fullname, ':') === false) { $fullname .= ':'; } list($appName, $instance) = explode(':', $fullname, 2); $appNameLower = strtolower($appName); if ($appNameLower !== 'pool' && $privileged && (!isset($section->privileged) || !$section->privileged->value)) { continue; } if (isset(Daemon::$appInstances[$appNameLower][$instance])) { continue; } $this->getInstance($appName, $instance, true, true); } } }
[ "public", "function", "preload", "(", "$", "privileged", "=", "false", ")", "{", "foreach", "(", "Daemon", "::", "$", "config", "as", "$", "fullname", "=>", "$", "section", ")", "{", "if", "(", "!", "$", "section", "instanceof", "Config", "\\", "Sectio...
Preloads applications @param boolean $privileged If true, we are in the pre-fork stage @return void
[ "Preloads", "applications" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/AppResolver.php#L21-L47
kakserpom/phpdaemon
PHPDaemon/Core/AppResolver.php
AppResolver.getInstance
public function getInstance($appName, $instance = '', $spawn = true, $preload = false) { $class = ClassFinder::find($appName, 'Applications'); if (isset(Daemon::$appInstances[$class][$instance])) { return Daemon::$appInstances[$class][$instance]; } if (!$spawn) { return false; } $fullname = $this->getAppFullName($appName, $instance); if (!class_exists($class)) { Daemon::$process->log(__METHOD__ . ': unable to find application class ' . json_encode($class) . '\''); return false; } if (!is_subclass_of($class, '\\PHPDaemon\\Core\\AppInstance')) { Daemon::$process->log(__METHOD__ . ': class ' . json_encode($class) . '\' found, but skipped as long as it is not subclass of \\PHPDaemon\\Core\\AppInstance'); return false; } $fullnameClass = $this->getAppFullName($class, $instance); if ($fullname !== $fullnameClass && isset(Daemon::$config->{$fullname})) { Daemon::$config->renameSection($fullname, $fullnameClass); } if (!$preload) { /** @noinspection PhpUndefinedVariableInspection */ if (!$class::$runOnDemand) { return false; } if (isset(Daemon::$config->{$fullnameClass}->limitinstances)) { return false; } } return new $class($instance); }
php
public function getInstance($appName, $instance = '', $spawn = true, $preload = false) { $class = ClassFinder::find($appName, 'Applications'); if (isset(Daemon::$appInstances[$class][$instance])) { return Daemon::$appInstances[$class][$instance]; } if (!$spawn) { return false; } $fullname = $this->getAppFullName($appName, $instance); if (!class_exists($class)) { Daemon::$process->log(__METHOD__ . ': unable to find application class ' . json_encode($class) . '\''); return false; } if (!is_subclass_of($class, '\\PHPDaemon\\Core\\AppInstance')) { Daemon::$process->log(__METHOD__ . ': class ' . json_encode($class) . '\' found, but skipped as long as it is not subclass of \\PHPDaemon\\Core\\AppInstance'); return false; } $fullnameClass = $this->getAppFullName($class, $instance); if ($fullname !== $fullnameClass && isset(Daemon::$config->{$fullname})) { Daemon::$config->renameSection($fullname, $fullnameClass); } if (!$preload) { /** @noinspection PhpUndefinedVariableInspection */ if (!$class::$runOnDemand) { return false; } if (isset(Daemon::$config->{$fullnameClass}->limitinstances)) { return false; } } return new $class($instance); }
[ "public", "function", "getInstance", "(", "$", "appName", ",", "$", "instance", "=", "''", ",", "$", "spawn", "=", "true", ",", "$", "preload", "=", "false", ")", "{", "$", "class", "=", "ClassFinder", "::", "find", "(", "$", "appName", ",", "'Applic...
Gets instance of application @param string $appName Application name @param string $instance Instance name @param boolean $spawn If true, we spawn an instance if absent @param boolean $preload If true, worker is at the preload stage @return object $instance AppInstance
[ "Gets", "instance", "of", "application" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/AppResolver.php#L57-L90
kakserpom/phpdaemon
PHPDaemon/Core/AppResolver.php
AppResolver.getRequest
public function getRequest($req, $upstream, $responder = null) { if (isset($req->attrs->server['APPNAME'])) { $appName = $req->attrs->server['APPNAME']; } elseif ($responder !== null) { $appName = $responder; } elseif (($appName = $this->getRequestRoute($req, $upstream)) !== null) { if ($appName === false) { return $req; } } else { return $req; } if (mb_orig_strpos($appName, ':') === false) { $appName .= ':'; } list($app, $instance) = explode(':', $appName, 2); $appInstance = $this->getInstanceByAppName($app, $instance); if (!$appInstance) { return $req; } return $appInstance->handleRequest($req, $upstream); }
php
public function getRequest($req, $upstream, $responder = null) { if (isset($req->attrs->server['APPNAME'])) { $appName = $req->attrs->server['APPNAME']; } elseif ($responder !== null) { $appName = $responder; } elseif (($appName = $this->getRequestRoute($req, $upstream)) !== null) { if ($appName === false) { return $req; } } else { return $req; } if (mb_orig_strpos($appName, ':') === false) { $appName .= ':'; } list($app, $instance) = explode(':', $appName, 2); $appInstance = $this->getInstanceByAppName($app, $instance); if (!$appInstance) { return $req; } return $appInstance->handleRequest($req, $upstream); }
[ "public", "function", "getRequest", "(", "$", "req", ",", "$", "upstream", ",", "$", "responder", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "req", "->", "attrs", "->", "server", "[", "'APPNAME'", "]", ")", ")", "{", "$", "appName", "=", ...
Routes incoming request to related application @param object $req Generic @param object $upstream AppInstance of Upstream @param string $responder @return object Request
[ "Routes", "incoming", "request", "to", "related", "application" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/AppResolver.php#L110-L135
kakserpom/phpdaemon
PHPDaemon/Core/AppResolver.php
AppResolver.getInstanceByAppName
public function getInstanceByAppName($appName, $instance = '', $spawn = true, $preload = false) { return $this->getInstance($appName, $instance, $spawn, $preload); }
php
public function getInstanceByAppName($appName, $instance = '', $spawn = true, $preload = false) { return $this->getInstance($appName, $instance, $spawn, $preload); }
[ "public", "function", "getInstanceByAppName", "(", "$", "appName", ",", "$", "instance", "=", "''", ",", "$", "spawn", "=", "true", ",", "$", "preload", "=", "false", ")", "{", "return", "$", "this", "->", "getInstance", "(", "$", "appName", ",", "$", ...
Gets instance of application @alias AppResolver::getInstance @param string $appName Application name @param string $instance Instance name @param boolean $spawn If true, we spawn an instance if absent @param boolean $preload If true, worker is at the preload stage @return object AppInstance
[ "Gets", "instance", "of", "application" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/AppResolver.php#L156-L159
kakserpom/phpdaemon
PHPDaemon/Config/Entry/Generic.php
Generic.setHumanValue
public function setHumanValue($value) { $this->humanValue = $value; $old = $this->value; $this->value = static::humanToPlain($value); $this->onUpdate($old); }
php
public function setHumanValue($value) { $this->humanValue = $value; $old = $this->value; $this->value = static::humanToPlain($value); $this->onUpdate($old); }
[ "public", "function", "setHumanValue", "(", "$", "value", ")", "{", "$", "this", "->", "humanValue", "=", "$", "value", ";", "$", "old", "=", "$", "this", "->", "value", ";", "$", "this", "->", "value", "=", "static", "::", "humanToPlain", "(", "$", ...
Set human-readable value @param mixed @return void
[ "Set", "human", "-", "readable", "value" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Config/Entry/Generic.php#L81-L87
kakserpom/phpdaemon
PHPDaemon/Config/Entry/Generic.php
Generic.setValue
public function setValue($value) { $old = $this->value; $this->value = $value; $this->humanValue = static::plainToHuman($value); $this->onUpdate($old); }
php
public function setValue($value) { $old = $this->value; $this->value = $value; $this->humanValue = static::plainToHuman($value); $this->onUpdate($old); }
[ "public", "function", "setValue", "(", "$", "value", ")", "{", "$", "old", "=", "$", "this", "->", "value", ";", "$", "this", "->", "value", "=", "$", "value", ";", "$", "this", "->", "humanValue", "=", "static", "::", "plainToHuman", "(", "$", "va...
Set value @param mixed @return void
[ "Set", "value" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Config/Entry/Generic.php#L103-L109
kakserpom/phpdaemon
PHPDaemon/Config/Entry/Generic.php
Generic.pushValue
public function pushValue($value) { $old = $this->value; if (!$this->stackable) { $this->setValue($value); return; } if (!is_array($this->value)) { $this->value = [$this->value, $value]; } else { $f = false; foreach ($this->value as $k => $v) { if (!is_int($k)) { $f = true; break; } } if (!$f) { $this->value[] = $value; } else { $this->value = [$this->value, $value]; } } $this->onUpdate($old); }
php
public function pushValue($value) { $old = $this->value; if (!$this->stackable) { $this->setValue($value); return; } if (!is_array($this->value)) { $this->value = [$this->value, $value]; } else { $f = false; foreach ($this->value as $k => $v) { if (!is_int($k)) { $f = true; break; } } if (!$f) { $this->value[] = $value; } else { $this->value = [$this->value, $value]; } } $this->onUpdate($old); }
[ "public", "function", "pushValue", "(", "$", "value", ")", "{", "$", "old", "=", "$", "this", "->", "value", ";", "if", "(", "!", "$", "this", "->", "stackable", ")", "{", "$", "this", "->", "setValue", "(", "$", "value", ")", ";", "return", ";",...
Push plain value @param $value @return void
[ "Push", "plain", "value" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Config/Entry/Generic.php#L142-L166
kakserpom/phpdaemon
PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Parser/Table.php
Table.parseTable
private function parseTable() { $length = $this->parseUnsignedInt32(); $stopAt = strlen($this->buffer) - $length; $table = []; while (strlen($this->buffer) > $stopAt) { $table[$this->parseShortString()] = $this->parseField(); } return $table; }
php
private function parseTable() { $length = $this->parseUnsignedInt32(); $stopAt = strlen($this->buffer) - $length; $table = []; while (strlen($this->buffer) > $stopAt) { $table[$this->parseShortString()] = $this->parseField(); } return $table; }
[ "private", "function", "parseTable", "(", ")", "{", "$", "length", "=", "$", "this", "->", "parseUnsignedInt32", "(", ")", ";", "$", "stopAt", "=", "strlen", "(", "$", "this", "->", "buffer", ")", "-", "$", "length", ";", "$", "table", "=", "[", "]...
Parse an AMQP table from the head of the buffer. @return array @throws \PHPDaemon\Clients\AMQP\Driver\Protocol\Exception\AMQPProtocolException
[ "Parse", "an", "AMQP", "table", "from", "the", "head", "of", "the", "buffer", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Parser/Table.php#L52-L63
kakserpom/phpdaemon
PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Parser/Table.php
Table.parseField
private function parseField() { $type = $this->buffer[0]; $this->buffer = substr($this->buffer, 1); // @todo bench switch vs if vs method map switch ($type) { case 's': return $this->parseSignedInt16(); case 'l': return $this->parseSignedInt64(); case 'x': return $this->parseByteArray(); case 't': return $this->parseUnsignedInt8() !== 0; case 'b': return $this->parseSignedInt8(); case 'I': return $this->parseSignedInt32(); case 'f': return $this->parseFloat(); case 'd': return $this->parseDouble(); case 'D': return $this->parseDecimal(); case 'S': return $this->parseLongString(); case 'A': return $this->parseArray(); case 'T': return $this->parseUnsignedInt64(); case 'F': return $this->parseTable(); case 'V': return null; } throw new AMQPProtocolException( sprintf( 'table value type (0x%02x) is invalid or unrecognised.', ord($type) ) ); }
php
private function parseField() { $type = $this->buffer[0]; $this->buffer = substr($this->buffer, 1); // @todo bench switch vs if vs method map switch ($type) { case 's': return $this->parseSignedInt16(); case 'l': return $this->parseSignedInt64(); case 'x': return $this->parseByteArray(); case 't': return $this->parseUnsignedInt8() !== 0; case 'b': return $this->parseSignedInt8(); case 'I': return $this->parseSignedInt32(); case 'f': return $this->parseFloat(); case 'd': return $this->parseDouble(); case 'D': return $this->parseDecimal(); case 'S': return $this->parseLongString(); case 'A': return $this->parseArray(); case 'T': return $this->parseUnsignedInt64(); case 'F': return $this->parseTable(); case 'V': return null; } throw new AMQPProtocolException( sprintf( 'table value type (0x%02x) is invalid or unrecognised.', ord($type) ) ); }
[ "private", "function", "parseField", "(", ")", "{", "$", "type", "=", "$", "this", "->", "buffer", "[", "0", "]", ";", "$", "this", "->", "buffer", "=", "substr", "(", "$", "this", "->", "buffer", ",", "1", ")", ";", "// @todo bench switch vs if vs met...
Parse a table or array field. @return integer|array|boolean|double|string|null @throws AMQPProtocolException
[ "Parse", "a", "table", "or", "array", "field", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Parser/Table.php#L71-L114
kakserpom/phpdaemon
PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Parser/Table.php
Table.parseDecimal
public function parseDecimal() { $scale = $this->parseUnsignedInt8(); $value = $this->parseSignedInt32(); if (0 === $scale) { return (string)$value; } if ($value >= 0) { $sign = ''; $value = (string)$value; } else { $sign = '-'; $value = (string)-$value; } $length = strlen($value); if ($length === $scale) { return $sign . '0.' . $value; } if ($length < $scale) { return $sign . '0.' . str_repeat('0', $scale - $length) . $value; } return $sign . substr($value, 0, -$scale) . '.' . substr($value, -$scale); }
php
public function parseDecimal() { $scale = $this->parseUnsignedInt8(); $value = $this->parseSignedInt32(); if (0 === $scale) { return (string)$value; } if ($value >= 0) { $sign = ''; $value = (string)$value; } else { $sign = '-'; $value = (string)-$value; } $length = strlen($value); if ($length === $scale) { return $sign . '0.' . $value; } if ($length < $scale) { return $sign . '0.' . str_repeat('0', $scale - $length) . $value; } return $sign . substr($value, 0, -$scale) . '.' . substr($value, -$scale); }
[ "public", "function", "parseDecimal", "(", ")", "{", "$", "scale", "=", "$", "this", "->", "parseUnsignedInt8", "(", ")", ";", "$", "value", "=", "$", "this", "->", "parseSignedInt32", "(", ")", ";", "if", "(", "0", "===", "$", "scale", ")", "{", "...
Parse an AMQP decimal from the head of the buffer. @return string
[ "Parse", "an", "AMQP", "decimal", "from", "the", "head", "of", "the", "buffer", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Parser/Table.php#L120-L148
kakserpom/phpdaemon
PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Parser/Table.php
Table.parseArray
private function parseArray() { $length = $this->parseUnsignedInt32(); $stopAt = strlen($this->buffer) - $length; $array = []; while (strlen($this->buffer) > $stopAt) { $array[] = $this->parseField(); } return $array; }
php
private function parseArray() { $length = $this->parseUnsignedInt32(); $stopAt = strlen($this->buffer) - $length; $array = []; while (strlen($this->buffer) > $stopAt) { $array[] = $this->parseField(); } return $array; }
[ "private", "function", "parseArray", "(", ")", "{", "$", "length", "=", "$", "this", "->", "parseUnsignedInt32", "(", ")", ";", "$", "stopAt", "=", "strlen", "(", "$", "this", "->", "buffer", ")", "-", "$", "length", ";", "$", "array", "=", "[", "]...
Parse an AMQP field-array value. @return array @throws \PHPDaemon\Clients\AMQP\Driver\Protocol\Exception\AMQPProtocolException
[ "Parse", "an", "AMQP", "field", "-", "array", "value", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Parser/Table.php#L155-L166
kakserpom/phpdaemon
PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Parser/Table.php
Table.parseByteArray
private function parseByteArray() { list(, $length) = unpack('N', $this->buffer); try { return substr($this->buffer, 4, $length); } finally { $this->buffer = substr($this->buffer, $length + 4); } }
php
private function parseByteArray() { list(, $length) = unpack('N', $this->buffer); try { return substr($this->buffer, 4, $length); } finally { $this->buffer = substr($this->buffer, $length + 4); } }
[ "private", "function", "parseByteArray", "(", ")", "{", "list", "(", ",", "$", "length", ")", "=", "unpack", "(", "'N'", ",", "$", "this", "->", "buffer", ")", ";", "try", "{", "return", "substr", "(", "$", "this", "->", "buffer", ",", "4", ",", ...
Parse an AMQP byte-array value. @return array
[ "Parse", "an", "AMQP", "byte", "-", "array", "value", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Parser/Table.php#L172-L181
kakserpom/phpdaemon
PHPDaemon/Network/ClientConnection.php
ClientConnection.onResponse
public function onResponse($cb) { if ($cb === null && !$this->noSAF) { return; } $this->onResponse->push($cb); $this->checkFree(); }
php
public function onResponse($cb) { if ($cb === null && !$this->noSAF) { return; } $this->onResponse->push($cb); $this->checkFree(); }
[ "public", "function", "onResponse", "(", "$", "cb", ")", "{", "if", "(", "$", "cb", "===", "null", "&&", "!", "$", "this", "->", "noSAF", ")", "{", "return", ";", "}", "$", "this", "->", "onResponse", "->", "push", "(", "$", "cb", ")", ";", "$"...
Push callback to onReponse stack @param callable $cb Callback @return void
[ "Push", "callback", "to", "onReponse", "stack" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/ClientConnection.php#L66-L73
kakserpom/phpdaemon
PHPDaemon/Network/ClientConnection.php
ClientConnection.checkFree
public function checkFree() { $this->setFree(!$this->finished && !$this->acquired && (!$this->onResponse || $this->onResponse->count() < $this->maxQueue)); }
php
public function checkFree() { $this->setFree(!$this->finished && !$this->acquired && (!$this->onResponse || $this->onResponse->count() < $this->maxQueue)); }
[ "public", "function", "checkFree", "(", ")", "{", "$", "this", "->", "setFree", "(", "!", "$", "this", "->", "finished", "&&", "!", "$", "this", "->", "acquired", "&&", "(", "!", "$", "this", "->", "onResponse", "||", "$", "this", "->", "onResponse",...
Set connection free/busy according to onResponse emptiness and ->finished @return void
[ "Set", "connection", "free", "/", "busy", "according", "to", "onResponse", "emptiness", "and", "-", ">", "finished" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/ClientConnection.php#L79-L82
kakserpom/phpdaemon
PHPDaemon/Network/ClientConnection.php
ClientConnection.setFree
public function setFree($free = true) { if ($this->busy === !$free) { return; } $this->busy = !$free; if ($this->url === null) { return; } if ($this->pool === null) { return; } if ($this->finished) { return; } if ($this->busy) { $this->pool->markConnBusy($this, $this->url); } else { $this->pool->markConnFree($this, $this->url); $this->pool->touchPending($this->url); } }
php
public function setFree($free = true) { if ($this->busy === !$free) { return; } $this->busy = !$free; if ($this->url === null) { return; } if ($this->pool === null) { return; } if ($this->finished) { return; } if ($this->busy) { $this->pool->markConnBusy($this, $this->url); } else { $this->pool->markConnFree($this, $this->url); $this->pool->touchPending($this->url); } }
[ "public", "function", "setFree", "(", "$", "free", "=", "true", ")", "{", "if", "(", "$", "this", "->", "busy", "===", "!", "$", "free", ")", "{", "return", ";", "}", "$", "this", "->", "busy", "=", "!", "$", "free", ";", "if", "(", "$", "thi...
Set connection free/busy @param boolean $free Free? @return void
[ "Set", "connection", "free", "/", "busy" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/ClientConnection.php#L89-L110
kakserpom/phpdaemon
PHPDaemon/Network/ClientConnection.php
ClientConnection.onReady
public function onReady() { parent::onReady(); $this->setWatermark(null, $this->pool->maxAllowedPacket); if ($this->url === null) { return; } if ($this->connected && !$this->busy) { $this->pool->markConnFree($this, $this->url); } }
php
public function onReady() { parent::onReady(); $this->setWatermark(null, $this->pool->maxAllowedPacket); if ($this->url === null) { return; } if ($this->connected && !$this->busy) { $this->pool->markConnFree($this, $this->url); } }
[ "public", "function", "onReady", "(", ")", "{", "parent", "::", "onReady", "(", ")", ";", "$", "this", "->", "setWatermark", "(", "null", ",", "$", "this", "->", "pool", "->", "maxAllowedPacket", ")", ";", "if", "(", "$", "this", "->", "url", "===", ...
Called when the connection is handshaked (at low-level), and peer is ready to recv. data @return void
[ "Called", "when", "the", "connection", "is", "handshaked", "(", "at", "low", "-", "level", ")", "and", "peer", "is", "ready", "to", "recv", ".", "data" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/ClientConnection.php#L116-L126
kakserpom/phpdaemon
PHPDaemon/Network/ClientConnection.php
ClientConnection.onFinish
public function onFinish() { $this->onResponse->executeAll($this, false); $this->onResponse = null; if ($this->pool && ($this->url !== null)) { $this->pool->detachConnFromUrl($this, $this->url); } parent::onFinish(); }
php
public function onFinish() { $this->onResponse->executeAll($this, false); $this->onResponse = null; if ($this->pool && ($this->url !== null)) { $this->pool->detachConnFromUrl($this, $this->url); } parent::onFinish(); }
[ "public", "function", "onFinish", "(", ")", "{", "$", "this", "->", "onResponse", "->", "executeAll", "(", "$", "this", ",", "false", ")", ";", "$", "this", "->", "onResponse", "=", "null", ";", "if", "(", "$", "this", "->", "pool", "&&", "(", "$",...
Called when connection finishes @return void
[ "Called", "when", "connection", "finishes" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/ClientConnection.php#L170-L178
kakserpom/phpdaemon
PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Basic/BasicQosFrame.php
BasicQosFrame.create
public static function create( $prefetchSize = null, $prefetchCount = null, $global = null ) { $frame = new self(); if (null !== $prefetchSize) { $frame->prefetchSize = $prefetchSize; } if (null !== $prefetchCount) { $frame->prefetchCount = $prefetchCount; } if (null !== $global) { $frame->global = $global; } return $frame; }
php
public static function create( $prefetchSize = null, $prefetchCount = null, $global = null ) { $frame = new self(); if (null !== $prefetchSize) { $frame->prefetchSize = $prefetchSize; } if (null !== $prefetchCount) { $frame->prefetchCount = $prefetchCount; } if (null !== $global) { $frame->global = $global; } return $frame; }
[ "public", "static", "function", "create", "(", "$", "prefetchSize", "=", "null", ",", "$", "prefetchCount", "=", "null", ",", "$", "global", "=", "null", ")", "{", "$", "frame", "=", "new", "self", "(", ")", ";", "if", "(", "null", "!==", "$", "pre...
bit
[ "bit" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Basic/BasicQosFrame.php#L22-L39
kakserpom/phpdaemon
PHPDaemon/Applications/FileReaderRequest.php
FileReaderRequest.init
public function init() { if (!isset($this->attrs->server['FR_PATH'])) { $this->status(404); $this->finish(); return; } $job = new \PHPDaemon\Core\ComplexJob(function ($job) { $this->wakeup(); }); $this->job = $job; $this->sleep(5, true); $this->attrs->server['FR_PATH'] = \PHPDaemon\FS\FileSystem::sanitizePath($this->attrs->server['FR_PATH']); $job('stat', function ($name, $job) { /** @var \PHPDaemon\Core\ComplexJob $job */ \PHPDaemon\FS\FileSystem::stat($this->attrs->server['FR_PATH'], function ($path, $stat) use ($job) { if ($stat === -1) { $this->fileNotFound(); $job->setResult('stat', false); return; } if ($stat['type'] === 'd') { if (!\PHPDaemon\FS\FileSystem::$supported) { $this->file(rtrim($path, '/') . '/index.html'); } else { $job('readdir', function ($name, $job) use ($path) { /** @var \PHPDaemon\Core\ComplexJob $job */ \PHPDaemon\FS\FileSystem::readdir(rtrim($path, '/'), function ($path, $dir) use ($job) { $found = false; if (is_array($dir)) { foreach ($dir['dents'] as $file) { if ($file['type'] === \EIO_DT_REG) { // is file if (in_array($file['name'], $this->appInstance->indexFiles)) { $this->file($path . '/' . $file['name']); $found = true; break; } } } } if (!$found) { if (isset($this->attrs->server['FR_AUTOINDEX']) && $this->attrs->server['FR_AUTOINDEX']) { $this->autoindex($path, $dir); } else { $this->fileNotFound(); } } $job->setResult('readdir'); }, \EIO_READDIR_STAT_ORDER | \EIO_READDIR_DENTS); }); } } elseif ($stat['type'] === 'f') { $this->file($path); } $job->setResult('stat', $stat); }); }); $job(); }
php
public function init() { if (!isset($this->attrs->server['FR_PATH'])) { $this->status(404); $this->finish(); return; } $job = new \PHPDaemon\Core\ComplexJob(function ($job) { $this->wakeup(); }); $this->job = $job; $this->sleep(5, true); $this->attrs->server['FR_PATH'] = \PHPDaemon\FS\FileSystem::sanitizePath($this->attrs->server['FR_PATH']); $job('stat', function ($name, $job) { /** @var \PHPDaemon\Core\ComplexJob $job */ \PHPDaemon\FS\FileSystem::stat($this->attrs->server['FR_PATH'], function ($path, $stat) use ($job) { if ($stat === -1) { $this->fileNotFound(); $job->setResult('stat', false); return; } if ($stat['type'] === 'd') { if (!\PHPDaemon\FS\FileSystem::$supported) { $this->file(rtrim($path, '/') . '/index.html'); } else { $job('readdir', function ($name, $job) use ($path) { /** @var \PHPDaemon\Core\ComplexJob $job */ \PHPDaemon\FS\FileSystem::readdir(rtrim($path, '/'), function ($path, $dir) use ($job) { $found = false; if (is_array($dir)) { foreach ($dir['dents'] as $file) { if ($file['type'] === \EIO_DT_REG) { // is file if (in_array($file['name'], $this->appInstance->indexFiles)) { $this->file($path . '/' . $file['name']); $found = true; break; } } } } if (!$found) { if (isset($this->attrs->server['FR_AUTOINDEX']) && $this->attrs->server['FR_AUTOINDEX']) { $this->autoindex($path, $dir); } else { $this->fileNotFound(); } } $job->setResult('readdir'); }, \EIO_READDIR_STAT_ORDER | \EIO_READDIR_DENTS); }); } } elseif ($stat['type'] === 'f') { $this->file($path); } $job->setResult('stat', $stat); }); }); $job(); }
[ "public", "function", "init", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "attrs", "->", "server", "[", "'FR_PATH'", "]", ")", ")", "{", "$", "this", "->", "status", "(", "404", ")", ";", "$", "this", "->", "finish", "(", ")...
Constructor. @return void
[ "Constructor", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Applications/FileReaderRequest.php#L29-L88
kakserpom/phpdaemon
PHPDaemon/Applications/FileReaderRequest.php
FileReaderRequest.fileNotFound
public function fileNotFound() { try { $this->header('404 Not Found'); $this->header('Content-Type: text/html'); } catch (\PHPDaemon\Request\RequestHeadersAlreadySent $e) { } $this->out('File not found.'); }
php
public function fileNotFound() { try { $this->header('404 Not Found'); $this->header('Content-Type: text/html'); } catch (\PHPDaemon\Request\RequestHeadersAlreadySent $e) { } $this->out('File not found.'); }
[ "public", "function", "fileNotFound", "(", ")", "{", "try", "{", "$", "this", "->", "header", "(", "'404 Not Found'", ")", ";", "$", "this", "->", "header", "(", "'Content-Type: text/html'", ")", ";", "}", "catch", "(", "\\", "PHPDaemon", "\\", "Request", ...
Send header 404 or, if not possible already, response "File not found"
[ "Send", "header", "404", "or", "if", "not", "possible", "already", "response", "File", "not", "found" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Applications/FileReaderRequest.php#L93-L101
kakserpom/phpdaemon
PHPDaemon/Clients/ICMP/Connection.php
Connection.sendEcho
public function sendEcho($cb, $data = 'phpdaemon') { ++$this->seq; if (mb_orig_strlen($data) % 2 !== 0) { $data .= "\x00"; } $packet = pack( 'ccnnn', 8, // type (c) 0, // code (c) 0, // checksum (n) Daemon::$process->getPid(), // pid (n) $this->seq // seq (n) ) . $data; $packet = substr_replace($packet, self::checksum($packet), 2, 2); $this->write($packet); $this->onResponse->push([$cb, microtime(true)]); }
php
public function sendEcho($cb, $data = 'phpdaemon') { ++$this->seq; if (mb_orig_strlen($data) % 2 !== 0) { $data .= "\x00"; } $packet = pack( 'ccnnn', 8, // type (c) 0, // code (c) 0, // checksum (n) Daemon::$process->getPid(), // pid (n) $this->seq // seq (n) ) . $data; $packet = substr_replace($packet, self::checksum($packet), 2, 2); $this->write($packet); $this->onResponse->push([$cb, microtime(true)]); }
[ "public", "function", "sendEcho", "(", "$", "cb", ",", "$", "data", "=", "'phpdaemon'", ")", "{", "++", "$", "this", "->", "seq", ";", "if", "(", "mb_orig_strlen", "(", "$", "data", ")", "%", "2", "!==", "0", ")", "{", "$", "data", ".=", "\"\\x00...
Send echo-request @param callable $cb Callback @param string $data Data @callback $cb ( ) @return void
[ "Send", "echo", "-", "request" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/ICMP/Connection.php#L45-L64
kakserpom/phpdaemon
PHPDaemon/Clients/ICMP/Connection.php
Connection.checksum
protected static function checksum($data) { $bit = unpack('n*', $data); $sum = array_sum($bit); if (mb_orig_strlen($data) % 2) { $temp = unpack('C*', $data[mb_orig_strlen($data) - 1]); $sum += $temp[1]; } $sum = ($sum >> 16) + ($sum & 0xffff); $sum += ($sum >> 16); return pack('n*', ~$sum); }
php
protected static function checksum($data) { $bit = unpack('n*', $data); $sum = array_sum($bit); if (mb_orig_strlen($data) % 2) { $temp = unpack('C*', $data[mb_orig_strlen($data) - 1]); $sum += $temp[1]; } $sum = ($sum >> 16) + ($sum & 0xffff); $sum += ($sum >> 16); return pack('n*', ~$sum); }
[ "protected", "static", "function", "checksum", "(", "$", "data", ")", "{", "$", "bit", "=", "unpack", "(", "'n*'", ",", "$", "data", ")", ";", "$", "sum", "=", "array_sum", "(", "$", "bit", ")", ";", "if", "(", "mb_orig_strlen", "(", "$", "data", ...
Build checksum @param string $data Source @return string Checksum
[ "Build", "checksum" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/ICMP/Connection.php#L71-L82
kakserpom/phpdaemon
PHPDaemon/Clients/ICMP/Connection.php
Connection.onRead
public function onRead() { $packet = $this->read(1024); $orig = $packet; $type = Binary::getByte($packet); $code = Binary::getByte($packet); $checksum = Binary::getStrWord($packet); $id = Binary::getWord($packet); $seq = Binary::getWord($packet); if ($checksum !== self::checksum(substr_replace($orig, "\x00\x00", 2, 2))) { $status = 'badChecksum'; } elseif ($type === 0x03) { $status = isset(static::$unreachableCodes[$code]) ? static::$unreachableCodes[$code] : 'unk' . $code . 'unreachable'; } else { $status = 'unknownType0x' . dechex($type); } while (!$this->onResponse->isEmpty()) { $el = $this->onResponse->shift(); if ($el instanceof CallbackWrapper) { $el = $el->unwrap(); } list($cb, $st) = $el; $cb(microtime(true) - $st, $status); } $this->finish(); }
php
public function onRead() { $packet = $this->read(1024); $orig = $packet; $type = Binary::getByte($packet); $code = Binary::getByte($packet); $checksum = Binary::getStrWord($packet); $id = Binary::getWord($packet); $seq = Binary::getWord($packet); if ($checksum !== self::checksum(substr_replace($orig, "\x00\x00", 2, 2))) { $status = 'badChecksum'; } elseif ($type === 0x03) { $status = isset(static::$unreachableCodes[$code]) ? static::$unreachableCodes[$code] : 'unk' . $code . 'unreachable'; } else { $status = 'unknownType0x' . dechex($type); } while (!$this->onResponse->isEmpty()) { $el = $this->onResponse->shift(); if ($el instanceof CallbackWrapper) { $el = $el->unwrap(); } list($cb, $st) = $el; $cb(microtime(true) - $st, $status); } $this->finish(); }
[ "public", "function", "onRead", "(", ")", "{", "$", "packet", "=", "$", "this", "->", "read", "(", "1024", ")", ";", "$", "orig", "=", "$", "packet", ";", "$", "type", "=", "Binary", "::", "getByte", "(", "$", "packet", ")", ";", "$", "code", "...
Called when new data received @return void
[ "Called", "when", "new", "data", "received" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/ICMP/Connection.php#L88-L113
kakserpom/phpdaemon
PHPDaemon/DNode/DNode.php
DNode.ensureCallback
public static function ensureCallback(&$arg) { if ($arg instanceof \Closure) { return true; } if (is_array($arg) && sizeof($arg) === 2) { if (isset($arg[0]) && $arg[0] instanceof \PHPDaemon\WebSocket\Route) { if (isset($arg[1]) && is_string($arg[1]) && strncmp($arg[1], 'remote_', 7) === 0) { return true; } } } $arg = null; return false; }
php
public static function ensureCallback(&$arg) { if ($arg instanceof \Closure) { return true; } if (is_array($arg) && sizeof($arg) === 2) { if (isset($arg[0]) && $arg[0] instanceof \PHPDaemon\WebSocket\Route) { if (isset($arg[1]) && is_string($arg[1]) && strncmp($arg[1], 'remote_', 7) === 0) { return true; } } } $arg = null; return false; }
[ "public", "static", "function", "ensureCallback", "(", "&", "$", "arg", ")", "{", "if", "(", "$", "arg", "instanceof", "\\", "Closure", ")", "{", "return", "true", ";", "}", "if", "(", "is_array", "(", "$", "arg", ")", "&&", "sizeof", "(", "$", "ar...
Ensures that the variable passed by reference holds a valid callback-function If it doesn't, its value will be reset to null @param mixed &$arg Argument @return boolean
[ "Ensures", "that", "the", "variable", "passed", "by", "reference", "holds", "a", "valid", "callback", "-", "function", "If", "it", "doesn", "t", "its", "value", "will", "be", "reset", "to", "null" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/DNode/DNode.php#L60-L74
kakserpom/phpdaemon
PHPDaemon/DNode/DNode.php
DNode.toJsonDebugResursive
public static function toJsonDebugResursive(&$m) { if ($m instanceof \Closure) { $m = '__CALLBACK__'; } elseif (is_array($m)) { if (sizeof($m) === 2 && isset($m[0]) && $m[0] instanceof \PHPDaemon\WebSocket\Route) { if (isset($m[1]) && is_string($m[1]) && strncmp($m[1], 'remote_', 7) === 0) { $m = '__CALLBACK__'; } } else { foreach ($m as &$v) { static::toJsonDebugResursive($v); } } } elseif (is_object($m)) { foreach ($m as &$v) { static::toJsonDebugResursive($v); } } }
php
public static function toJsonDebugResursive(&$m) { if ($m instanceof \Closure) { $m = '__CALLBACK__'; } elseif (is_array($m)) { if (sizeof($m) === 2 && isset($m[0]) && $m[0] instanceof \PHPDaemon\WebSocket\Route) { if (isset($m[1]) && is_string($m[1]) && strncmp($m[1], 'remote_', 7) === 0) { $m = '__CALLBACK__'; } } else { foreach ($m as &$v) { static::toJsonDebugResursive($v); } } } elseif (is_object($m)) { foreach ($m as &$v) { static::toJsonDebugResursive($v); } } }
[ "public", "static", "function", "toJsonDebugResursive", "(", "&", "$", "m", ")", "{", "if", "(", "$", "m", "instanceof", "\\", "Closure", ")", "{", "$", "m", "=", "'__CALLBACK__'", ";", "}", "elseif", "(", "is_array", "(", "$", "m", ")", ")", "{", ...
Recursion handler for toJsonDebug() @param array &$a Data @return void
[ "Recursion", "handler", "for", "toJsonDebug", "()" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/DNode/DNode.php#L92-L111
kakserpom/phpdaemon
PHPDaemon/DNode/DNode.php
DNode.defineLocalMethods
protected function defineLocalMethods($arr = []) { foreach (get_class_methods($this) as $m) { if (substr($m, -6) === 'Method') { $k = substr($m, 0, -6); if ($k === 'methods') { continue; } $arr[$k] = [$this, $m]; } } foreach ($arr as $k => $v) { $this->localMethods[$k] = $v; } $this->persistentMode = true; $this->callRemote('methods', $arr); $this->persistentMode = false; }
php
protected function defineLocalMethods($arr = []) { foreach (get_class_methods($this) as $m) { if (substr($m, -6) === 'Method') { $k = substr($m, 0, -6); if ($k === 'methods') { continue; } $arr[$k] = [$this, $m]; } } foreach ($arr as $k => $v) { $this->localMethods[$k] = $v; } $this->persistentMode = true; $this->callRemote('methods', $arr); $this->persistentMode = false; }
[ "protected", "function", "defineLocalMethods", "(", "$", "arr", "=", "[", "]", ")", "{", "foreach", "(", "get_class_methods", "(", "$", "this", ")", "as", "$", "m", ")", "{", "if", "(", "substr", "(", "$", "m", ",", "-", "6", ")", "===", "'Method'"...
Defines local methods @param array $arr Associative array of callbacks (methodName => callback) @return void
[ "Defines", "local", "methods" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/DNode/DNode.php#L127-L144
kakserpom/phpdaemon
PHPDaemon/DNode/DNode.php
DNode.exportObjectMethods
public static function exportObjectMethods($object) { $methods = []; foreach (get_class_methods($object) as $method) { if ($method[0] === '_') { continue; } $methods[$method] = [$object, $method]; } return $methods; }
php
public static function exportObjectMethods($object) { $methods = []; foreach (get_class_methods($object) as $method) { if ($method[0] === '_') { continue; } $methods[$method] = [$object, $method]; } return $methods; }
[ "public", "static", "function", "exportObjectMethods", "(", "$", "object", ")", "{", "$", "methods", "=", "[", "]", ";", "foreach", "(", "get_class_methods", "(", "$", "object", ")", "as", "$", "method", ")", "{", "if", "(", "$", "method", "[", "0", ...
Export object methods @param $object @return array
[ "Export", "object", "methods" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/DNode/DNode.php#L164-L173
kakserpom/phpdaemon
PHPDaemon/DNode/DNode.php
DNode.callRemoteArray
public function callRemoteArray($method, $args) { if (isset($this->remoteMethods[$method])) { $this->remoteMethods[$method](...$args); return $this; } $pct = [ 'method' => $method, ]; if (sizeof($args)) { $callbacks = []; $path = []; $this->extractCallbacks($args, $callbacks, $path); $pct['arguments'] = $args; if (sizeof($callbacks)) { $pct['callbacks'] = $callbacks; } } $this->sendPacket($pct); return $this; }
php
public function callRemoteArray($method, $args) { if (isset($this->remoteMethods[$method])) { $this->remoteMethods[$method](...$args); return $this; } $pct = [ 'method' => $method, ]; if (sizeof($args)) { $callbacks = []; $path = []; $this->extractCallbacks($args, $callbacks, $path); $pct['arguments'] = $args; if (sizeof($callbacks)) { $pct['callbacks'] = $callbacks; } } $this->sendPacket($pct); return $this; }
[ "public", "function", "callRemoteArray", "(", "$", "method", ",", "$", "args", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "remoteMethods", "[", "$", "method", "]", ")", ")", "{", "$", "this", "->", "remoteMethods", "[", "$", "method", "]",...
Calls a remote method with array of arguments @param string $method Method name @param array $args Arguments @return this
[ "Calls", "a", "remote", "method", "with", "array", "of", "arguments" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/DNode/DNode.php#L181-L201
kakserpom/phpdaemon
PHPDaemon/DNode/DNode.php
DNode.extractCallbacks
protected function extractCallbacks(&$args, &$list, &$path) { foreach ($args as $k => &$v) { if (is_array($v)) { if (sizeof($v) === 2) { if (isset($v[0]) && is_object($v[0])) { if (isset($v[1]) && is_string($v[1])) { $id = ++$this->counter; if ($this->persistentMode) { $this->persistentCallbacks[$id] = $v; } else { $this->callbacks[$id] = $v; } $v = ''; $list[$id] = $path; $list[$id][] = $k; continue; } } } $path[] = $k; $this->extractCallbacks($v, $list, $path); array_pop($path); } elseif ($v instanceof \Closure) { $id = ++$this->counter; if ($this->persistentMode) { $this->persistentCallbacks[$id] = $v; } else { $this->callbacks[$id] = $v; } $v = ''; $list[$id] = $path; $list[$id][] = $k; } } }
php
protected function extractCallbacks(&$args, &$list, &$path) { foreach ($args as $k => &$v) { if (is_array($v)) { if (sizeof($v) === 2) { if (isset($v[0]) && is_object($v[0])) { if (isset($v[1]) && is_string($v[1])) { $id = ++$this->counter; if ($this->persistentMode) { $this->persistentCallbacks[$id] = $v; } else { $this->callbacks[$id] = $v; } $v = ''; $list[$id] = $path; $list[$id][] = $k; continue; } } } $path[] = $k; $this->extractCallbacks($v, $list, $path); array_pop($path); } elseif ($v instanceof \Closure) { $id = ++$this->counter; if ($this->persistentMode) { $this->persistentCallbacks[$id] = $v; } else { $this->callbacks[$id] = $v; } $v = ''; $list[$id] = $path; $list[$id][] = $k; } } }
[ "protected", "function", "extractCallbacks", "(", "&", "$", "args", ",", "&", "$", "list", ",", "&", "$", "path", ")", "{", "foreach", "(", "$", "args", "as", "$", "k", "=>", "&", "$", "v", ")", "{", "if", "(", "is_array", "(", "$", "v", ")", ...
Extracts callback functions from array of arguments @param array &$args Arguments @param array &$list Output array for 'callbacks' property @param array &$path Recursion path holder @return void
[ "Extracts", "callback", "functions", "from", "array", "of", "arguments" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/DNode/DNode.php#L210-L245
kakserpom/phpdaemon
PHPDaemon/DNode/DNode.php
DNode.sendPacket
protected function sendPacket($pct) { if (!$this->client) { return; } if (is_string($pct['method']) && ctype_digit($pct['method'])) { $pct['method'] = (int)$pct['method']; } $this->client->sendFrame(static::toJson($pct) . "\n"); }
php
protected function sendPacket($pct) { if (!$this->client) { return; } if (is_string($pct['method']) && ctype_digit($pct['method'])) { $pct['method'] = (int)$pct['method']; } $this->client->sendFrame(static::toJson($pct) . "\n"); }
[ "protected", "function", "sendPacket", "(", "$", "pct", ")", "{", "if", "(", "!", "$", "this", "->", "client", ")", "{", "return", ";", "}", "if", "(", "is_string", "(", "$", "pct", "[", "'method'", "]", ")", "&&", "ctype_digit", "(", "$", "pct", ...
Sends a packet @param array $pct Data @return void
[ "Sends", "a", "packet" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/DNode/DNode.php#L252-L261
kakserpom/phpdaemon
PHPDaemon/DNode/DNode.php
DNode.callLocal
public function callLocal(...$args) { if (!sizeof($args)) { return $this; } $method = array_shift($args); $p = [ 'method' => $method, 'arguments' => $args, ]; $this->onPacket($p); return $this; }
php
public function callLocal(...$args) { if (!sizeof($args)) { return $this; } $method = array_shift($args); $p = [ 'method' => $method, 'arguments' => $args, ]; $this->onPacket($p); return $this; }
[ "public", "function", "callLocal", "(", "...", "$", "args", ")", "{", "if", "(", "!", "sizeof", "(", "$", "args", ")", ")", "{", "return", "$", "this", ";", "}", "$", "method", "=", "array_shift", "(", "$", "args", ")", ";", "$", "p", "=", "[",...
Calls a local method @param string $method Method name @param mixed ...$args Arguments @return this
[ "Calls", "a", "local", "method" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/DNode/DNode.php#L279-L291
kakserpom/phpdaemon
PHPDaemon/DNode/DNode.php
DNode.onPacket
public function onPacket($pct) { if ($this->cleaned) { return; } $m = isset($pct['method']) ? $pct['method'] : null; $args = isset($pct['arguments']) ? $pct['arguments'] : []; if (isset($pct['callbacks']) && is_array($pct['callbacks'])) { foreach ($pct['callbacks'] as $id => $path) { static::setPath($args, $path, [$this, 'remote_' . $id]); } } if (isset($pct['links']) && is_array($pct['links'])) { foreach ($pct['links'] as $link) { static::setPath($args, $link['to'], static::getPath($args, $link['from'])); } } try { if (is_string($m)) { if (isset($this->localMethods[$m])) { $this->localMethods[$m](...$args); } elseif (method_exists($this, $m . 'Method')) { $func = [$this, $m . 'Method']; $func(...$args); } else { $this->handleException(new UndefinedMethodCalled( 'DNode: local method ' . json_encode($m) . ' does not exist. Packet: ' . json_encode($pct) )); } } elseif (is_int($m)) { if (isset($this->callbacks[$m])) { if (!$this->callbacks[$m](...$args)) { unset($this->callbacks[$m]); } } elseif (isset($this->persistentCallbacks[$m])) { $this->persistentCallbacks[$m](...$args); } else { $this->handleException(new UndefinedMethodCalled( 'DNode: local callback # ' . $m . ' is not registered. Packet: ' . json_encode($pct) )); } } else { $this->handleException(new ProtocolError( 'DNode: \'method\' must be string or integer. Packet: ' . json_encode($pct) )); } } catch (\Throwable $exception) { } }
php
public function onPacket($pct) { if ($this->cleaned) { return; } $m = isset($pct['method']) ? $pct['method'] : null; $args = isset($pct['arguments']) ? $pct['arguments'] : []; if (isset($pct['callbacks']) && is_array($pct['callbacks'])) { foreach ($pct['callbacks'] as $id => $path) { static::setPath($args, $path, [$this, 'remote_' . $id]); } } if (isset($pct['links']) && is_array($pct['links'])) { foreach ($pct['links'] as $link) { static::setPath($args, $link['to'], static::getPath($args, $link['from'])); } } try { if (is_string($m)) { if (isset($this->localMethods[$m])) { $this->localMethods[$m](...$args); } elseif (method_exists($this, $m . 'Method')) { $func = [$this, $m . 'Method']; $func(...$args); } else { $this->handleException(new UndefinedMethodCalled( 'DNode: local method ' . json_encode($m) . ' does not exist. Packet: ' . json_encode($pct) )); } } elseif (is_int($m)) { if (isset($this->callbacks[$m])) { if (!$this->callbacks[$m](...$args)) { unset($this->callbacks[$m]); } } elseif (isset($this->persistentCallbacks[$m])) { $this->persistentCallbacks[$m](...$args); } else { $this->handleException(new UndefinedMethodCalled( 'DNode: local callback # ' . $m . ' is not registered. Packet: ' . json_encode($pct) )); } } else { $this->handleException(new ProtocolError( 'DNode: \'method\' must be string or integer. Packet: ' . json_encode($pct) )); } } catch (\Throwable $exception) { } }
[ "public", "function", "onPacket", "(", "$", "pct", ")", "{", "if", "(", "$", "this", "->", "cleaned", ")", "{", "return", ";", "}", "$", "m", "=", "isset", "(", "$", "pct", "[", "'method'", "]", ")", "?", "$", "pct", "[", "'method'", "]", ":", ...
Called when new packet is received @param array $pct Packet @return void
[ "Called", "when", "new", "packet", "is", "received" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/DNode/DNode.php#L298-L346
kakserpom/phpdaemon
PHPDaemon/DNode/DNode.php
DNode.setPath
protected static function setPath(&$m, $path, $val) { foreach ($path as $p) { $m =& $m[$p]; } $m = $val; }
php
protected static function setPath(&$m, $path, $val) { foreach ($path as $p) { $m =& $m[$p]; } $m = $val; }
[ "protected", "static", "function", "setPath", "(", "&", "$", "m", ",", "$", "path", ",", "$", "val", ")", "{", "foreach", "(", "$", "path", "as", "$", "p", ")", "{", "$", "m", "=", "&", "$", "m", "[", "$", "p", "]", ";", "}", "$", "m", "=...
Sets value by materialized path @param array &$m @param array $path @param mixed $val @return void
[ "Sets", "value", "by", "materialized", "path" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/DNode/DNode.php#L355-L361
kakserpom/phpdaemon
PHPDaemon/DNode/DNode.php
DNode.&
protected static function &getPath(&$m, $path) { foreach ($path as $p) { $m =& $m[$p]; } return $m; }
php
protected static function &getPath(&$m, $path) { foreach ($path as $p) { $m =& $m[$p]; } return $m; }
[ "protected", "static", "function", "&", "getPath", "(", "&", "$", "m", ",", "$", "path", ")", "{", "foreach", "(", "$", "path", "as", "$", "p", ")", "{", "$", "m", "=", "&", "$", "m", "[", "$", "p", "]", ";", "}", "return", "$", "m", ";", ...
Finds value by materialized path @param array &$m @param array $path @return mixed Value
[ "Finds", "value", "by", "materialized", "path" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/DNode/DNode.php#L369-L375
kakserpom/phpdaemon
PHPDaemon/DNode/DNode.php
DNode.cleanup
public function cleanup() { $this->cleaned = true; $this->remoteMethods = []; $this->localMethods = []; $this->persistentCallbacks = []; $this->callbacks = []; }
php
public function cleanup() { $this->cleaned = true; $this->remoteMethods = []; $this->localMethods = []; $this->persistentCallbacks = []; $this->callbacks = []; }
[ "public", "function", "cleanup", "(", ")", "{", "$", "this", "->", "cleaned", "=", "true", ";", "$", "this", "->", "remoteMethods", "=", "[", "]", ";", "$", "this", "->", "localMethods", "=", "[", "]", ";", "$", "this", "->", "persistentCallbacks", "...
Swipes internal structures @return void
[ "Swipes", "internal", "structures" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/DNode/DNode.php#L391-L398
kakserpom/phpdaemon
PHPDaemon/DNode/DNode.php
DNode.onFrame
public function onFrame($data, $type) { foreach (explode("\n", $data) as $pct) { if ($pct === '') { continue; } $this->onPacket(json_decode($pct, true)); } }
php
public function onFrame($data, $type) { foreach (explode("\n", $data) as $pct) { if ($pct === '') { continue; } $this->onPacket(json_decode($pct, true)); } }
[ "public", "function", "onFrame", "(", "$", "data", ",", "$", "type", ")", "{", "foreach", "(", "explode", "(", "\"\\n\"", ",", "$", "data", ")", "as", "$", "pct", ")", "{", "if", "(", "$", "pct", "===", "''", ")", "{", "continue", ";", "}", "$"...
Called when new frame is received @param string $data Frame's contents @param integer $type Frame's type @return void
[ "Called", "when", "new", "frame", "is", "received" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/DNode/DNode.php#L424-L432
kakserpom/phpdaemon
PHPDaemon/Traits/EventHandlers.php
EventHandlers.trigger
public function trigger($name, ...$args) { if ($this->addThisToEvents) { array_unshift($args, $this); } if (isset($this->eventHandlers[$name])) { $this->lastEventName = $name; foreach ($this->eventHandlers[$name] as $cb) { if ($cb(...$args) === true) { return $this; } } } return $this; }
php
public function trigger($name, ...$args) { if ($this->addThisToEvents) { array_unshift($args, $this); } if (isset($this->eventHandlers[$name])) { $this->lastEventName = $name; foreach ($this->eventHandlers[$name] as $cb) { if ($cb(...$args) === true) { return $this; } } } return $this; }
[ "public", "function", "trigger", "(", "$", "name", ",", "...", "$", "args", ")", "{", "if", "(", "$", "this", "->", "addThisToEvents", ")", "{", "array_unshift", "(", "$", "args", ",", "$", "this", ")", ";", "}", "if", "(", "isset", "(", "$", "th...
Propagate event @param string $name Event name @param mixed ...$args Arguments @return this
[ "Propagate", "event" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Traits/EventHandlers.php#L56-L70
kakserpom/phpdaemon
PHPDaemon/Traits/EventHandlers.php
EventHandlers.triggerAndCount
public function triggerAndCount($name, ...$args) { if ($this->addThisToEvents) { array_unshift($args, $this); } $cnt = 0; if (isset($this->eventHandlers[$name])) { $this->lastEventName = $name; foreach ($this->eventHandlers[$name] as $cb) { if ($cb(...$args) !== 0) { ++$cnt; } } } return $cnt; }
php
public function triggerAndCount($name, ...$args) { if ($this->addThisToEvents) { array_unshift($args, $this); } $cnt = 0; if (isset($this->eventHandlers[$name])) { $this->lastEventName = $name; foreach ($this->eventHandlers[$name] as $cb) { if ($cb(...$args) !== 0) { ++$cnt; } } } return $cnt; }
[ "public", "function", "triggerAndCount", "(", "$", "name", ",", "...", "$", "args", ")", "{", "if", "(", "$", "this", "->", "addThisToEvents", ")", "{", "array_unshift", "(", "$", "args", ",", "$", "this", ")", ";", "}", "$", "cnt", "=", "0", ";", ...
Propagate event @param string $name Event name @param mixed ...$args Arguments @return integer
[ "Propagate", "event" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Traits/EventHandlers.php#L78-L93
kakserpom/phpdaemon
PHPDaemon/Traits/EventHandlers.php
EventHandlers.bind
public function bind($event, $cb) { if ($cb !== null) { $cb = CallbackWrapper::wrap($cb); } $event = (array) $event; foreach ($event as $e) { CallbackWrapper::addToArray($this->eventHandlers[$e], $cb); } return $this; }
php
public function bind($event, $cb) { if ($cb !== null) { $cb = CallbackWrapper::wrap($cb); } $event = (array) $event; foreach ($event as $e) { CallbackWrapper::addToArray($this->eventHandlers[$e], $cb); } return $this; }
[ "public", "function", "bind", "(", "$", "event", ",", "$", "cb", ")", "{", "if", "(", "$", "cb", "!==", "null", ")", "{", "$", "cb", "=", "CallbackWrapper", "::", "wrap", "(", "$", "cb", ")", ";", "}", "$", "event", "=", "(", "array", ")", "$...
Bind event or events @param string|array $event Event name @param callable $cb Callback @return this
[ "Bind", "event", "or", "events" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Traits/EventHandlers.php#L122-L132
kakserpom/phpdaemon
PHPDaemon/Traits/EventHandlers.php
EventHandlers.unbind
public function unbind($event, $cb = null) { if ($cb !== null) { $cb = CallbackWrapper::wrap($cb); } $event = (array) $event; $success = true; foreach ($event as $e) { if (!isset($this->eventHandlers[$e])) { $success = false; continue; } if ($cb === null) { unset($this->eventHandlers[$e]); continue; } CallbackWrapper::removeFromArray($this->eventHandlers[$e], $cb); } return $this; }
php
public function unbind($event, $cb = null) { if ($cb !== null) { $cb = CallbackWrapper::wrap($cb); } $event = (array) $event; $success = true; foreach ($event as $e) { if (!isset($this->eventHandlers[$e])) { $success = false; continue; } if ($cb === null) { unset($this->eventHandlers[$e]); continue; } CallbackWrapper::removeFromArray($this->eventHandlers[$e], $cb); } return $this; }
[ "public", "function", "unbind", "(", "$", "event", ",", "$", "cb", "=", "null", ")", "{", "if", "(", "$", "cb", "!==", "null", ")", "{", "$", "cb", "=", "CallbackWrapper", "::", "wrap", "(", "$", "cb", ")", ";", "}", "$", "event", "=", "(", "...
Unbind event(s) or callback from event(s) @param string|array $event Event name @param callable $cb Callback, optional @return this
[ "Unbind", "event", "(", "s", ")", "or", "callback", "from", "event", "(", "s", ")" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Traits/EventHandlers.php#L152-L171
kakserpom/phpdaemon
PHPDaemon/Structures/ObjectStorage.php
ObjectStorage.each
public function each($method, ...$args) { if ($this->count() === 0) { return 0; } $n = 0; foreach ($this as $obj) { $obj->$method(...$args); ++$n; } return $n; }
php
public function each($method, ...$args) { if ($this->count() === 0) { return 0; } $n = 0; foreach ($this as $obj) { $obj->$method(...$args); ++$n; } return $n; }
[ "public", "function", "each", "(", "$", "method", ",", "...", "$", "args", ")", "{", "if", "(", "$", "this", "->", "count", "(", ")", "===", "0", ")", "{", "return", "0", ";", "}", "$", "n", "=", "0", ";", "foreach", "(", "$", "this", "as", ...
Call given method of all objects in storage @param string $method Method name @param mixed ...$args Arguments @return integer Number of called objects
[ "Call", "given", "method", "of", "all", "objects", "in", "storage" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Structures/ObjectStorage.php#L20-L31
kakserpom/phpdaemon
PHPDaemon/Structures/ObjectStorage.php
ObjectStorage.removeAll
public function removeAll($obj = null) { if ($obj === null) { $this->removeAllExcept(new \SplObjectStorage); } parent::removeAll($obj); }
php
public function removeAll($obj = null) { if ($obj === null) { $this->removeAllExcept(new \SplObjectStorage); } parent::removeAll($obj); }
[ "public", "function", "removeAll", "(", "$", "obj", "=", "null", ")", "{", "if", "(", "$", "obj", "===", "null", ")", "{", "$", "this", "->", "removeAllExcept", "(", "new", "\\", "SplObjectStorage", ")", ";", "}", "parent", "::", "removeAll", "(", "$...
Remove all objects from this storage, which contained in another storage @param \SplObjectStorage $obj @return void
[ "Remove", "all", "objects", "from", "this", "storage", "which", "contained", "in", "another", "storage" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Structures/ObjectStorage.php#L38-L44
kakserpom/phpdaemon
PHPDaemon/Structures/ObjectStorage.php
ObjectStorage.detachFirst
public function detachFirst() { $this->rewind(); $o = $this->current(); if (!$o) { return false; } $this->detach($o); return $o; }
php
public function detachFirst() { $this->rewind(); $o = $this->current(); if (!$o) { return false; } $this->detach($o); return $o; }
[ "public", "function", "detachFirst", "(", ")", "{", "$", "this", "->", "rewind", "(", ")", ";", "$", "o", "=", "$", "this", "->", "current", "(", ")", ";", "if", "(", "!", "$", "o", ")", "{", "return", "false", ";", "}", "$", "this", "->", "d...
Detaches first object and returns it @return object
[ "Detaches", "first", "object", "and", "returns", "it" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Structures/ObjectStorage.php#L50-L59
kakserpom/phpdaemon
PHPDaemon/Clients/Valve/Pool.php
Pool.ping
public function ping($addr, $cb) { $e = explode(':', $addr); $this->getConnection('valve://[udp:' . $e[0] . ']' . (isset($e[1]) ? ':' . $e[1] : '') . '/ping', function ($conn) use ($cb) { if (!$conn->connected) { $cb($conn, false); return; } $mt = microtime(true); $conn->request('ping', null, function ($conn, $success) use ($mt, $cb) { $cb($conn, $success ? (microtime(true) - $mt) : false); }); }); }
php
public function ping($addr, $cb) { $e = explode(':', $addr); $this->getConnection('valve://[udp:' . $e[0] . ']' . (isset($e[1]) ? ':' . $e[1] : '') . '/ping', function ($conn) use ($cb) { if (!$conn->connected) { $cb($conn, false); return; } $mt = microtime(true); $conn->request('ping', null, function ($conn, $success) use ($mt, $cb) { $cb($conn, $success ? (microtime(true) - $mt) : false); }); }); }
[ "public", "function", "ping", "(", "$", "addr", ",", "$", "cb", ")", "{", "$", "e", "=", "explode", "(", "':'", ",", "$", "addr", ")", ";", "$", "this", "->", "getConnection", "(", "'valve://[udp:'", ".", "$", "e", "[", "0", "]", ".", "']'", "....
Sends echo-request @param string $addr Address @param callable $cb Callback @callback $cb ( ) @return void
[ "Sends", "echo", "-", "request" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Valve/Pool.php#L29-L43
kakserpom/phpdaemon
PHPDaemon/Clients/Valve/Pool.php
Pool.request
public function request($addr, $type, $data, $cb) { $e = explode(':', $addr); $this->getConnection('valve://[udp:' . $e[0] . ']' . (isset($e[1]) ? ':' . $e[1] : '') . '/', function ($conn) use ($cb, $addr, $data, $type) { if (!$conn->connected) { $cb($conn, false); return; } $conn->request($type, $data, $cb); }); }
php
public function request($addr, $type, $data, $cb) { $e = explode(':', $addr); $this->getConnection('valve://[udp:' . $e[0] . ']' . (isset($e[1]) ? ':' . $e[1] : '') . '/', function ($conn) use ($cb, $addr, $data, $type) { if (!$conn->connected) { $cb($conn, false); return; } $conn->request($type, $data, $cb); }); }
[ "public", "function", "request", "(", "$", "addr", ",", "$", "type", ",", "$", "data", ",", "$", "cb", ")", "{", "$", "e", "=", "explode", "(", "':'", ",", "$", "addr", ")", ";", "$", "this", "->", "getConnection", "(", "'valve://[udp:'", ".", "$...
Sends a request @param string $addr Address @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/Pool.php#L66-L77
kakserpom/phpdaemon
PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Connection/ConnectionOpenFrame.php
ConnectionOpenFrame.create
public static function create( $virtualHost = null, $capabilities = null, $insist = null ) { $frame = new self(); if (null !== $virtualHost) { $frame->virtualHost = $virtualHost; } if (null !== $capabilities) { $frame->capabilities = $capabilities; } if (null !== $insist) { $frame->insist = $insist; } return $frame; }
php
public static function create( $virtualHost = null, $capabilities = null, $insist = null ) { $frame = new self(); if (null !== $virtualHost) { $frame->virtualHost = $virtualHost; } if (null !== $capabilities) { $frame->capabilities = $capabilities; } if (null !== $insist) { $frame->insist = $insist; } return $frame; }
[ "public", "static", "function", "create", "(", "$", "virtualHost", "=", "null", ",", "$", "capabilities", "=", "null", ",", "$", "insist", "=", "null", ")", "{", "$", "frame", "=", "new", "self", "(", ")", ";", "if", "(", "null", "!==", "$", "virtu...
bit
[ "bit" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Connection/ConnectionOpenFrame.php#L22-L39
kakserpom/phpdaemon
PHPDaemon/Servers/FastCGI/Connection.php
Connection.onRead
public function onRead() { start: if ($this->state === self::STATE_ROOT) { $header = $this->readExact(8); if ($header === false) { return; } $this->header = unpack('Cver/Ctype/nreqid/nconlen/Cpadlen/Creserved', $header); if ($this->header['conlen'] > 0) { $this->setWatermark($this->header['conlen'], $this->header['conlen']); } $type = $this->header['type']; $this->header['ttype'] = isset(self::$requestTypes[$type]) ? self::$requestTypes[$type] : $type; $rid = $this->header['reqid']; $this->state = self::STATE_CONTENT; } else { $type = $this->header['type']; $rid = $this->header['reqid']; } if ($this->state === self::STATE_CONTENT) { $this->content = $this->readExact($this->header['conlen']); if ($this->content === false) { $this->setWatermark($this->header['conlen'], $this->header['conlen']); return; } if ($this->header['padlen'] > 0) { $this->setWatermark($this->header['padlen'], $this->header['padlen']); } $this->state = self::STATE_PADDING; } if ($this->state === self::STATE_PADDING) { $pad = $this->readExact($this->header['padlen']); if ($pad === false) { return; } } $this->setWatermark(8, 0xFFFFFF); $this->state = self::STATE_ROOT; // /*Daemon::log('[DEBUG] FastCGI-record ' . $this->header['ttype'] . '). Request ID: ' . $rid // . '. Content length: ' . $this->header['conlen'] . ' (' . mb_orig_strlen($this->content) . ') Padding length: ' . $this->header['padlen'] // . ' (' . mb_orig_strlen($pad) . ')');*/ if ($type === self::FCGI_BEGIN_REQUEST) { $u = unpack('nrole/Cflags', $this->content); $req = new \stdClass(); $req->attrs = new \stdClass; $req->attrs->request = []; $req->attrs->get = []; $req->attrs->post = []; $req->attrs->cookie = []; $req->attrs->server = []; $req->attrs->files = []; $req->attrs->session = null; $req->attrs->role = self::$roles[$u['role']]; $req->attrs->flags = $u['flags']; $req->attrs->id = $this->header['reqid']; $req->attrs->paramsDone = false; $req->attrs->inputDone = false; $req->attrs->input = new \PHPDaemon\HTTPRequest\Input(); $req->attrs->chunked = false; $req->attrs->noHttpVer = true; $req->queueId = $rid; $this->requests[$rid] = $req; } elseif (isset($this->requests[$rid])) { $req = $this->requests[$rid]; } else { Daemon::log('Unexpected FastCGI-record #' . $this->header['type'] . ' (' . $this->header['ttype'] . '). Request ID: ' . $rid . '.'); return; } if ($type === self::FCGI_ABORT_REQUEST) { $req->abort(); } elseif ($type === self::FCGI_PARAMS) { if ($this->content === '') { if (!isset($req->attrs->server['REQUEST_TIME'])) { $req->attrs->server['REQUEST_TIME'] = time(); } if (!isset($req->attrs->server['REQUEST_TIME_FLOAT'])) { $req->attrs->server['REQUEST_TIME_FLOAT'] = microtime(true); } $req->attrs->paramsDone = true; $req = Daemon::$appResolver->getRequest($req, $this); if ($req instanceof \stdClass) { $this->endRequest($req, 0, 0); unset($this->requests[$rid]); } else { if ($this->pool->config->sendfile->value && ( !$this->pool->config->sendfileonlybycommand->value || isset($req->attrs->server['USE_SENDFILE']) ) && !isset($req->attrs->server['DONT_USE_SENDFILE']) ) { $fn = tempnam( $this->pool->config->sendfiledir->value, $this->pool->config->sendfileprefix->value ); $req->sendfp = fopen($fn, 'wb'); $req->header('X-Sendfile: ' . $fn); } $this->requests[$rid] = $req; $req->callInit(); } } else { $p = 0; while ($p < $this->header['conlen']) { if (($namelen = ord($this->content{$p})) < 128) { ++$p; } else { $u = unpack( 'Nlen', chr(ord($this->content{$p}) & 0x7f) . mb_orig_substr($this->content, $p + 1, 3) ); $namelen = $u['len']; $p += 4; } if (($vlen = ord($this->content{$p})) < 128) { ++$p; } else { $u = unpack( 'Nlen', chr(ord($this->content{$p}) & 0x7f) . mb_orig_substr($this->content, $p + 1, 3) ); $vlen = $u['len']; $p += 4; } $req->attrs->server[mb_orig_substr($this->content, $p, $namelen)] = mb_orig_substr( $this->content, $p + $namelen, $vlen ); $p += $namelen + $vlen; } } } elseif ($type === self::FCGI_STDIN) { if (!$req->attrs->input) { goto start; } if ($this->content === '') { $req->attrs->input->sendEOF(); } else { $req->attrs->input->readFromString($this->content); } } if ($req->attrs->inputDone && $req->attrs->paramsDone) { $order = $this->pool->variablesOrder ?: 'GPC'; for ($i = 0, $s = mb_orig_strlen($order); $i < $s; ++$i) { $char = $order[$i]; if ($char === 'G' && is_array($req->attrs->get)) { $req->attrs->request += $req->attrs->get; } elseif ($char === 'P' && is_array($req->attrs->post)) { $req->attrs->request += $req->attrs->post; } elseif ($char === 'C' && is_array($req->attrs->cookie)) { $req->attrs->request += $req->attrs->cookie; } } Daemon::$process->timeLastActivity = time(); } goto start; }
php
public function onRead() { start: if ($this->state === self::STATE_ROOT) { $header = $this->readExact(8); if ($header === false) { return; } $this->header = unpack('Cver/Ctype/nreqid/nconlen/Cpadlen/Creserved', $header); if ($this->header['conlen'] > 0) { $this->setWatermark($this->header['conlen'], $this->header['conlen']); } $type = $this->header['type']; $this->header['ttype'] = isset(self::$requestTypes[$type]) ? self::$requestTypes[$type] : $type; $rid = $this->header['reqid']; $this->state = self::STATE_CONTENT; } else { $type = $this->header['type']; $rid = $this->header['reqid']; } if ($this->state === self::STATE_CONTENT) { $this->content = $this->readExact($this->header['conlen']); if ($this->content === false) { $this->setWatermark($this->header['conlen'], $this->header['conlen']); return; } if ($this->header['padlen'] > 0) { $this->setWatermark($this->header['padlen'], $this->header['padlen']); } $this->state = self::STATE_PADDING; } if ($this->state === self::STATE_PADDING) { $pad = $this->readExact($this->header['padlen']); if ($pad === false) { return; } } $this->setWatermark(8, 0xFFFFFF); $this->state = self::STATE_ROOT; // /*Daemon::log('[DEBUG] FastCGI-record ' . $this->header['ttype'] . '). Request ID: ' . $rid // . '. Content length: ' . $this->header['conlen'] . ' (' . mb_orig_strlen($this->content) . ') Padding length: ' . $this->header['padlen'] // . ' (' . mb_orig_strlen($pad) . ')');*/ if ($type === self::FCGI_BEGIN_REQUEST) { $u = unpack('nrole/Cflags', $this->content); $req = new \stdClass(); $req->attrs = new \stdClass; $req->attrs->request = []; $req->attrs->get = []; $req->attrs->post = []; $req->attrs->cookie = []; $req->attrs->server = []; $req->attrs->files = []; $req->attrs->session = null; $req->attrs->role = self::$roles[$u['role']]; $req->attrs->flags = $u['flags']; $req->attrs->id = $this->header['reqid']; $req->attrs->paramsDone = false; $req->attrs->inputDone = false; $req->attrs->input = new \PHPDaemon\HTTPRequest\Input(); $req->attrs->chunked = false; $req->attrs->noHttpVer = true; $req->queueId = $rid; $this->requests[$rid] = $req; } elseif (isset($this->requests[$rid])) { $req = $this->requests[$rid]; } else { Daemon::log('Unexpected FastCGI-record #' . $this->header['type'] . ' (' . $this->header['ttype'] . '). Request ID: ' . $rid . '.'); return; } if ($type === self::FCGI_ABORT_REQUEST) { $req->abort(); } elseif ($type === self::FCGI_PARAMS) { if ($this->content === '') { if (!isset($req->attrs->server['REQUEST_TIME'])) { $req->attrs->server['REQUEST_TIME'] = time(); } if (!isset($req->attrs->server['REQUEST_TIME_FLOAT'])) { $req->attrs->server['REQUEST_TIME_FLOAT'] = microtime(true); } $req->attrs->paramsDone = true; $req = Daemon::$appResolver->getRequest($req, $this); if ($req instanceof \stdClass) { $this->endRequest($req, 0, 0); unset($this->requests[$rid]); } else { if ($this->pool->config->sendfile->value && ( !$this->pool->config->sendfileonlybycommand->value || isset($req->attrs->server['USE_SENDFILE']) ) && !isset($req->attrs->server['DONT_USE_SENDFILE']) ) { $fn = tempnam( $this->pool->config->sendfiledir->value, $this->pool->config->sendfileprefix->value ); $req->sendfp = fopen($fn, 'wb'); $req->header('X-Sendfile: ' . $fn); } $this->requests[$rid] = $req; $req->callInit(); } } else { $p = 0; while ($p < $this->header['conlen']) { if (($namelen = ord($this->content{$p})) < 128) { ++$p; } else { $u = unpack( 'Nlen', chr(ord($this->content{$p}) & 0x7f) . mb_orig_substr($this->content, $p + 1, 3) ); $namelen = $u['len']; $p += 4; } if (($vlen = ord($this->content{$p})) < 128) { ++$p; } else { $u = unpack( 'Nlen', chr(ord($this->content{$p}) & 0x7f) . mb_orig_substr($this->content, $p + 1, 3) ); $vlen = $u['len']; $p += 4; } $req->attrs->server[mb_orig_substr($this->content, $p, $namelen)] = mb_orig_substr( $this->content, $p + $namelen, $vlen ); $p += $namelen + $vlen; } } } elseif ($type === self::FCGI_STDIN) { if (!$req->attrs->input) { goto start; } if ($this->content === '') { $req->attrs->input->sendEOF(); } else { $req->attrs->input->readFromString($this->content); } } if ($req->attrs->inputDone && $req->attrs->paramsDone) { $order = $this->pool->variablesOrder ?: 'GPC'; for ($i = 0, $s = mb_orig_strlen($order); $i < $s; ++$i) { $char = $order[$i]; if ($char === 'G' && is_array($req->attrs->get)) { $req->attrs->request += $req->attrs->get; } elseif ($char === 'P' && is_array($req->attrs->post)) { $req->attrs->request += $req->attrs->post; } elseif ($char === 'C' && is_array($req->attrs->cookie)) { $req->attrs->request += $req->attrs->cookie; } } Daemon::$process->timeLastActivity = time(); } goto start; }
[ "public", "function", "onRead", "(", ")", "{", "start", ":", "if", "(", "$", "this", "->", "state", "===", "self", "::", "STATE_ROOT", ")", "{", "$", "header", "=", "$", "this", "->", "readExact", "(", "8", ")", ";", "if", "(", "$", "header", "==...
Called when new data received @return void
[ "Called", "when", "new", "data", "received" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/FastCGI/Connection.php#L94-L275
kakserpom/phpdaemon
PHPDaemon/Servers/FastCGI/Connection.php
Connection.endRequest
public function endRequest($req, $appStatus, $protoStatus) { $c = pack('NC', $appStatus, $protoStatus) // app status, protocol status . "\x00\x00\x00"; $this->write( "\x01" // protocol version . "\x03" // record type (END_REQUEST) . pack('nn', $req->attrs->id, mb_orig_strlen($c)) // id, content length . "\x00" // padding length . "\x00" // reserved . $c // content ); if ($protoStatus === -1) { $this->close(); } elseif (!$this->pool->config->keepalive->value) { $this->finish(); } }
php
public function endRequest($req, $appStatus, $protoStatus) { $c = pack('NC', $appStatus, $protoStatus) // app status, protocol status . "\x00\x00\x00"; $this->write( "\x01" // protocol version . "\x03" // record type (END_REQUEST) . pack('nn', $req->attrs->id, mb_orig_strlen($c)) // id, content length . "\x00" // padding length . "\x00" // reserved . $c // content ); if ($protoStatus === -1) { $this->close(); } elseif (!$this->pool->config->keepalive->value) { $this->finish(); } }
[ "public", "function", "endRequest", "(", "$", "req", ",", "$", "appStatus", ",", "$", "protoStatus", ")", "{", "$", "c", "=", "pack", "(", "'NC'", ",", "$", "appStatus", ",", "$", "protoStatus", ")", "// app status, protocol status", ".", "\"\\x00\\x00\\x00\...
Handles the output from downstream requests @param object $req @param string $appStatus @param string $protoStatus @return void
[ "Handles", "the", "output", "from", "downstream", "requests" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/FastCGI/Connection.php#L284-L303
kakserpom/phpdaemon
PHPDaemon/Servers/FastCGI/Connection.php
Connection.requestOut
public function requestOut($req, $out) { $cs = $this->pool->config->chunksize->value; if (mb_orig_strlen($out) > $cs) { while (($ol = mb_orig_strlen($out)) > 0) { $l = min($cs, $ol); if ($this->sendChunk($req, mb_orig_substr($out, 0, $l)) === false) { $req->abort(); return false; } $out = mb_orig_substr($out, $l); } } elseif ($this->sendChunk($req, $out) === false) { $req->abort(); return false; } return true; }
php
public function requestOut($req, $out) { $cs = $this->pool->config->chunksize->value; if (mb_orig_strlen($out) > $cs) { while (($ol = mb_orig_strlen($out)) > 0) { $l = min($cs, $ol); if ($this->sendChunk($req, mb_orig_substr($out, 0, $l)) === false) { $req->abort(); return false; } $out = mb_orig_substr($out, $l); } } elseif ($this->sendChunk($req, $out) === false) { $req->abort(); return false; } return true; }
[ "public", "function", "requestOut", "(", "$", "req", ",", "$", "out", ")", "{", "$", "cs", "=", "$", "this", "->", "pool", "->", "config", "->", "chunksize", "->", "value", ";", "if", "(", "mb_orig_strlen", "(", "$", "out", ")", ">", "$", "cs", "...
Handles the output from downstream requests @param object $req Request @param string $out The output @return boolean Success
[ "Handles", "the", "output", "from", "downstream", "requests" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/FastCGI/Connection.php#L311-L328
kakserpom/phpdaemon
PHPDaemon/Servers/FastCGI/Connection.php
Connection.sendChunk
public function sendChunk($req, $chunk) { $packet = "\x01" // protocol version . "\x06" // record type (STDOUT) . pack( 'nn', $req->attrs->id, mb_orig_strlen($chunk) ) // id, content length . "\x00" // padding length . "\x00";// reserved return $this->write($packet) && $this->write($chunk); // content }
php
public function sendChunk($req, $chunk) { $packet = "\x01" // protocol version . "\x06" // record type (STDOUT) . pack( 'nn', $req->attrs->id, mb_orig_strlen($chunk) ) // id, content length . "\x00" // padding length . "\x00";// reserved return $this->write($packet) && $this->write($chunk); // content }
[ "public", "function", "sendChunk", "(", "$", "req", ",", "$", "chunk", ")", "{", "$", "packet", "=", "\"\\x01\"", "// protocol version", ".", "\"\\x06\"", "// record type (STDOUT)", ".", "pack", "(", "'nn'", ",", "$", "req", "->", "attrs", "->", "id", ",",...
Sends a chunk @param object $req Request @param string $chunk Data @return bool
[ "Sends", "a", "chunk" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/FastCGI/Connection.php#L336-L349
kakserpom/phpdaemon
PHPDaemon/Servers/FastCGI/Connection.php
Connection.freeRequest
public function freeRequest($req) { $req->attrs->input = null; unset($this->requests[$req->attrs->id]); }
php
public function freeRequest($req) { $req->attrs->input = null; unset($this->requests[$req->attrs->id]); }
[ "public", "function", "freeRequest", "(", "$", "req", ")", "{", "$", "req", "->", "attrs", "->", "input", "=", "null", ";", "unset", "(", "$", "this", "->", "requests", "[", "$", "req", "->", "attrs", "->", "id", "]", ")", ";", "}" ]
Frees request @param object $req
[ "Frees", "request" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/FastCGI/Connection.php#L355-L359
kakserpom/phpdaemon
PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Basic/BasicGetFrame.php
BasicGetFrame.create
public static function create( $queue = null, $noAck = null ) { $frame = new self(); if (null !== $queue) { $frame->queue = $queue; } if (null !== $noAck) { $frame->noAck = $noAck; } return $frame; }
php
public static function create( $queue = null, $noAck = null ) { $frame = new self(); if (null !== $queue) { $frame->queue = $queue; } if (null !== $noAck) { $frame->noAck = $noAck; } return $frame; }
[ "public", "static", "function", "create", "(", "$", "queue", "=", "null", ",", "$", "noAck", "=", "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/Basic/BasicGetFrame.php#L22-L36
kakserpom/phpdaemon
PHPDaemon/Applications/GibsonREST/Request.php
Request.init
public function init() { try { $this->header('Content-Type: text/plain'); //$this->header('Content-Type: application/x-json'); } catch (\Exception $e) { } if (!$this->importCmdArgs()) { return; } $this->sleep(5, true); // setting timeout 5 seconds */ $this->onSessionStart(function () { $this->wakeup(); if ($this->cmd === 'LOGIN') { if (sizeof($this->args) !== 2) { $this->result = ['$err' => 'You must pass exactly 2 arguments.']; $this->wakeup(); return; } if ((hash_equals($this->appInstance->config->username->value, $this->args[0]) + hash_equals($this->appInstance->config->password->value, $this->args[1])) < 2) { $this->result = ['$err' => 'Wrong username and/or password.']; return; } $this->attrs->session['logged'] = $this->appInstance->config->credver; $this->result = ['$ok' => 1]; $this->wakeup(); return; } elseif ($this->cmd === 'LOGOUT') { unset($this->attrs->session['logged']); $this->result = ['$ok' => 1]; $this->wakeup(); return; } if (!isset($this->attrs->session['logged']) || $this->attrs->session['logged'] < $this->appInstance->config->credver) { $this->result = ['$err' => 'You must be authenticated.']; $this->wakeup(); return; } }); }
php
public function init() { try { $this->header('Content-Type: text/plain'); //$this->header('Content-Type: application/x-json'); } catch (\Exception $e) { } if (!$this->importCmdArgs()) { return; } $this->sleep(5, true); // setting timeout 5 seconds */ $this->onSessionStart(function () { $this->wakeup(); if ($this->cmd === 'LOGIN') { if (sizeof($this->args) !== 2) { $this->result = ['$err' => 'You must pass exactly 2 arguments.']; $this->wakeup(); return; } if ((hash_equals($this->appInstance->config->username->value, $this->args[0]) + hash_equals($this->appInstance->config->password->value, $this->args[1])) < 2) { $this->result = ['$err' => 'Wrong username and/or password.']; return; } $this->attrs->session['logged'] = $this->appInstance->config->credver; $this->result = ['$ok' => 1]; $this->wakeup(); return; } elseif ($this->cmd === 'LOGOUT') { unset($this->attrs->session['logged']); $this->result = ['$ok' => 1]; $this->wakeup(); return; } if (!isset($this->attrs->session['logged']) || $this->attrs->session['logged'] < $this->appInstance->config->credver) { $this->result = ['$err' => 'You must be authenticated.']; $this->wakeup(); return; } }); }
[ "public", "function", "init", "(", ")", "{", "try", "{", "$", "this", "->", "header", "(", "'Content-Type: text/plain'", ")", ";", "//$this->header('Content-Type: application/x-json');", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "}", "if", "(",...
/* Constructor. @return void
[ "/", "*", "Constructor", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Applications/GibsonREST/Request.php#L16-L57
kakserpom/phpdaemon
PHPDaemon/Applications/GibsonREST/Request.php
Request.importCmdArgs
protected function importCmdArgs() { $this->cmd = static::getString($_GET['cmd']); if ($this->cmd === '') { $e = explode('/', isset($this->attrs->server['SUBPATH']) ? $this->attrs->server['SUBPATH'] : $this->attrs->server['DOCUMENT_URI']); $this->cmd = array_shift($e); $this->args = sizeof($e) ? array_map('urldecode', $e) : []; } if (!$this->appInstance->gibson->isCommand($this->cmd) && $this->cmd !== 'LOGIN' && $this->cmd !== 'LOGOUT') { $this->result = ['$err' => 'Unrecognized command']; return false; } return true; }
php
protected function importCmdArgs() { $this->cmd = static::getString($_GET['cmd']); if ($this->cmd === '') { $e = explode('/', isset($this->attrs->server['SUBPATH']) ? $this->attrs->server['SUBPATH'] : $this->attrs->server['DOCUMENT_URI']); $this->cmd = array_shift($e); $this->args = sizeof($e) ? array_map('urldecode', $e) : []; } if (!$this->appInstance->gibson->isCommand($this->cmd) && $this->cmd !== 'LOGIN' && $this->cmd !== 'LOGOUT') { $this->result = ['$err' => 'Unrecognized command']; return false; } return true; }
[ "protected", "function", "importCmdArgs", "(", ")", "{", "$", "this", "->", "cmd", "=", "static", "::", "getString", "(", "$", "_GET", "[", "'cmd'", "]", ")", ";", "if", "(", "$", "this", "->", "cmd", "===", "''", ")", "{", "$", "e", "=", "explod...
/* Import command name and arguments from input @return void
[ "/", "*", "Import", "command", "name", "and", "arguments", "from", "input" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Applications/GibsonREST/Request.php#L63-L77
kakserpom/phpdaemon
PHPDaemon/Applications/GibsonREST/Request.php
Request.run
public function run() { if (!$this->performed && $this->result === null) { $this->performed = true; $this->importCmdArgsFromPost(); $this->performCommand(); if ($this->result === null) { $this->sleep(5); return; } } echo json_encode($this->result); }
php
public function run() { if (!$this->performed && $this->result === null) { $this->performed = true; $this->importCmdArgsFromPost(); $this->performCommand(); if ($this->result === null) { $this->sleep(5); return; } } echo json_encode($this->result); }
[ "public", "function", "run", "(", ")", "{", "if", "(", "!", "$", "this", "->", "performed", "&&", "$", "this", "->", "result", "===", "null", ")", "{", "$", "this", "->", "performed", "=", "true", ";", "$", "this", "->", "importCmdArgsFromPost", "(",...
Called when request iterated. @return integer Status.
[ "Called", "when", "request", "iterated", "." ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Applications/GibsonREST/Request.php#L88-L100
kakserpom/phpdaemon
PHPDaemon/Applications/GibsonREST/Request.php
Request.importCmdArgsFromPost
protected function importCmdArgsFromPost() { if ($this->result === null) { foreach (static::getArray($_POST['args']) as $arg) { if (is_string($arg)) { $this->args[] = $arg; } } } }
php
protected function importCmdArgsFromPost() { if ($this->result === null) { foreach (static::getArray($_POST['args']) as $arg) { if (is_string($arg)) { $this->args[] = $arg; } } } }
[ "protected", "function", "importCmdArgsFromPost", "(", ")", "{", "if", "(", "$", "this", "->", "result", "===", "null", ")", "{", "foreach", "(", "static", "::", "getArray", "(", "$", "_POST", "[", "'args'", "]", ")", "as", "$", "arg", ")", "{", "if"...
/* Performs command @return void
[ "/", "*", "Performs", "command" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Applications/GibsonREST/Request.php#L107-L116
kakserpom/phpdaemon
PHPDaemon/XMLStream/XMLStream.php
XMLStream.finish
public function finish() { $this->xml_depth = 0; $this->current_ns = []; $this->idhandlers = []; $this->xpathhandlers = []; $this->eventHandlers = []; }
php
public function finish() { $this->xml_depth = 0; $this->current_ns = []; $this->idhandlers = []; $this->xpathhandlers = []; $this->eventHandlers = []; }
[ "public", "function", "finish", "(", ")", "{", "$", "this", "->", "xml_depth", "=", "0", ";", "$", "this", "->", "current_ns", "=", "[", "]", ";", "$", "this", "->", "idhandlers", "=", "[", "]", ";", "$", "this", "->", "xpathhandlers", "=", "[", ...
Finishes the stream @return void
[ "Finishes", "the", "stream" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/XMLStream/XMLStream.php#L45-L52
kakserpom/phpdaemon
PHPDaemon/XMLStream/XMLStream.php
XMLStream.__destroy
public function __destroy() { if ($this->parser) { xml_parse($this->parser, '', true); xml_parser_free($this->parser); } }
php
public function __destroy() { if ($this->parser) { xml_parse($this->parser, '', true); xml_parser_free($this->parser); } }
[ "public", "function", "__destroy", "(", ")", "{", "if", "(", "$", "this", "->", "parser", ")", "{", "xml_parse", "(", "$", "this", "->", "parser", ",", "''", ",", "true", ")", ";", "xml_parser_free", "(", "$", "this", "->", "parser", ")", ";", "}",...
Destructor @return void
[ "Destructor" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/XMLStream/XMLStream.php#L58-L64
kakserpom/phpdaemon
PHPDaemon/XMLStream/XMLStream.php
XMLStream.startXML
public function startXML($parser, $name, $attr) { ++$this->xml_depth; if (array_key_exists('XMLNS', $attr)) { $this->current_ns[$this->xml_depth] = $attr['XMLNS']; } else { $this->current_ns[$this->xml_depth] = $this->current_ns[$this->xml_depth - 1]; if (!$this->current_ns[$this->xml_depth]) { $this->current_ns[$this->xml_depth] = $this->default_ns; } } $ns = $this->current_ns[$this->xml_depth]; foreach ($attr as $key => $value) { if (mb_orig_strpos($key, ':') !== false) { $key = explode(':', $key); $key = $key[1]; $this->ns_map[$key] = $value; } } if (mb_orig_strpos($name, ':') !== false) { $name = explode(':', $name); $ns = $this->ns_map[$name[0]]; $name = $name[1]; } $obj = new XMLStreamObject($name, $ns, $attr); if ($this->xml_depth > 1) { $this->xmlobj[$this->xml_depth - 1]->subs[] = $obj; } $this->xmlobj[$this->xml_depth] = $obj; }
php
public function startXML($parser, $name, $attr) { ++$this->xml_depth; if (array_key_exists('XMLNS', $attr)) { $this->current_ns[$this->xml_depth] = $attr['XMLNS']; } else { $this->current_ns[$this->xml_depth] = $this->current_ns[$this->xml_depth - 1]; if (!$this->current_ns[$this->xml_depth]) { $this->current_ns[$this->xml_depth] = $this->default_ns; } } $ns = $this->current_ns[$this->xml_depth]; foreach ($attr as $key => $value) { if (mb_orig_strpos($key, ':') !== false) { $key = explode(':', $key); $key = $key[1]; $this->ns_map[$key] = $value; } } if (mb_orig_strpos($name, ':') !== false) { $name = explode(':', $name); $ns = $this->ns_map[$name[0]]; $name = $name[1]; } $obj = new XMLStreamObject($name, $ns, $attr); if ($this->xml_depth > 1) { $this->xmlobj[$this->xml_depth - 1]->subs[] = $obj; } $this->xmlobj[$this->xml_depth] = $obj; }
[ "public", "function", "startXML", "(", "$", "parser", ",", "$", "name", ",", "$", "attr", ")", "{", "++", "$", "this", "->", "xml_depth", ";", "if", "(", "array_key_exists", "(", "'XMLNS'", ",", "$", "attr", ")", ")", "{", "$", "this", "->", "curre...
XML start callback @see xml_set_element_handler @param resource $parser @param string $name @param array $attr @return void
[ "XML", "start", "callback" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/XMLStream/XMLStream.php#L94-L123
kakserpom/phpdaemon
PHPDaemon/XMLStream/XMLStream.php
XMLStream.endXML
public function endXML($parser, $name) { --$this->xml_depth; if ($this->xml_depth === 1) { foreach ($this->xpathhandlers as $handler) { if (is_array($this->xmlobj) && array_key_exists(2, $this->xmlobj)) { $searchxml = $this->xmlobj[2]; $nstag = array_shift($handler[0]); if (($nstag[0] === null or $searchxml->ns === $nstag[0]) and ($nstag[1] === "*" or $nstag[1] === $searchxml->name)) { foreach ($handler[0] as $nstag) { if ($searchxml !== null and $searchxml->hasSub($nstag[1], $ns = $nstag[0])) { $searchxml = $searchxml->sub($nstag[1], $ns = $nstag[0]); } else { $searchxml = null; break; } } if ($searchxml !== null) { if ($handler[2] === null) { $handler[2] = $this; } $handler[1]($this->xmlobj[2]); } } } } foreach ($this->idhandlers as $id => $handler) { if (array_key_exists('id', $this->xmlobj[2]->attrs) and $this->xmlobj[2]->attrs['id'] == $id) { $handler($this->xmlobj[2]); #id handlers are only used once unset($this->idhandlers[$id]); break; } } if (is_array($this->xmlobj)) { $this->xmlobj = array_slice($this->xmlobj, 0, 1); if (isset($this->xmlobj[0]) && $this->xmlobj[0] instanceof XMLStreamObject) { $this->xmlobj[0]->subs = null; } } unset($this->xmlobj[2]); } if ($this->xml_depth === 0) { $this->event('streamEnd'); } }
php
public function endXML($parser, $name) { --$this->xml_depth; if ($this->xml_depth === 1) { foreach ($this->xpathhandlers as $handler) { if (is_array($this->xmlobj) && array_key_exists(2, $this->xmlobj)) { $searchxml = $this->xmlobj[2]; $nstag = array_shift($handler[0]); if (($nstag[0] === null or $searchxml->ns === $nstag[0]) and ($nstag[1] === "*" or $nstag[1] === $searchxml->name)) { foreach ($handler[0] as $nstag) { if ($searchxml !== null and $searchxml->hasSub($nstag[1], $ns = $nstag[0])) { $searchxml = $searchxml->sub($nstag[1], $ns = $nstag[0]); } else { $searchxml = null; break; } } if ($searchxml !== null) { if ($handler[2] === null) { $handler[2] = $this; } $handler[1]($this->xmlobj[2]); } } } } foreach ($this->idhandlers as $id => $handler) { if (array_key_exists('id', $this->xmlobj[2]->attrs) and $this->xmlobj[2]->attrs['id'] == $id) { $handler($this->xmlobj[2]); #id handlers are only used once unset($this->idhandlers[$id]); break; } } if (is_array($this->xmlobj)) { $this->xmlobj = array_slice($this->xmlobj, 0, 1); if (isset($this->xmlobj[0]) && $this->xmlobj[0] instanceof XMLStreamObject) { $this->xmlobj[0]->subs = null; } } unset($this->xmlobj[2]); } if ($this->xml_depth === 0) { $this->event('streamEnd'); } }
[ "public", "function", "endXML", "(", "$", "parser", ",", "$", "name", ")", "{", "--", "$", "this", "->", "xml_depth", ";", "if", "(", "$", "this", "->", "xml_depth", "===", "1", ")", "{", "foreach", "(", "$", "this", "->", "xpathhandlers", "as", "$...
XML end callback @see xml_set_element_handler @param resource $parser @param string $name @return void
[ "XML", "end", "callback" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/XMLStream/XMLStream.php#L134-L179
kakserpom/phpdaemon
PHPDaemon/XMLStream/XMLStream.php
XMLStream.addXPathHandler
public function addXPathHandler($xpath, $cb, $obj = null) { if (preg_match_all("/\(?{[^\}]+}\)?(\/?)[^\/]+/", $xpath, $regs)) { $ns_tags = $regs[0]; } else { $ns_tags = [$xpath]; } foreach ($ns_tags as $ns_tag) { list($l, $r) = explode("}", $ns_tag); if ($r !== null) { $xpart = [substr($l, 1), $r]; } else { $xpart = [null, $l]; } $xpath_array[] = $xpart; } $this->xpathhandlers[] = [$xpath_array, $cb, $obj, $xpath]; }
php
public function addXPathHandler($xpath, $cb, $obj = null) { if (preg_match_all("/\(?{[^\}]+}\)?(\/?)[^\/]+/", $xpath, $regs)) { $ns_tags = $regs[0]; } else { $ns_tags = [$xpath]; } foreach ($ns_tags as $ns_tag) { list($l, $r) = explode("}", $ns_tag); if ($r !== null) { $xpart = [substr($l, 1), $r]; } else { $xpart = [null, $l]; } $xpath_array[] = $xpart; } $this->xpathhandlers[] = [$xpath_array, $cb, $obj, $xpath]; }
[ "public", "function", "addXPathHandler", "(", "$", "xpath", ",", "$", "cb", ",", "$", "obj", "=", "null", ")", "{", "if", "(", "preg_match_all", "(", "\"/\\(?{[^\\}]+}\\)?(\\/?)[^\\/]+/\"", ",", "$", "xpath", ",", "$", "regs", ")", ")", "{", "$", "ns_tag...
Add XPath Handler @param string $xpath @param \Closure $cb @param null $obj
[ "Add", "XPath", "Handler" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/XMLStream/XMLStream.php#L227-L244
kakserpom/phpdaemon
PHPDaemon/BoundSocket/UDP.php
UDP.sendTo
public function sendTo($data, $flags, $host, $port) { return socket_sendto($this->fd, $data, mb_orig_strlen($data), $flags, $host, $port); }
php
public function sendTo($data, $flags, $host, $port) { return socket_sendto($this->fd, $data, mb_orig_strlen($data), $flags, $host, $port); }
[ "public", "function", "sendTo", "(", "$", "data", ",", "$", "flags", ",", "$", "host", ",", "$", "port", ")", "{", "return", "socket_sendto", "(", "$", "this", "->", "fd", ",", "$", "data", ",", "mb_orig_strlen", "(", "$", "data", ")", ",", "$", ...
Send UDP packet @param string $data Data @param integer $flags Flags @param string $host Host @param integer $port Port @return integer
[ "Send", "UDP", "packet" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/BoundSocket/UDP.php#L72-L75
kakserpom/phpdaemon
PHPDaemon/BoundSocket/UDP.php
UDP.bindSocket
public function bindSocket() { $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); if (!$sock) { $errno = socket_last_error(); Daemon::$process->log(get_class($this) . ': Couldn\'t create UDP-socket (' . $errno . ' - ' . socket_strerror($errno) . ').'); return false; } if (!isset($this->port)) { if (isset($this->defaultPort)) { $this->port = $this->defaultPort; } else { Daemon::log(get_class($this) . ' (' . get_class($this->pool) . '): no port defined for \'' . $this->uri['uri'] . '\''); } } if ($this->reuse) { if (!socket_set_option($sock, SOL_SOCKET, SO_REUSEADDR, 1)) { $errno = socket_last_error(); Daemon::$process->log(get_class($this) . ': Couldn\'t set option REUSEADDR to socket (' . $errno . ' - ' . socket_strerror($errno) . ').'); return false; } if (defined('SO_REUSEPORT') && !@socket_set_option($sock, SOL_SOCKET, SO_REUSEPORT, 1)) { $errno = socket_last_error(); Daemon::$process->log(get_class($this) . ': Couldn\'t set option REUSEPORT to socket (' . $errno . ' - ' . socket_strerror($errno) . ').'); return false; } } if (!@socket_bind($sock, $this->host, $this->port)) { $errno = socket_last_error(); $addr = $this->host . ':' . $this->port; Daemon::$process->log(get_class($this) . ': Couldn\'t bind UDP-socket \'' . $addr . '\' (' . $errno . ' - ' . socket_strerror($errno) . ').'); return false; } socket_getsockname($sock, $this->host, $this->port); $addr = $this->host . ':' . $this->port; socket_set_nonblock($sock); $this->setFd($sock); return true; }
php
public function bindSocket() { $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); if (!$sock) { $errno = socket_last_error(); Daemon::$process->log(get_class($this) . ': Couldn\'t create UDP-socket (' . $errno . ' - ' . socket_strerror($errno) . ').'); return false; } if (!isset($this->port)) { if (isset($this->defaultPort)) { $this->port = $this->defaultPort; } else { Daemon::log(get_class($this) . ' (' . get_class($this->pool) . '): no port defined for \'' . $this->uri['uri'] . '\''); } } if ($this->reuse) { if (!socket_set_option($sock, SOL_SOCKET, SO_REUSEADDR, 1)) { $errno = socket_last_error(); Daemon::$process->log(get_class($this) . ': Couldn\'t set option REUSEADDR to socket (' . $errno . ' - ' . socket_strerror($errno) . ').'); return false; } if (defined('SO_REUSEPORT') && !@socket_set_option($sock, SOL_SOCKET, SO_REUSEPORT, 1)) { $errno = socket_last_error(); Daemon::$process->log(get_class($this) . ': Couldn\'t set option REUSEPORT to socket (' . $errno . ' - ' . socket_strerror($errno) . ').'); return false; } } if (!@socket_bind($sock, $this->host, $this->port)) { $errno = socket_last_error(); $addr = $this->host . ':' . $this->port; Daemon::$process->log(get_class($this) . ': Couldn\'t bind UDP-socket \'' . $addr . '\' (' . $errno . ' - ' . socket_strerror($errno) . ').'); return false; } socket_getsockname($sock, $this->host, $this->port); $addr = $this->host . ':' . $this->port; socket_set_nonblock($sock); $this->setFd($sock); return true; }
[ "public", "function", "bindSocket", "(", ")", "{", "$", "sock", "=", "socket_create", "(", "AF_INET", ",", "SOCK_DGRAM", ",", "SOL_UDP", ")", ";", "if", "(", "!", "$", "sock", ")", "{", "$", "errno", "=", "socket_last_error", "(", ")", ";", "Daemon", ...
Bind given addreess @return boolean Success.
[ "Bind", "given", "addreess" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/BoundSocket/UDP.php#L101-L139
kakserpom/phpdaemon
PHPDaemon/BoundSocket/UDP.php
UDP.onBound
protected function onBound() { if (!$this->ev) { Daemon::log(get_class($this) . '::' . __METHOD__ . ': Couldn\'t set event on bound socket: ' . Debug::dump($this->fd)); return false; } return true; }
php
protected function onBound() { if (!$this->ev) { Daemon::log(get_class($this) . '::' . __METHOD__ . ': Couldn\'t set event on bound socket: ' . Debug::dump($this->fd)); return false; } return true; }
[ "protected", "function", "onBound", "(", ")", "{", "if", "(", "!", "$", "this", "->", "ev", ")", "{", "Daemon", "::", "log", "(", "get_class", "(", "$", "this", ")", ".", "'::'", ".", "__METHOD__", ".", "': Couldn\\'t set event on bound socket: '", ".", ...
Called when socket is bound @return boolean Success
[ "Called", "when", "socket", "is", "bound" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/BoundSocket/UDP.php#L145-L152
kakserpom/phpdaemon
PHPDaemon/BoundSocket/UDP.php
UDP.enable
public function enable() { if ($this->enabled) { return; } if (!$this->fd) { return; } $this->enabled = true; if ($this->ev === null) { if ($this->eventLoop === null) { // @TODO нужно перенести куда-то выше, не годиться тут инициировать $this->eventLoop = EventLoop::$instance; } $this->ev = $this->eventLoop->event($this->fd, \Event::READ | \Event::PERSIST, [$this, 'onReadUdp']); $this->onBound(); } else { $this->onAcceptEv(); } $this->ev->add(); }
php
public function enable() { if ($this->enabled) { return; } if (!$this->fd) { return; } $this->enabled = true; if ($this->ev === null) { if ($this->eventLoop === null) { // @TODO нужно перенести куда-то выше, не годиться тут инициировать $this->eventLoop = EventLoop::$instance; } $this->ev = $this->eventLoop->event($this->fd, \Event::READ | \Event::PERSIST, [$this, 'onReadUdp']); $this->onBound(); } else { $this->onAcceptEv(); } $this->ev->add(); }
[ "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/UDP.php#L158-L180
kakserpom/phpdaemon
PHPDaemon/BoundSocket/UDP.php
UDP.onReadUdp
public function onReadUdp($stream = null, $events = 0, $arg = null) { if (Daemon::$process->reload) { return false; } if ($this->pool->maxConcurrency) { if ($this->pool->count() >= $this->pool->maxConcurrency) { $this->overload = true; return false; } } $host = null; do { $l = @socket_recvfrom($this->fd, $buf, 10240, MSG_DONTWAIT, $host, $port); if (!$l) { break; } $key = '[' . $host . ']:' . $port; if (!isset($this->portsMap[$key])) { if ($this->pool->allowedClients !== null) { if (!self::netMatch($this->pool->allowedClients, $host)) { Daemon::log('Connection is not allowed (' . $host . ')'); } continue; } $class = $this->pool->connectionClass; $conn = new $class(null, $this->pool); $conn->setDgram(true); $conn->onWriteEv(null); $conn->setPeername($host, $port); $conn->setParentSocket($this); $this->portsMap[$key] = $conn; $conn->timeoutRef = setTimeout(function ($timer) use ($conn) { $conn->finish(); $timer->finish(); }, $conn->timeout * 1e6); $conn->onUdpPacket($buf); } else { $conn = $this->portsMap[$key]; $conn->onUdpPacket($buf); Timer::setTimeout($conn->timeoutRef); } } while (true); return $host !== null; }
php
public function onReadUdp($stream = null, $events = 0, $arg = null) { if (Daemon::$process->reload) { return false; } if ($this->pool->maxConcurrency) { if ($this->pool->count() >= $this->pool->maxConcurrency) { $this->overload = true; return false; } } $host = null; do { $l = @socket_recvfrom($this->fd, $buf, 10240, MSG_DONTWAIT, $host, $port); if (!$l) { break; } $key = '[' . $host . ']:' . $port; if (!isset($this->portsMap[$key])) { if ($this->pool->allowedClients !== null) { if (!self::netMatch($this->pool->allowedClients, $host)) { Daemon::log('Connection is not allowed (' . $host . ')'); } continue; } $class = $this->pool->connectionClass; $conn = new $class(null, $this->pool); $conn->setDgram(true); $conn->onWriteEv(null); $conn->setPeername($host, $port); $conn->setParentSocket($this); $this->portsMap[$key] = $conn; $conn->timeoutRef = setTimeout(function ($timer) use ($conn) { $conn->finish(); $timer->finish(); }, $conn->timeout * 1e6); $conn->onUdpPacket($buf); } else { $conn = $this->portsMap[$key]; $conn->onUdpPacket($buf); Timer::setTimeout($conn->timeoutRef); } } while (true); return $host !== null; }
[ "public", "function", "onReadUdp", "(", "$", "stream", "=", "null", ",", "$", "events", "=", "0", ",", "$", "arg", "=", "null", ")", "{", "if", "(", "Daemon", "::", "$", "process", "->", "reload", ")", "{", "return", "false", ";", "}", "if", "(",...
Called when we got UDP packet @param resource $stream Descriptor @param integer $events Events @param mixed $arg Attached variable @return boolean Success.
[ "Called", "when", "we", "got", "UDP", "packet" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/BoundSocket/UDP.php#L189-L235
kakserpom/phpdaemon
PHPDaemon/Core/ShellCommand.php
ShellCommand.exec
public static function exec($binPath = null, $cb = null, $args = null, $env = null) { $o = new static; $data = ''; $o->bind('read', function ($o) use (&$data) { $data .= $o->readUnlimited(); }); $o->bind('eof', function ($o) use (&$data, $cb) { $cb($o, $data); $o->close(); }); $o->execute($binPath, $args, $env); }
php
public static function exec($binPath = null, $cb = null, $args = null, $env = null) { $o = new static; $data = ''; $o->bind('read', function ($o) use (&$data) { $data .= $o->readUnlimited(); }); $o->bind('eof', function ($o) use (&$data, $cb) { $cb($o, $data); $o->close(); }); $o->execute($binPath, $args, $env); }
[ "public", "static", "function", "exec", "(", "$", "binPath", "=", "null", ",", "$", "cb", "=", "null", ",", "$", "args", "=", "null", ",", "$", "env", "=", "null", ")", "{", "$", "o", "=", "new", "static", ";", "$", "data", "=", "''", ";", "$...
Execute @param string $binPath Binpath @param callable $cb Callback @param array $args Optional. Arguments @param array $env Optional. Hash of environment's variables
[ "Execute" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/ShellCommand.php#L96-L108
kakserpom/phpdaemon
PHPDaemon/Core/ShellCommand.php
ShellCommand.execute
public function execute($binPath = null, $args = null, $env = null) { if ($binPath !== null) { $this->binPath = $binPath; } if ($env !== null) { $this->env = $env; } if ($args !== null) { $this->args = $args; } $this->cmd = $this->binPath . static::buildArgs($this->args) . ($this->outputErrors ? ' 2>&1' : ''); if (isset($this->setUser) || isset($this->setGroup)) { if (isset($this->setUser) && isset($this->setGroup) && ($this->setUser !== $this->setGroup)) { $this->cmd = 'sudo -g ' . escapeshellarg($this->setGroup) . ' -u ' . escapeshellarg($this->setUser) . ' ' . $this->cmd; } else { $this->cmd = 'su ' . escapeshellarg($this->setGroup) . ' -c ' . escapeshellarg($this->cmd); } } if ($this->chroot !== '/') { $this->cmd = 'chroot ' . escapeshellarg($this->chroot) . ' ' . $this->cmd; } if ($this->nice !== null) { $this->cmd = 'nice -n ' . ((int)$this->nice) . ' ' . $this->cmd; } $pipesDescr = [ 0 => ['pipe', 'r'], // stdin is a pipe that the child will read from 1 => ['pipe', 'w'] // stdout is a pipe that the child will write to ]; if (($this->errlogfile !== null) && !$this->outputErrors) { $pipesDescr[2] = ['file', $this->errlogfile, 'a']; // @TODO: refactoring } $this->pd = proc_open($this->cmd, $pipesDescr, $this->pipes, $this->cwd, $this->env); if ($this->pd) { $this->setFd($this->pipes[1]); } return $this; }
php
public function execute($binPath = null, $args = null, $env = null) { if ($binPath !== null) { $this->binPath = $binPath; } if ($env !== null) { $this->env = $env; } if ($args !== null) { $this->args = $args; } $this->cmd = $this->binPath . static::buildArgs($this->args) . ($this->outputErrors ? ' 2>&1' : ''); if (isset($this->setUser) || isset($this->setGroup)) { if (isset($this->setUser) && isset($this->setGroup) && ($this->setUser !== $this->setGroup)) { $this->cmd = 'sudo -g ' . escapeshellarg($this->setGroup) . ' -u ' . escapeshellarg($this->setUser) . ' ' . $this->cmd; } else { $this->cmd = 'su ' . escapeshellarg($this->setGroup) . ' -c ' . escapeshellarg($this->cmd); } } if ($this->chroot !== '/') { $this->cmd = 'chroot ' . escapeshellarg($this->chroot) . ' ' . $this->cmd; } if ($this->nice !== null) { $this->cmd = 'nice -n ' . ((int)$this->nice) . ' ' . $this->cmd; } $pipesDescr = [ 0 => ['pipe', 'r'], // stdin is a pipe that the child will read from 1 => ['pipe', 'w'] // stdout is a pipe that the child will write to ]; if (($this->errlogfile !== null) && !$this->outputErrors) { $pipesDescr[2] = ['file', $this->errlogfile, 'a']; // @TODO: refactoring } $this->pd = proc_open($this->cmd, $pipesDescr, $this->pipes, $this->cwd, $this->env); if ($this->pd) { $this->setFd($this->pipes[1]); } return $this; }
[ "public", "function", "execute", "(", "$", "binPath", "=", "null", ",", "$", "args", "=", "null", ",", "$", "env", "=", "null", ")", "{", "if", "(", "$", "binPath", "!==", "null", ")", "{", "$", "this", "->", "binPath", "=", "$", "binPath", ";", ...
Execute @param string $binPath Optional. Binpath @param array $args Optional. Arguments @param array $env Optional. Hash of environment's variables @return this
[ "Execute" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/ShellCommand.php#L117-L163
kakserpom/phpdaemon
PHPDaemon/Core/ShellCommand.php
ShellCommand.buildArgs
public static function buildArgs($args) { if (!is_array($args)) { return ''; } $ret = ''; foreach ($args as $k => $v) { if (!is_int($v) && ($v !== null)) { $v = escapeshellarg($v); } if (is_int($k)) { $ret .= ' ' . $v; } else { if ($k{0} !== '-') { $ret .= ' --' . $k . ($v !== null ? '=' . $v : ''); } else { $ret .= ' ' . $k . ($v !== null ? '=' . $v : ''); } } } return $ret; }
php
public static function buildArgs($args) { if (!is_array($args)) { return ''; } $ret = ''; foreach ($args as $k => $v) { if (!is_int($v) && ($v !== null)) { $v = escapeshellarg($v); } if (is_int($k)) { $ret .= ' ' . $v; } else { if ($k{0} !== '-') { $ret .= ' --' . $k . ($v !== null ? '=' . $v : ''); } else { $ret .= ' ' . $k . ($v !== null ? '=' . $v : ''); } } } return $ret; }
[ "public", "static", "function", "buildArgs", "(", "$", "args", ")", "{", "if", "(", "!", "is_array", "(", "$", "args", ")", ")", "{", "return", "''", ";", "}", "$", "ret", "=", "''", ";", "foreach", "(", "$", "args", "as", "$", "k", "=>", "$", ...
Build arguments string from associative/enumerated array (may be mixed) @param array $args @return string
[ "Build", "arguments", "string", "from", "associative", "/", "enumerated", "array", "(", "may", "be", "mixed", ")" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/ShellCommand.php#L170-L191
kakserpom/phpdaemon
PHPDaemon/Core/ShellCommand.php
ShellCommand.setFd
public function setFd($fd, $bev = null) { $this->fd = $fd; if ($fd === false) { $this->finish(); return; } $this->fdWrite = $this->pipes[0]; $flags = !is_resource($this->fd) ? \EventBufferEvent::OPT_CLOSE_ON_FREE : 0; $flags |= \EventBufferEvent::OPT_DEFER_CALLBACKS; // buggy option if ($this->eventLoop === null) { $this->eventLoop = EventLoop::$instance; } $this->bev = $this->eventLoop->bufferEvent( $this->fd, 0, [$this, 'onReadEv'], null, [$this, 'onStateEv'] ); $this->bevWrite = $this->eventLoop->bufferEvent( $this->fdWrite, 0, null, [$this, 'onWriteEv'], null ); if (!$this->bev || !$this->bevWrite) { $this->finish(); return; } if ($this->priority !== null) { $this->bev->priority = $this->priority; } if ($this->timeout !== null) { $this->setTimeout($this->timeout); } if (!$this->bev->enable(\Event::READ | \Event::TIMEOUT | \Event::PERSIST)) { $this->finish(); return; } if (!$this->bevWrite->enable(\Event::WRITE | \Event::TIMEOUT | \Event::PERSIST)) { $this->finish(); return; } $this->bev->setWatermark(\Event::READ, $this->lowMark, $this->highMark); init: if (!$this->inited) { $this->inited = true; $this->init(); } }
php
public function setFd($fd, $bev = null) { $this->fd = $fd; if ($fd === false) { $this->finish(); return; } $this->fdWrite = $this->pipes[0]; $flags = !is_resource($this->fd) ? \EventBufferEvent::OPT_CLOSE_ON_FREE : 0; $flags |= \EventBufferEvent::OPT_DEFER_CALLBACKS; // buggy option if ($this->eventLoop === null) { $this->eventLoop = EventLoop::$instance; } $this->bev = $this->eventLoop->bufferEvent( $this->fd, 0, [$this, 'onReadEv'], null, [$this, 'onStateEv'] ); $this->bevWrite = $this->eventLoop->bufferEvent( $this->fdWrite, 0, null, [$this, 'onWriteEv'], null ); if (!$this->bev || !$this->bevWrite) { $this->finish(); return; } if ($this->priority !== null) { $this->bev->priority = $this->priority; } if ($this->timeout !== null) { $this->setTimeout($this->timeout); } if (!$this->bev->enable(\Event::READ | \Event::TIMEOUT | \Event::PERSIST)) { $this->finish(); return; } if (!$this->bevWrite->enable(\Event::WRITE | \Event::TIMEOUT | \Event::PERSIST)) { $this->finish(); return; } $this->bev->setWatermark(\Event::READ, $this->lowMark, $this->highMark); init: if (!$this->inited) { $this->inited = true; $this->init(); } }
[ "public", "function", "setFd", "(", "$", "fd", ",", "$", "bev", "=", "null", ")", "{", "$", "this", "->", "fd", "=", "$", "fd", ";", "if", "(", "$", "fd", "===", "false", ")", "{", "$", "this", "->", "finish", "(", ")", ";", "return", ";", ...
Sets fd @param resource $fd File descriptor @param \EventBufferEvent $bev @return void
[ "Sets", "fd" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/ShellCommand.php#L199-L252
kakserpom/phpdaemon
PHPDaemon/Core/ShellCommand.php
ShellCommand.closeWrite
public function closeWrite() { if ($this->bevWrite) { if (isset($this->bevWrite)) { $this->bevWrite->free(); } $this->bevWrite = null; } if ($this->fdWrite) { fclose($this->fdWrite); $this->fdWrite = null; } return $this; }
php
public function closeWrite() { if ($this->bevWrite) { if (isset($this->bevWrite)) { $this->bevWrite->free(); } $this->bevWrite = null; } if ($this->fdWrite) { fclose($this->fdWrite); $this->fdWrite = null; } return $this; }
[ "public", "function", "closeWrite", "(", ")", "{", "if", "(", "$", "this", "->", "bevWrite", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "bevWrite", ")", ")", "{", "$", "this", "->", "bevWrite", "->", "free", "(", ")", ";", "}", "$", ...
Close write stream @return this
[ "Close", "write", "stream" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/ShellCommand.php#L361-L376
kakserpom/phpdaemon
PHPDaemon/Core/ShellCommand.php
ShellCommand.write
public function write($data) { if (!$this->alive) { Daemon::log('Attempt to write to dead IOStream (' . get_class($this) . ')'); return false; } if (!isset($this->bevWrite)) { return false; } if (!mb_orig_strlen($data)) { return true; } $this->writing = true; Daemon::$noError = true; if (!$this->bevWrite->write($data) || !Daemon::$noError) { $this->close(); return false; } return true; }
php
public function write($data) { if (!$this->alive) { Daemon::log('Attempt to write to dead IOStream (' . get_class($this) . ')'); return false; } if (!isset($this->bevWrite)) { return false; } if (!mb_orig_strlen($data)) { return true; } $this->writing = true; Daemon::$noError = true; if (!$this->bevWrite->write($data) || !Daemon::$noError) { $this->close(); return false; } return true; }
[ "public", "function", "write", "(", "$", "data", ")", "{", "if", "(", "!", "$", "this", "->", "alive", ")", "{", "Daemon", "::", "log", "(", "'Attempt to write to dead IOStream ('", ".", "get_class", "(", "$", "this", ")", ".", "')'", ")", ";", "return...
Send data to the connection. Note that it just writes to buffer that flushes at every baseloop @param string $data Data to send @return boolean Success
[ "Send", "data", "to", "the", "connection", ".", "Note", "that", "it", "just", "writes", "to", "buffer", "that", "flushes", "at", "every", "baseloop" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/ShellCommand.php#L414-L433
kakserpom/phpdaemon
PHPDaemon/Core/ShellCommand.php
ShellCommand.close
public function close() { parent::close(); $this->closeWrite(); if (is_resource($this->pd)) { proc_close($this->pd); } }
php
public function close() { parent::close(); $this->closeWrite(); if (is_resource($this->pd)) { proc_close($this->pd); } }
[ "public", "function", "close", "(", ")", "{", "parent", "::", "close", "(", ")", ";", "$", "this", "->", "closeWrite", "(", ")", ";", "if", "(", "is_resource", "(", "$", "this", "->", "pd", ")", ")", "{", "proc_close", "(", "$", "this", "->", "pd...
Close the process @return void
[ "Close", "the", "process" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/ShellCommand.php#L439-L446
kakserpom/phpdaemon
PHPDaemon/Core/ShellCommand.php
ShellCommand.writeln
public function writeln($data) { if (!$this->alive) { Daemon::log('Attempt to write to dead IOStream (' . get_class($this) . ')'); return false; } if (!isset($this->bevWrite)) { return false; } if (!mb_orig_strlen($data) && !mb_orig_strlen($this->EOL)) { return true; } $this->writing = true; $this->bevWrite->write($data); $this->bevWrite->write($this->EOL); return true; }
php
public function writeln($data) { if (!$this->alive) { Daemon::log('Attempt to write to dead IOStream (' . get_class($this) . ')'); return false; } if (!isset($this->bevWrite)) { return false; } if (!mb_orig_strlen($data) && !mb_orig_strlen($this->EOL)) { return true; } $this->writing = true; $this->bevWrite->write($data); $this->bevWrite->write($this->EOL); return true; }
[ "public", "function", "writeln", "(", "$", "data", ")", "{", "if", "(", "!", "$", "this", "->", "alive", ")", "{", "Daemon", "::", "log", "(", "'Attempt to write to dead IOStream ('", ".", "get_class", "(", "$", "this", ")", ".", "')'", ")", ";", "retu...
Send data and appending \n to connection. Note that it just writes to buffer flushed at every baseloop @param string Data to send @return boolean Success
[ "Send", "data", "and", "appending", "\\", "n", "to", "connection", ".", "Note", "that", "it", "just", "writes", "to", "buffer", "flushed", "at", "every", "baseloop" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/ShellCommand.php#L453-L469
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.setFd
public function setFd($fd, $bev = null) { if ($this->eventLoop === null) { $this->eventLoop = EventLoop::$instance; } $this->fd = $fd; if ($this->fd === false) { $this->finish(); return; } if ($bev !== null) { $this->bev = $bev; $this->bev->setCallbacks([$this, 'onReadEv'], [$this, 'onWriteEv'], [$this, 'onStateEv']); if (!$this->bev) { return; } $this->ready = true; $this->alive = true; } else { $flags = !is_resource($this->fd) ? \EventBufferEvent::OPT_CLOSE_ON_FREE : 0; $flags |= \EventBufferEvent::OPT_DEFER_CALLBACKS; /* buggy option */ if ($this->ctx) { if ($this->ctx instanceof \EventSslContext) { $this->bev = $this->eventLoop->bufferEventSsl( $this->fd, $this->ctx, $this->ctxMode, $flags ); if ($this->bev) { $this->bev->setCallbacks([$this, 'onReadEv'], [$this, 'onWriteEv'], [$this, 'onStateEv']); } $this->ssl = true; } else { $this->log('unsupported type of context: ' . ($this->ctx ? get_class($this->ctx) : 'undefined')); return; } } else { $this->bev = $this->eventLoop->bufferEvent( $this->fd, $flags, [$this, 'onReadEv'], [$this, 'onWriteEv'], [$this, 'onStateEv'] ); } if (!$this->bev) { return; } } if ($this->priority !== null) { $this->bev->priority = $this->priority; } $this->setTimeouts( $this->timeoutRead !== null ? $this->timeoutRead : $this->timeout, $this->timeoutWrite !== null ? $this->timeoutWrite : $this->timeout ); if ($this->bevConnect && ($this->fd === null)) { //$this->bev->connectHost(Daemon::$process->dnsBase, $this->hostReal, $this->port); $this->bev->connect($this->addr); } if (!$this->bev) { $this->finish(); return; } if (!$this->bev->enable(\Event::READ | \Event::WRITE | \Event::TIMEOUT | \Event::PERSIST)) { $this->finish(); return; } $this->bev->setWatermark(\Event::READ, $this->lowMark, $this->highMark); init: if ($this->keepalive && $this->fd != null) { $this->setKeepalive(true); } if (!$this->inited) { $this->inited = true; $this->init(); } }
php
public function setFd($fd, $bev = null) { if ($this->eventLoop === null) { $this->eventLoop = EventLoop::$instance; } $this->fd = $fd; if ($this->fd === false) { $this->finish(); return; } if ($bev !== null) { $this->bev = $bev; $this->bev->setCallbacks([$this, 'onReadEv'], [$this, 'onWriteEv'], [$this, 'onStateEv']); if (!$this->bev) { return; } $this->ready = true; $this->alive = true; } else { $flags = !is_resource($this->fd) ? \EventBufferEvent::OPT_CLOSE_ON_FREE : 0; $flags |= \EventBufferEvent::OPT_DEFER_CALLBACKS; /* buggy option */ if ($this->ctx) { if ($this->ctx instanceof \EventSslContext) { $this->bev = $this->eventLoop->bufferEventSsl( $this->fd, $this->ctx, $this->ctxMode, $flags ); if ($this->bev) { $this->bev->setCallbacks([$this, 'onReadEv'], [$this, 'onWriteEv'], [$this, 'onStateEv']); } $this->ssl = true; } else { $this->log('unsupported type of context: ' . ($this->ctx ? get_class($this->ctx) : 'undefined')); return; } } else { $this->bev = $this->eventLoop->bufferEvent( $this->fd, $flags, [$this, 'onReadEv'], [$this, 'onWriteEv'], [$this, 'onStateEv'] ); } if (!$this->bev) { return; } } if ($this->priority !== null) { $this->bev->priority = $this->priority; } $this->setTimeouts( $this->timeoutRead !== null ? $this->timeoutRead : $this->timeout, $this->timeoutWrite !== null ? $this->timeoutWrite : $this->timeout ); if ($this->bevConnect && ($this->fd === null)) { //$this->bev->connectHost(Daemon::$process->dnsBase, $this->hostReal, $this->port); $this->bev->connect($this->addr); } if (!$this->bev) { $this->finish(); return; } if (!$this->bev->enable(\Event::READ | \Event::WRITE | \Event::TIMEOUT | \Event::PERSIST)) { $this->finish(); return; } $this->bev->setWatermark(\Event::READ, $this->lowMark, $this->highMark); init: if ($this->keepalive && $this->fd != null) { $this->setKeepalive(true); } if (!$this->inited) { $this->inited = true; $this->init(); } }
[ "public", "function", "setFd", "(", "$", "fd", ",", "$", "bev", "=", "null", ")", "{", "if", "(", "$", "this", "->", "eventLoop", "===", "null", ")", "{", "$", "this", "->", "eventLoop", "=", "EventLoop", "::", "$", "instance", ";", "}", "$", "th...
Sets fd @param resource $fd File descriptor @param object $bev EventBufferEvent @return void
[ "Sets", "fd" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L276-L355
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.setTimeouts
public function setTimeouts($read, $write) { $this->timeoutRead = $read; $this->timeoutWrite = $write; if ($this->bev) { $this->bev->setTimeouts($this->timeoutRead, $this->timeoutWrite); } }
php
public function setTimeouts($read, $write) { $this->timeoutRead = $read; $this->timeoutWrite = $write; if ($this->bev) { $this->bev->setTimeouts($this->timeoutRead, $this->timeoutWrite); } }
[ "public", "function", "setTimeouts", "(", "$", "read", ",", "$", "write", ")", "{", "$", "this", "->", "timeoutRead", "=", "$", "read", ";", "$", "this", "->", "timeoutWrite", "=", "$", "write", ";", "if", "(", "$", "this", "->", "bev", ")", "{", ...
Set timeouts @param integer $read Read timeout in seconds @param integer $write Write timeout in seconds @return void
[ "Set", "timeouts" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L373-L380
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.setWatermark
public function setWatermark($low = null, $high = null) { if ($low !== null) { $this->lowMark = $low; } if ($high !== null) { $this->highMark = $high; } if ($this->highMark > 0) { $this->highMark = max($this->lowMark, $this->highMark); } $this->bev->setWatermark(\Event::READ, $this->lowMark, $this->highMark); }
php
public function setWatermark($low = null, $high = null) { if ($low !== null) { $this->lowMark = $low; } if ($high !== null) { $this->highMark = $high; } if ($this->highMark > 0) { $this->highMark = max($this->lowMark, $this->highMark); } $this->bev->setWatermark(\Event::READ, $this->lowMark, $this->highMark); }
[ "public", "function", "setWatermark", "(", "$", "low", "=", "null", ",", "$", "high", "=", "null", ")", "{", "if", "(", "$", "low", "!==", "null", ")", "{", "$", "this", "->", "lowMark", "=", "$", "low", ";", "}", "if", "(", "$", "high", "!==",...
Sets watermark @param integer|null $low Low @param integer|null $high High @return void
[ "Sets", "watermark" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L399-L411
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.readLine
public function readLine($eol = null) { if (!isset($this->bev)) { return null; } return $this->bev->input->readLine($eol ?: $this->EOLS); }
php
public function readLine($eol = null) { if (!isset($this->bev)) { return null; } return $this->bev->input->readLine($eol ?: $this->EOLS); }
[ "public", "function", "readLine", "(", "$", "eol", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "bev", ")", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "bev", "->", "input", "->", "readLine", "(",...
Reads line from buffer @param integer $eol EOLS_* @return string|null
[ "Reads", "line", "from", "buffer" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L426-L432
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.drainIfMatch
public function drainIfMatch($str) { if (!isset($this->bev)) { return false; } $in = $this->bev->input; $l = mb_orig_strlen($str); $ll = $in->length; if ($ll === 0) { return $l === 0 ? true : null; } if ($ll < $l) { return $in->search(substr($str, 0, $ll)) === 0 ? null : false; } if ($ll === $l) { if ($in->search($str) === 0) { $in->drain($l); return true; } } elseif ($in->search($str, 0, $l) === 0) { $in->drain($l); return true; } return false; }
php
public function drainIfMatch($str) { if (!isset($this->bev)) { return false; } $in = $this->bev->input; $l = mb_orig_strlen($str); $ll = $in->length; if ($ll === 0) { return $l === 0 ? true : null; } if ($ll < $l) { return $in->search(substr($str, 0, $ll)) === 0 ? null : false; } if ($ll === $l) { if ($in->search($str) === 0) { $in->drain($l); return true; } } elseif ($in->search($str, 0, $l) === 0) { $in->drain($l); return true; } return false; }
[ "public", "function", "drainIfMatch", "(", "$", "str", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "bev", ")", ")", "{", "return", "false", ";", "}", "$", "in", "=", "$", "this", "->", "bev", "->", "input", ";", "$", "l", "=", ...
Drains buffer it matches the string @param string $str Data @return boolean|null Success
[ "Drains", "buffer", "it", "matches", "the", "string" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L449-L473
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.prependInput
public function prependInput($str) { if (!isset($this->bev)) { return false; } return $this->bev->input->prepend($str); }
php
public function prependInput($str) { if (!isset($this->bev)) { return false; } return $this->bev->input->prepend($str); }
[ "public", "function", "prependInput", "(", "$", "str", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "bev", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "bev", "->", "input", "->", "prepend", "(", "$", "st...
Prepends data to input buffer @param string $str Data @return boolean Success
[ "Prepends", "data", "to", "input", "buffer" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L497-L503
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.prependOutput
public function prependOutput($str) { if (!isset($this->bev)) { return false; } return $this->bev->output->prepend($str); }
php
public function prependOutput($str) { if (!isset($this->bev)) { return false; } return $this->bev->output->prepend($str); }
[ "public", "function", "prependOutput", "(", "$", "str", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "bev", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "bev", "->", "output", "->", "prepend", "(", "$", "...
Prepends data to output buffer @param string $str Data @return boolean Success
[ "Prepends", "data", "to", "output", "buffer" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L510-L516
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.look
public function look($n, $o = 0) { if (!isset($this->bev)) { return false; } if ($this->bev->input->length <= $o) { return ''; } return $this->bev->input->substr($o, $n); }
php
public function look($n, $o = 0) { if (!isset($this->bev)) { return false; } if ($this->bev->input->length <= $o) { return ''; } return $this->bev->input->substr($o, $n); }
[ "public", "function", "look", "(", "$", "n", ",", "$", "o", "=", "0", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "bev", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "this", "->", "bev", "->", "input", "->", "l...
Read from buffer without draining @param integer $n Number of bytes to read @param integer $o Offset @return string|false
[ "Read", "from", "buffer", "without", "draining" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L524-L533
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.substr
public function substr($o, $n = -1) { if (!isset($this->bev)) { return false; } return $this->bev->input->substr($o, $n); }
php
public function substr($o, $n = -1) { if (!isset($this->bev)) { return false; } return $this->bev->input->substr($o, $n); }
[ "public", "function", "substr", "(", "$", "o", ",", "$", "n", "=", "-", "1", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "bev", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "bev", "->", "input", "->"...
Read from buffer without draining @param integer $o Offset @param integer $n Number of bytes to read @return string|false
[ "Read", "from", "buffer", "without", "draining" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L541-L547
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.search
public function search($what, $start = 0, $end = -1) { return $this->bev->input->search($what, $start, $end); }
php
public function search($what, $start = 0, $end = -1) { return $this->bev->input->search($what, $start, $end); }
[ "public", "function", "search", "(", "$", "what", ",", "$", "start", "=", "0", ",", "$", "end", "=", "-", "1", ")", "{", "return", "$", "this", "->", "bev", "->", "input", "->", "search", "(", "$", "what", ",", "$", "start", ",", "$", "end", ...
Searches first occurence of the string in input buffer @param string $what Needle @param integer $start Offset start @param integer $end Offset end @return integer Position
[ "Searches", "first", "occurence", "of", "the", "string", "in", "input", "buffer" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L556-L559
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.readExact
public function readExact($n) { if ($n === 0) { return ''; } if (!$this->bev || $this->bev->input->length < $n) { return false; } return $this->read($n); }
php
public function readExact($n) { if ($n === 0) { return ''; } if (!$this->bev || $this->bev->input->length < $n) { return false; } return $this->read($n); }
[ "public", "function", "readExact", "(", "$", "n", ")", "{", "if", "(", "$", "n", "===", "0", ")", "{", "return", "''", ";", "}", "if", "(", "!", "$", "this", "->", "bev", "||", "$", "this", "->", "bev", "->", "input", "->", "length", "<", "$"...
Reads exact $n bytes from buffer @param integer $n Number of bytes to read @return string|false
[ "Reads", "exact", "$n", "bytes", "from", "buffer" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L566-L575
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.freezeInput
public function freezeInput($at_front = true) { if (isset($this->bev)) { return $this->bev->input->freeze($at_front); } return false; }
php
public function freezeInput($at_front = true) { if (isset($this->bev)) { return $this->bev->input->freeze($at_front); } return false; }
[ "public", "function", "freezeInput", "(", "$", "at_front", "=", "true", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "bev", ")", ")", "{", "return", "$", "this", "->", "bev", "->", "input", "->", "freeze", "(", "$", "at_front", ")", ";", ...
Freeze input @param boolean $at_front At front. Default is true. If the front of a buffer is frozen, operations that drain data from the front of the buffer, or that prepend data to the buffer, will fail until it is unfrozen. If the back a buffer is frozen, operations that append data from the buffer will fail until it is unfrozen @return boolean Success
[ "Freeze", "input" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L601-L607
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.unfreezeInput
public function unfreezeInput($at_front = true) { if (isset($this->bev)) { return $this->bev->input->unfreeze($at_front); } return false; }
php
public function unfreezeInput($at_front = true) { if (isset($this->bev)) { return $this->bev->input->unfreeze($at_front); } return false; }
[ "public", "function", "unfreezeInput", "(", "$", "at_front", "=", "true", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "bev", ")", ")", "{", "return", "$", "this", "->", "bev", "->", "input", "->", "unfreeze", "(", "$", "at_front", ")", ";...
Unfreeze input @param boolean $at_front At front. Default is true. If the front of a buffer is frozen, operations that drain data from the front of the buffer, or that prepend data to the buffer, will fail until it is unfrozen. If the back a buffer is frozen, operations that append data from the buffer will fail until it is unfrozen @return boolean Success
[ "Unfreeze", "input" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L614-L620
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.freezeOutput
public function freezeOutput($at_front = true) { if (isset($this->bev)) { return $this->bev->output->unfreeze($at_front); } return false; }
php
public function freezeOutput($at_front = true) { if (isset($this->bev)) { return $this->bev->output->unfreeze($at_front); } return false; }
[ "public", "function", "freezeOutput", "(", "$", "at_front", "=", "true", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "bev", ")", ")", "{", "return", "$", "this", "->", "bev", "->", "output", "->", "unfreeze", "(", "$", "at_front", ")", ";...
Freeze output @param boolean $at_front At front. Default is true. If the front of a buffer is frozen, operations that drain data from the front of the buffer, or that prepend data to the buffer, will fail until it is unfrozen. If the back a buffer is frozen, operations that append data from the buffer will fail until it is unfrozen @return boolean Success
[ "Freeze", "output" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L627-L633
kakserpom/phpdaemon
PHPDaemon/Network/IOStream.php
IOStream.finish
public function finish() { if ($this->finished) { return; } $this->finished = true; $this->eventLoop->interrupt(); $this->onFinish(); if (!$this->writing) { $this->close(); } }
php
public function finish() { if ($this->finished) { return; } $this->finished = true; $this->eventLoop->interrupt(); $this->onFinish(); if (!$this->writing) { $this->close(); } }
[ "public", "function", "finish", "(", ")", "{", "if", "(", "$", "this", "->", "finished", ")", "{", "return", ";", "}", "$", "this", "->", "finished", "=", "true", ";", "$", "this", "->", "eventLoop", "->", "interrupt", "(", ")", ";", "$", "this", ...
Finish the session. You should not worry about buffers, they are going to be flushed properly @return void
[ "Finish", "the", "session", ".", "You", "should", "not", "worry", "about", "buffers", "they", "are", "going", "to", "be", "flushed", "properly" ]
train
https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/IOStream.php#L709-L720