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/Servers/WebSocket/Protocols/V13.php | V13.mask | public function mask($data, $mask)
{
for ($i = 0, $l = mb_orig_strlen($data), $ml = mb_orig_strlen($mask); $i < $l; $i++) {
$data[$i] = $data[$i] ^ $mask[$i % $ml];
}
return $data;
} | php | public function mask($data, $mask)
{
for ($i = 0, $l = mb_orig_strlen($data), $ml = mb_orig_strlen($mask); $i < $l; $i++) {
$data[$i] = $data[$i] ^ $mask[$i % $ml];
}
return $data;
} | [
"public",
"function",
"mask",
"(",
"$",
"data",
",",
"$",
"mask",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"l",
"=",
"mb_orig_strlen",
"(",
"$",
"data",
")",
",",
"$",
"ml",
"=",
"mb_orig_strlen",
"(",
"$",
"mask",
")",
";",
"$",
"... | Apply mask
@param $data
@param string|false $mask
@return mixed | [
"Apply",
"mask"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/WebSocket/Protocols/V13.php#L169-L175 |
kakserpom/phpdaemon | PHPDaemon/Servers/WebSocket/Protocols/V13.php | V13.onRead | public function onRead()
{
if ($this->state === self::STATE_PREHANDSHAKE) {
if (!$this->handshake()) {
return;
}
}
if ($this->state === self::STATE_HANDSHAKED) {
while (($buflen = $this->getInputLength()) >= 2) {
$first = ord($this->look(1)); // first byte integer (fin, opcode)
$firstBits = Binary::getbitmap($first);
$opcode = (int)bindec(substr($firstBits, 4, 4));
if ($opcode === 0x8) { // CLOSE
$this->finish();
return;
}
$opcodeName = isset(static::$opcodes[$opcode]) ? static::$opcodes[$opcode] : false;
if (!$opcodeName) {
Daemon::log(get_class($this) . ': Undefined opcode ' . $opcode);
$this->finish();
return;
}
if ($this->firstFrameOpcodeName === null) {
$this->firstFrameOpcodeName = $opcodeName;
}
$second = ord($this->look(1, 1)); // second byte integer (masked, payload length)
$fin = (bool)($first >> 7);
$isMasked = (bool)($second >> 7);
$dataLength = $second & 0x7f;
$p = 2;
if ($dataLength === 0x7e) { // 2 bytes-length
if ($buflen < $p + 2) {
return; // not enough data yet
}
$dataLength = Binary::bytes2int($this->look(2, $p), false);
$p += 2;
} elseif ($dataLength === 0x7f) { // 8 bytes-length
if ($buflen < $p + 8) {
return; // not enough data yet
}
$dataLength = Binary::bytes2int($this->look(8, $p));
$p += 8;
}
if ($this->pool->maxAllowedPacket <= $dataLength) {
// Too big packet
Daemon::log(get_class($this) . ': MaxAllowedPacket limit exceeded. Packet size ' . $dataLength . ' bytes when limit ' . $this->pool->maxAllowedPacket . ' bytes');
$this->finish();
return;
}
// Extend buffer size to accommodate all data
$this->setWatermark(null, $dataLength + 100);
if ($isMasked) {
if ($buflen < $p + 4) {
return; // not enough data yet
}
$mask = $this->look(4, $p);
$p += 4;
}
if ($buflen < $p + $dataLength) {
return; // not enough data yet
}
$this->drain($p);
$data = $this->read($dataLength);
if ($isMasked) {
$data = $this->mask($data, $mask);
}
//Daemon::log(Debug::dump(array('ext' => $this->extensions, 'rsv1' => $firstBits[1], 'data' => Debug::exportBytes($data))));
/*if ($firstBits[1] && in_array('deflate-frame', $this->extensions)) { // deflate frame
$data = gzuncompress($data, $this->pool->maxAllowedPacket);
}*/
if (!$fin) {
$this->framebuf .= $data;
} else {
$this->onFrame($this->framebuf . $data, $this->firstFrameOpcodeName);
$this->firstFrameOpcodeName = null;
$this->framebuf = '';
}
}
}
} | php | public function onRead()
{
if ($this->state === self::STATE_PREHANDSHAKE) {
if (!$this->handshake()) {
return;
}
}
if ($this->state === self::STATE_HANDSHAKED) {
while (($buflen = $this->getInputLength()) >= 2) {
$first = ord($this->look(1)); // first byte integer (fin, opcode)
$firstBits = Binary::getbitmap($first);
$opcode = (int)bindec(substr($firstBits, 4, 4));
if ($opcode === 0x8) { // CLOSE
$this->finish();
return;
}
$opcodeName = isset(static::$opcodes[$opcode]) ? static::$opcodes[$opcode] : false;
if (!$opcodeName) {
Daemon::log(get_class($this) . ': Undefined opcode ' . $opcode);
$this->finish();
return;
}
if ($this->firstFrameOpcodeName === null) {
$this->firstFrameOpcodeName = $opcodeName;
}
$second = ord($this->look(1, 1)); // second byte integer (masked, payload length)
$fin = (bool)($first >> 7);
$isMasked = (bool)($second >> 7);
$dataLength = $second & 0x7f;
$p = 2;
if ($dataLength === 0x7e) { // 2 bytes-length
if ($buflen < $p + 2) {
return; // not enough data yet
}
$dataLength = Binary::bytes2int($this->look(2, $p), false);
$p += 2;
} elseif ($dataLength === 0x7f) { // 8 bytes-length
if ($buflen < $p + 8) {
return; // not enough data yet
}
$dataLength = Binary::bytes2int($this->look(8, $p));
$p += 8;
}
if ($this->pool->maxAllowedPacket <= $dataLength) {
// Too big packet
Daemon::log(get_class($this) . ': MaxAllowedPacket limit exceeded. Packet size ' . $dataLength . ' bytes when limit ' . $this->pool->maxAllowedPacket . ' bytes');
$this->finish();
return;
}
// Extend buffer size to accommodate all data
$this->setWatermark(null, $dataLength + 100);
if ($isMasked) {
if ($buflen < $p + 4) {
return; // not enough data yet
}
$mask = $this->look(4, $p);
$p += 4;
}
if ($buflen < $p + $dataLength) {
return; // not enough data yet
}
$this->drain($p);
$data = $this->read($dataLength);
if ($isMasked) {
$data = $this->mask($data, $mask);
}
//Daemon::log(Debug::dump(array('ext' => $this->extensions, 'rsv1' => $firstBits[1], 'data' => Debug::exportBytes($data))));
/*if ($firstBits[1] && in_array('deflate-frame', $this->extensions)) { // deflate frame
$data = gzuncompress($data, $this->pool->maxAllowedPacket);
}*/
if (!$fin) {
$this->framebuf .= $data;
} else {
$this->onFrame($this->framebuf . $data, $this->firstFrameOpcodeName);
$this->firstFrameOpcodeName = null;
$this->framebuf = '';
}
}
}
} | [
"public",
"function",
"onRead",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"state",
"===",
"self",
"::",
"STATE_PREHANDSHAKE",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"handshake",
"(",
")",
")",
"{",
"return",
";",
"}",
"}",
"if",
"(",
"$"... | Called when new data received
@see http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10#page-16
@return void | [
"Called",
"when",
"new",
"data",
"received"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/WebSocket/Protocols/V13.php#L182-L261 |
kakserpom/phpdaemon | PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Parser/Frame.php | Frame.feed | public function feed($buffer, &$requiredBytes = 0)
{
$this->buffer .= $buffer;
$availableBytes = \strlen($this->buffer);
// not enough bytes for a frame ...
if ($availableBytes < $this->requiredBytes) {
$requiredBytes = $this->requiredBytes;
return null;
// we're still looking for the header ...
}
if ($this->requiredBytes === self::MINIMUM_FRAME_SIZE) {
// now that we know the payload size we can add that to the number
// of required bytes ...
$this->requiredBytes += \unpack(
'N',
mb_orig_substr(
$this->buffer,
self::HEADER_TYPE_SIZE + self::HEADER_CHANNEL_SIZE,
self::HEADER_PAYLOAD_LENGTH_SIZE
)
)[1];
// taking the payload into account we still don't have enough bytes
// for the frame ...
if ($availableBytes < $this->requiredBytes) {
$requiredBytes = $this->requiredBytes;
return null;
}
}
// we've got enough bytes, check that the last byte is the end marker ...
if (\ord($this->buffer[$this->requiredBytes - 1]) !== Constants::FRAME_END) {
throw new AMQPProtocolException(
sprintf(
'Frame end marker (0x%02x) is invalid.',
\ord($this->buffer[$this->requiredBytes - 1])
)
);
}
// read the (t)ype and (c)hannel then discard the header ...
$fields = \unpack('Ct/nc', $this->buffer);
$this->buffer = mb_orig_substr($this->buffer, self::HEADER_SIZE);
$type = $fields['t'];
// read the frame ...
if ($type === Constants::FRAME_METHOD) {
$frame = $this->parseMethodFrame();
} elseif ($type === Constants::FRAME_HEADER) {
$frame = $this->parseHeaderFrame();
} elseif ($type === Constants::FRAME_BODY) {
$length = $this->requiredBytes - self::MINIMUM_FRAME_SIZE;
$frame = new BodyFrame();
$frame->content = mb_orig_substr($this->buffer, 0, $length);
$this->buffer = mb_orig_substr($this->buffer, $length);
} elseif ($type === Constants::FRAME_HEARTBEAT) {
if (self::MINIMUM_FRAME_SIZE !== $this->requiredBytes) {
throw new AMQPProtocolException(
sprintf(
'Heartbeat frame payload size (%d) is invalid, must be zero.',
$this->requiredBytes - self::MINIMUM_FRAME_SIZE
)
);
}
$frame = new HeartbeatFrame();
} else {
throw new AMQPProtocolException(
sprintf(
'Frame type (0x%02x) is invalid.',
$type
)
);
}
// discard the end marker ...
$this->buffer = mb_orig_substr($this->buffer, 1);
$consumedBytes = $availableBytes - \strlen($this->buffer);
// the frame lied about its payload size ...
if ($consumedBytes !== $this->requiredBytes) {
throw new AMQPProtocolException(
sprintf(
'Mismatch between frame size (%s) and consumed bytes (%s).',
$this->requiredBytes,
$consumedBytes
)
);
}
$this->requiredBytes = $requiredBytes = self::MINIMUM_FRAME_SIZE;
$frame->frameChannelId = $fields['c'];
return $frame;
} | php | public function feed($buffer, &$requiredBytes = 0)
{
$this->buffer .= $buffer;
$availableBytes = \strlen($this->buffer);
// not enough bytes for a frame ...
if ($availableBytes < $this->requiredBytes) {
$requiredBytes = $this->requiredBytes;
return null;
// we're still looking for the header ...
}
if ($this->requiredBytes === self::MINIMUM_FRAME_SIZE) {
// now that we know the payload size we can add that to the number
// of required bytes ...
$this->requiredBytes += \unpack(
'N',
mb_orig_substr(
$this->buffer,
self::HEADER_TYPE_SIZE + self::HEADER_CHANNEL_SIZE,
self::HEADER_PAYLOAD_LENGTH_SIZE
)
)[1];
// taking the payload into account we still don't have enough bytes
// for the frame ...
if ($availableBytes < $this->requiredBytes) {
$requiredBytes = $this->requiredBytes;
return null;
}
}
// we've got enough bytes, check that the last byte is the end marker ...
if (\ord($this->buffer[$this->requiredBytes - 1]) !== Constants::FRAME_END) {
throw new AMQPProtocolException(
sprintf(
'Frame end marker (0x%02x) is invalid.',
\ord($this->buffer[$this->requiredBytes - 1])
)
);
}
// read the (t)ype and (c)hannel then discard the header ...
$fields = \unpack('Ct/nc', $this->buffer);
$this->buffer = mb_orig_substr($this->buffer, self::HEADER_SIZE);
$type = $fields['t'];
// read the frame ...
if ($type === Constants::FRAME_METHOD) {
$frame = $this->parseMethodFrame();
} elseif ($type === Constants::FRAME_HEADER) {
$frame = $this->parseHeaderFrame();
} elseif ($type === Constants::FRAME_BODY) {
$length = $this->requiredBytes - self::MINIMUM_FRAME_SIZE;
$frame = new BodyFrame();
$frame->content = mb_orig_substr($this->buffer, 0, $length);
$this->buffer = mb_orig_substr($this->buffer, $length);
} elseif ($type === Constants::FRAME_HEARTBEAT) {
if (self::MINIMUM_FRAME_SIZE !== $this->requiredBytes) {
throw new AMQPProtocolException(
sprintf(
'Heartbeat frame payload size (%d) is invalid, must be zero.',
$this->requiredBytes - self::MINIMUM_FRAME_SIZE
)
);
}
$frame = new HeartbeatFrame();
} else {
throw new AMQPProtocolException(
sprintf(
'Frame type (0x%02x) is invalid.',
$type
)
);
}
// discard the end marker ...
$this->buffer = mb_orig_substr($this->buffer, 1);
$consumedBytes = $availableBytes - \strlen($this->buffer);
// the frame lied about its payload size ...
if ($consumedBytes !== $this->requiredBytes) {
throw new AMQPProtocolException(
sprintf(
'Mismatch between frame size (%s) and consumed bytes (%s).',
$this->requiredBytes,
$consumedBytes
)
);
}
$this->requiredBytes = $requiredBytes = self::MINIMUM_FRAME_SIZE;
$frame->frameChannelId = $fields['c'];
return $frame;
} | [
"public",
"function",
"feed",
"(",
"$",
"buffer",
",",
"&",
"$",
"requiredBytes",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"buffer",
".=",
"$",
"buffer",
";",
"$",
"availableBytes",
"=",
"\\",
"strlen",
"(",
"$",
"this",
"->",
"buffer",
")",
";",
"//... | Retrieve the next frame from the internal buffer.
@param string $buffer Binary data to feed to the parser.
@param int &$requiredBytes The minimum number of bytes that must be
read to produce the next frame.
@return ProtocolFrameInterface|null The frame parsed from the start of the buffer.
@throws AMQPProtocolException The incoming data does not conform to the AMQP specification. | [
"Retrieve",
"the",
"next",
"frame",
"from",
"the",
"internal",
"buffer",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Parser/Frame.php#L76-L175 |
kakserpom/phpdaemon | PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Access/AccessRequestFrame.php | AccessRequestFrame.create | public static function create(
$realm = null, $exclusive = null, $passive = null, $active = null, $write = null, $read = null
)
{
$frame = new self();
if (null !== $realm) {
$frame->realm = $realm;
}
if (null !== $exclusive) {
$frame->exclusive = $exclusive;
}
if (null !== $passive) {
$frame->passive = $passive;
}
if (null !== $active) {
$frame->active = $active;
}
if (null !== $write) {
$frame->write = $write;
}
if (null !== $read) {
$frame->read = $read;
}
return $frame;
} | php | public static function create(
$realm = null, $exclusive = null, $passive = null, $active = null, $write = null, $read = null
)
{
$frame = new self();
if (null !== $realm) {
$frame->realm = $realm;
}
if (null !== $exclusive) {
$frame->exclusive = $exclusive;
}
if (null !== $passive) {
$frame->passive = $passive;
}
if (null !== $active) {
$frame->active = $active;
}
if (null !== $write) {
$frame->write = $write;
}
if (null !== $read) {
$frame->read = $read;
}
return $frame;
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"realm",
"=",
"null",
",",
"$",
"exclusive",
"=",
"null",
",",
"$",
"passive",
"=",
"null",
",",
"$",
"active",
"=",
"null",
",",
"$",
"write",
"=",
"null",
",",
"$",
"read",
"=",
"null",
")",
"... | bit | [
"bit"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Access/AccessRequestFrame.php#L25-L51 |
kakserpom/phpdaemon | PHPDaemon/Config/Entry/ConfigFile.php | ConfigFile.onUpdate | public function onUpdate($old)
{
if (!Daemon::$process instanceof Master || (Daemon::$config->autoreload->value === 0) || !$old) {
return;
}
$e = explode(';', $old);
foreach ($e as $path) {
Daemon::$process->fileWatcher->rmWatch($path, [Daemon::$process, 'sighup']);
}
$e = explode(';', $this->value);
foreach ($e as $path) {
Daemon::$process->fileWatcher->addWatch($path, [Daemon::$process, 'sighup']);
}
} | php | public function onUpdate($old)
{
if (!Daemon::$process instanceof Master || (Daemon::$config->autoreload->value === 0) || !$old) {
return;
}
$e = explode(';', $old);
foreach ($e as $path) {
Daemon::$process->fileWatcher->rmWatch($path, [Daemon::$process, 'sighup']);
}
$e = explode(';', $this->value);
foreach ($e as $path) {
Daemon::$process->fileWatcher->addWatch($path, [Daemon::$process, 'sighup']);
}
} | [
"public",
"function",
"onUpdate",
"(",
"$",
"old",
")",
"{",
"if",
"(",
"!",
"Daemon",
"::",
"$",
"process",
"instanceof",
"Master",
"||",
"(",
"Daemon",
"::",
"$",
"config",
"->",
"autoreload",
"->",
"value",
"===",
"0",
")",
"||",
"!",
"$",
"old",
... | Called when entry is updated
@param $old
@return void | [
"Called",
"when",
"entry",
"is",
"updated"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Config/Entry/ConfigFile.php#L23-L38 |
kakserpom/phpdaemon | PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Channel/ChannelFlowOkFrame.php | ChannelFlowOkFrame.create | public static function create(
$active = null
)
{
$frame = new self();
if (null !== $active) {
$frame->active = $active;
}
return $frame;
} | php | public static function create(
$active = null
)
{
$frame = new self();
if (null !== $active) {
$frame->active = $active;
}
return $frame;
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"active",
"=",
"null",
")",
"{",
"$",
"frame",
"=",
"new",
"self",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"active",
")",
"{",
"$",
"frame",
"->",
"active",
"=",
"$",
"active",
";",
"}",
... | bit | [
"bit"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Channel/ChannelFlowOkFrame.php#L21-L32 |
kakserpom/phpdaemon | PHPDaemon/Clients/Redis/Examples/Iterator.php | Iterator.onReady | public function onReady()
{
$this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance();
$this->redis->hmset('myset', 'field1', 'value1', 'field2', 'value2', 'field3', 'value3', 'field4', 'value4',
'field5', 'value5', function ($redis) {
$this->redis->hgetall('myset', function ($redis) {
D('TEST 1: HGETALL');
foreach ($redis as $key => $value) {
D($key . ' - ' . $value);
}
D($redis->assoc);
});
$this->redis->hmget('myset', 'field2', 'field4', function ($redis) {
D('TEST 2: HMGET');
foreach ($redis as $key => $value) {
D($key . ' - ' . $value);
}
D($redis->assoc);
});
});
$this->redis->zadd('myzset', 100, 'one', 150, 'two', 325, 'three', function ($redis) {
$this->redis->zrange('myzset', 0, -1, function ($redis) {
D('TEST 3: ZRANGE');
foreach ($redis as $key => $value) {
D($key . ' - ' . $value);
}
D($redis->assoc);
});
$this->redis->zrange('myzset', 0, -1, 'WITHSCORES', function ($redis) {
D('TEST 4: ZRANGE WITHSCORES');
foreach ($redis as $key => $value) {
D($key . ' - ' . $value);
}
D($redis->assoc);
});
});
$this->redis->subscribe('mysub', function ($redis) {
D('TEST 5: SUB & PUB');
foreach ($redis as $key => $value) {
D($key . ' - ' . $value);
}
D($redis->channel, $redis->msg, $redis->assoc);
});
$this->redis->publish('mysub', 'Test message!');
} | php | public function onReady()
{
$this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance();
$this->redis->hmset('myset', 'field1', 'value1', 'field2', 'value2', 'field3', 'value3', 'field4', 'value4',
'field5', 'value5', function ($redis) {
$this->redis->hgetall('myset', function ($redis) {
D('TEST 1: HGETALL');
foreach ($redis as $key => $value) {
D($key . ' - ' . $value);
}
D($redis->assoc);
});
$this->redis->hmget('myset', 'field2', 'field4', function ($redis) {
D('TEST 2: HMGET');
foreach ($redis as $key => $value) {
D($key . ' - ' . $value);
}
D($redis->assoc);
});
});
$this->redis->zadd('myzset', 100, 'one', 150, 'two', 325, 'three', function ($redis) {
$this->redis->zrange('myzset', 0, -1, function ($redis) {
D('TEST 3: ZRANGE');
foreach ($redis as $key => $value) {
D($key . ' - ' . $value);
}
D($redis->assoc);
});
$this->redis->zrange('myzset', 0, -1, 'WITHSCORES', function ($redis) {
D('TEST 4: ZRANGE WITHSCORES');
foreach ($redis as $key => $value) {
D($key . ' - ' . $value);
}
D($redis->assoc);
});
});
$this->redis->subscribe('mysub', function ($redis) {
D('TEST 5: SUB & PUB');
foreach ($redis as $key => $value) {
D($key . ' - ' . $value);
}
D($redis->channel, $redis->msg, $redis->assoc);
});
$this->redis->publish('mysub', 'Test message!');
} | [
"public",
"function",
"onReady",
"(",
")",
"{",
"$",
"this",
"->",
"redis",
"=",
"\\",
"PHPDaemon",
"\\",
"Clients",
"\\",
"Redis",
"\\",
"Pool",
"::",
"getInstance",
"(",
")",
";",
"$",
"this",
"->",
"redis",
"->",
"hmset",
"(",
"'myset'",
",",
"'fi... | Called when the worker is ready to go
@return void | [
"Called",
"when",
"the",
"worker",
"is",
"ready",
"to",
"go"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Redis/Examples/Iterator.php#L24-L74 |
kakserpom/phpdaemon | PHPDaemon/Clients/Redis/MultiEval.php | MultiEval.execute | public function execute()
{
if (!count($this->stack)) {
foreach ($this->listeners as $cb) {
$cb($this->pool);
}
return;
}
$params = $this->getParams();
$params[] = function ($redis) {
foreach ($this->listeners as $cb) {
$cb($redis);
}
};
$this->pool->eval(...$params);
} | php | public function execute()
{
if (!count($this->stack)) {
foreach ($this->listeners as $cb) {
$cb($this->pool);
}
return;
}
$params = $this->getParams();
$params[] = function ($redis) {
foreach ($this->listeners as $cb) {
$cb($redis);
}
};
$this->pool->eval(...$params);
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"if",
"(",
"!",
"count",
"(",
"$",
"this",
"->",
"stack",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"listeners",
"as",
"$",
"cb",
")",
"{",
"$",
"cb",
"(",
"$",
"this",
"->",
"pool",
")",
... | Runs the stack of commands | [
"Runs",
"the",
"stack",
"of",
"commands"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Redis/MultiEval.php#L89-L105 |
kakserpom/phpdaemon | PHPDaemon/Clients/Redis/MultiEval.php | MultiEval.getParams | public function getParams()
{
if ($this->cachedParams) {
return $this->cachedParams;
}
$CMDS = [];
$KEYS = [];
$ARGV = [];
$KEYNUM = 0;
$ARGNUM = 0;
foreach ($this->stack as $part) {
list($cmd, $keys, $argv) = $part;
if (!empty($keys)) {
$cmd = preg_replace_callback('~KEYS\[(\d+)\]~', function ($m) use (&$KEYS, &$KEYNUM, $keys) {
$key = $keys[$m[1] - 1];
if (!isset($KEYS[$key])) {
$KEYS[$key] = ++$KEYNUM;
}
return 'KEYS[' . $KEYS[$key] . ']';
}, $cmd);
}
if (!empty($argv)) {
$cmd = preg_replace_callback('~ARGV\[(\d+)\]~', function ($m) use (&$ARGV, &$ARGNUM, $argv) {
$arg = $argv[$m[1] - 1];
if (!isset($ARGV[$arg])) {
$ARGV[$arg] = ++$ARGNUM;
}
return 'ARGV[' . $ARGV[$arg] . ']';
}, $cmd);
}
$CMDS[] = $cmd;
}
return $this->cachedParams = array_merge(
[implode(';', $CMDS), count($KEYS)],
array_keys($KEYS),
array_keys($ARGV)
);
} | php | public function getParams()
{
if ($this->cachedParams) {
return $this->cachedParams;
}
$CMDS = [];
$KEYS = [];
$ARGV = [];
$KEYNUM = 0;
$ARGNUM = 0;
foreach ($this->stack as $part) {
list($cmd, $keys, $argv) = $part;
if (!empty($keys)) {
$cmd = preg_replace_callback('~KEYS\[(\d+)\]~', function ($m) use (&$KEYS, &$KEYNUM, $keys) {
$key = $keys[$m[1] - 1];
if (!isset($KEYS[$key])) {
$KEYS[$key] = ++$KEYNUM;
}
return 'KEYS[' . $KEYS[$key] . ']';
}, $cmd);
}
if (!empty($argv)) {
$cmd = preg_replace_callback('~ARGV\[(\d+)\]~', function ($m) use (&$ARGV, &$ARGNUM, $argv) {
$arg = $argv[$m[1] - 1];
if (!isset($ARGV[$arg])) {
$ARGV[$arg] = ++$ARGNUM;
}
return 'ARGV[' . $ARGV[$arg] . ']';
}, $cmd);
}
$CMDS[] = $cmd;
}
return $this->cachedParams = array_merge(
[implode(';', $CMDS), count($KEYS)],
array_keys($KEYS),
array_keys($ARGV)
);
} | [
"public",
"function",
"getParams",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cachedParams",
")",
"{",
"return",
"$",
"this",
"->",
"cachedParams",
";",
"}",
"$",
"CMDS",
"=",
"[",
"]",
";",
"$",
"KEYS",
"=",
"[",
"]",
";",
"$",
"ARGV",
"=",
... | Return params for eval command
@return array | [
"Return",
"params",
"for",
"eval",
"command"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Redis/MultiEval.php#L111-L154 |
kakserpom/phpdaemon | PHPDaemon/Clients/Redis/MultiEval.php | MultiEval.add | public function add($cmd, $keys = null, $argv = null)
{
if ($keys !== null) {
if (is_scalar($keys)) {
$keys = [(string)$keys];
} elseif (!is_array($keys)) {
throw new \Exception("Keys must be an array or scalar");
}
}
if ($argv !== null) {
if (is_scalar($argv)) {
$argv = [(string)$argv];
} elseif (!is_array($argv)) {
throw new \Exception("Argv must be an array or scalar");
}
}
$this->cachedParams = false;
$this->stack[] = [$cmd, $keys, $argv];
} | php | public function add($cmd, $keys = null, $argv = null)
{
if ($keys !== null) {
if (is_scalar($keys)) {
$keys = [(string)$keys];
} elseif (!is_array($keys)) {
throw new \Exception("Keys must be an array or scalar");
}
}
if ($argv !== null) {
if (is_scalar($argv)) {
$argv = [(string)$argv];
} elseif (!is_array($argv)) {
throw new \Exception("Argv must be an array or scalar");
}
}
$this->cachedParams = false;
$this->stack[] = [$cmd, $keys, $argv];
} | [
"public",
"function",
"add",
"(",
"$",
"cmd",
",",
"$",
"keys",
"=",
"null",
",",
"$",
"argv",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"keys",
"!==",
"null",
")",
"{",
"if",
"(",
"is_scalar",
"(",
"$",
"keys",
")",
")",
"{",
"$",
"keys",
"=",
... | Adds eval command in stack
@param string $cmd Lua script
@param mixed $keys Keys
@param mixed $argv Arguments | [
"Adds",
"eval",
"command",
"in",
"stack"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Redis/MultiEval.php#L162-L181 |
kakserpom/phpdaemon | PHPDaemon/Clients/IRC/Connection.php | Connection.onReady | public function onReady()
{
if ($this->pool->identd) {
/** @noinspection PhpParamsInspection */
$this->getSocketName();
$this->pool->identd->registerPair($this->locAddr, $this->locPort, ['UNIX', $this->user]);
}
list($this->nick, $this->realname) = explode('/', $this->path . '/John Doe');
$this->command('USER', $this->user, 0, '*', $this->realname);
$this->command('NICK', $this->nick);
if (mb_orig_strlen($this->password)) {
$this->message('NickServ', 'IDENTIFY ' . $this->password);
}
} | php | public function onReady()
{
if ($this->pool->identd) {
/** @noinspection PhpParamsInspection */
$this->getSocketName();
$this->pool->identd->registerPair($this->locAddr, $this->locPort, ['UNIX', $this->user]);
}
list($this->nick, $this->realname) = explode('/', $this->path . '/John Doe');
$this->command('USER', $this->user, 0, '*', $this->realname);
$this->command('NICK', $this->nick);
if (mb_orig_strlen($this->password)) {
$this->message('NickServ', 'IDENTIFY ' . $this->password);
}
} | [
"public",
"function",
"onReady",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"pool",
"->",
"identd",
")",
"{",
"/** @noinspection PhpParamsInspection */",
"$",
"this",
"->",
"getSocketName",
"(",
")",
";",
"$",
"this",
"->",
"pool",
"->",
"identd",
"->",
... | Called when the connection is handshaked (at low-level), and peer is ready to recv. data
@return void | [
"Called",
"when",
"the",
"connection",
"is",
"handshaked",
"(",
"at",
"low",
"-",
"level",
")",
"and",
"peer",
"is",
"ready",
"to",
"recv",
".",
"data"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/IRC/Connection.php#L85-L98 |
kakserpom/phpdaemon | PHPDaemon/Clients/IRC/Connection.php | Connection.onFinish | public function onFinish()
{
if ($this->pool->identd) {
$this->pool->identd->unregisterPair($this->locPort, $this->port);
}
$this->event('disconnect');
parent::onFinish();
} | php | public function onFinish()
{
if ($this->pool->identd) {
$this->pool->identd->unregisterPair($this->locPort, $this->port);
}
$this->event('disconnect');
parent::onFinish();
} | [
"public",
"function",
"onFinish",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"pool",
"->",
"identd",
")",
"{",
"$",
"this",
"->",
"pool",
"->",
"identd",
"->",
"unregisterPair",
"(",
"$",
"this",
"->",
"locPort",
",",
"$",
"this",
"->",
"port",
"... | Called when connection finishes
@return void | [
"Called",
"when",
"connection",
"finishes"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/IRC/Connection.php#L184-L191 |
kakserpom/phpdaemon | PHPDaemon/Clients/IRC/Connection.php | Connection.onRead | public function onRead()
{
while (($line = $this->readline()) !== null) {
if ($line === '') {
continue;
}
if (mb_orig_strlen($line) > 512) {
Daemon::$process->log('IRCClientConnection error: buffer overflow.');
$this->finish();
return;
}
$line = mb_orig_substr($line, 0, -mb_orig_strlen($this->EOL));
$p = mb_orig_strpos($line, ' :', 1);
$max = $p !== false ? substr_count($line, "\x20", 0, $p + 1) + 1 : 18;
$e = explode("\x20", $line, $max);
$i = 0;
$from = IRC::parseUsermask($e[$i]{0} === ':' ? mb_orig_substr($e[$i++], 1) : null);
$cmd = $e[$i++];
$args = [];
for ($s = min(sizeof($e), 14); $i < $s; ++$i) {
if ($e[$i][0] === ':') {
$args[] = mb_orig_substr($e[$i], 1);
break;
}
$args[] = $e[$i];
}
if (ctype_digit($cmd)) {
$code = (int)$cmd;
$cmd = isset(IRC::$codes[$code]) ? IRC::$codes[$code] : $code;
}
$this->lastLine = $line;
$this->onCommand($from, $cmd, $args);
}
if (mb_orig_strlen($this->buf) > 512) {
Daemon::$process->log('IRCClientConnection error: buffer overflow.');
$this->finish();
}
} | php | public function onRead()
{
while (($line = $this->readline()) !== null) {
if ($line === '') {
continue;
}
if (mb_orig_strlen($line) > 512) {
Daemon::$process->log('IRCClientConnection error: buffer overflow.');
$this->finish();
return;
}
$line = mb_orig_substr($line, 0, -mb_orig_strlen($this->EOL));
$p = mb_orig_strpos($line, ' :', 1);
$max = $p !== false ? substr_count($line, "\x20", 0, $p + 1) + 1 : 18;
$e = explode("\x20", $line, $max);
$i = 0;
$from = IRC::parseUsermask($e[$i]{0} === ':' ? mb_orig_substr($e[$i++], 1) : null);
$cmd = $e[$i++];
$args = [];
for ($s = min(sizeof($e), 14); $i < $s; ++$i) {
if ($e[$i][0] === ':') {
$args[] = mb_orig_substr($e[$i], 1);
break;
}
$args[] = $e[$i];
}
if (ctype_digit($cmd)) {
$code = (int)$cmd;
$cmd = isset(IRC::$codes[$code]) ? IRC::$codes[$code] : $code;
}
$this->lastLine = $line;
$this->onCommand($from, $cmd, $args);
}
if (mb_orig_strlen($this->buf) > 512) {
Daemon::$process->log('IRCClientConnection error: buffer overflow.');
$this->finish();
}
} | [
"public",
"function",
"onRead",
"(",
")",
"{",
"while",
"(",
"(",
"$",
"line",
"=",
"$",
"this",
"->",
"readline",
"(",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"$",
"line",
"===",
"''",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"mb_orig_... | Called when new data received
@return void | [
"Called",
"when",
"new",
"data",
"received"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/IRC/Connection.php#L397-L436 |
kakserpom/phpdaemon | PHPDaemon/Clients/MySQL/Pool.php | Pool.values | public static function values($arr)
{
if (!is_array($arr)) {
return '';
}
$arr = array_values($arr);
foreach ($arr as &$v) {
$v = static::value($v);
}
return implode(',', $arr);
} | php | public static function values($arr)
{
if (!is_array($arr)) {
return '';
}
$arr = array_values($arr);
foreach ($arr as &$v) {
$v = static::value($v);
}
return implode(',', $arr);
} | [
"public",
"static",
"function",
"values",
"(",
"$",
"arr",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"arr",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"arr",
"=",
"array_values",
"(",
"$",
"arr",
")",
";",
"foreach",
"(",
"$",
"arr",
"... | [values description]
@param array $arr
@return string | [
"[",
"values",
"description",
"]"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/MySQL/Pool.php#L296-L306 |
kakserpom/phpdaemon | PHPDaemon/Clients/MySQL/Pool.php | Pool.value | public static function value($mixed)
{
if (is_string($mixed)) {
return '\'' . static::escape($mixed) . '\'';
} elseif (is_integer($mixed)) {
return (string)$mixed;
} elseif (is_float($mixed)) {
return '\'' . $mixed . '\'';
}
return 'null';
} | php | public static function value($mixed)
{
if (is_string($mixed)) {
return '\'' . static::escape($mixed) . '\'';
} elseif (is_integer($mixed)) {
return (string)$mixed;
} elseif (is_float($mixed)) {
return '\'' . $mixed . '\'';
}
return 'null';
} | [
"public",
"static",
"function",
"value",
"(",
"$",
"mixed",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"mixed",
")",
")",
"{",
"return",
"'\\''",
".",
"static",
"::",
"escape",
"(",
"$",
"mixed",
")",
".",
"'\\''",
";",
"}",
"elseif",
"(",
"is_int... | [value description]
@param mixed $mixed
@return string | [
"[",
"value",
"description",
"]"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/MySQL/Pool.php#L313-L323 |
kakserpom/phpdaemon | PHPDaemon/Thread/Generic.php | Generic.sighandler | public function sighandler($signo)
{
if (!isset(self::$signals[$signo])) {
$this->log('caught unknown signal #' . $signo);
return;
}
if (method_exists($this, $m = strtolower(self::$signals[$signo]))) {
$this->$m();
} elseif (method_exists($this, 'sigunknown')) {
$this->sigunknown($signo);
}
} | php | public function sighandler($signo)
{
if (!isset(self::$signals[$signo])) {
$this->log('caught unknown signal #' . $signo);
return;
}
if (method_exists($this, $m = strtolower(self::$signals[$signo]))) {
$this->$m();
} elseif (method_exists($this, 'sigunknown')) {
$this->sigunknown($signo);
}
} | [
"public",
"function",
"sighandler",
"(",
"$",
"signo",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"signals",
"[",
"$",
"signo",
"]",
")",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"'caught unknown signal #'",
".",
"$",
"signo",
")",
... | Called when the signal is caught
@param integer Signal's number
@return void | [
"Called",
"when",
"the",
"signal",
"is",
"caught"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Thread/Generic.php#L185-L196 |
kakserpom/phpdaemon | PHPDaemon/Thread/Generic.php | Generic.start | public function start($clearstack = true)
{
$pid = \pcntl_fork();
if ($pid === -1) {
throw new \Exception('Could not fork');
} elseif ($pid === 0) { // we are the child
$thread = $this;
$thread->pid = \posix_getpid();
if (!$thread->delayedSigReg) {
$thread->registerSignals();
}
if ($clearstack) {
throw new ClearStack('', 0, $thread);
} else {
$thread->run();
$thread->shutdown();
}
} else { // we are the master
$this->pid = $pid;
}
} | php | public function start($clearstack = true)
{
$pid = \pcntl_fork();
if ($pid === -1) {
throw new \Exception('Could not fork');
} elseif ($pid === 0) { // we are the child
$thread = $this;
$thread->pid = \posix_getpid();
if (!$thread->delayedSigReg) {
$thread->registerSignals();
}
if ($clearstack) {
throw new ClearStack('', 0, $thread);
} else {
$thread->run();
$thread->shutdown();
}
} else { // we are the master
$this->pid = $pid;
}
} | [
"public",
"function",
"start",
"(",
"$",
"clearstack",
"=",
"true",
")",
"{",
"$",
"pid",
"=",
"\\",
"pcntl_fork",
"(",
")",
";",
"if",
"(",
"$",
"pid",
"===",
"-",
"1",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Could not fork'",
")",
";"... | Starts the process
@return void | [
"Starts",
"the",
"process"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Thread/Generic.php#L202-L223 |
kakserpom/phpdaemon | PHPDaemon/Thread/Generic.php | Generic.registerSignals | protected function registerSignals()
{
foreach (self::$signals as $no => $name) {
if (($name === 'SIGKILL') || ($name == 'SIGSTOP')) {
continue;
}
if (!\pcntl_signal($no, [$this, 'sighandler'], true)) {
$this->log('Cannot assign ' . $name . ' signal');
}
}
} | php | protected function registerSignals()
{
foreach (self::$signals as $no => $name) {
if (($name === 'SIGKILL') || ($name == 'SIGSTOP')) {
continue;
}
if (!\pcntl_signal($no, [$this, 'sighandler'], true)) {
$this->log('Cannot assign ' . $name . ' signal');
}
}
} | [
"protected",
"function",
"registerSignals",
"(",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"signals",
"as",
"$",
"no",
"=>",
"$",
"name",
")",
"{",
"if",
"(",
"(",
"$",
"name",
"===",
"'SIGKILL'",
")",
"||",
"(",
"$",
"name",
"==",
"'SIGSTOP'",
... | Registers signals
@return void | [
"Registers",
"signals"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Thread/Generic.php#L229-L240 |
kakserpom/phpdaemon | PHPDaemon/Thread/Generic.php | Generic.sleep | public function sleep($s)
{
static $interval = 0.2;
$n = $s / $interval;
for ($i = 0; $i < $n; ++$i) {
if ($this->shutdown) {
return false;
}
\usleep($interval * 1000000);
}
return true;
} | php | public function sleep($s)
{
static $interval = 0.2;
$n = $s / $interval;
for ($i = 0; $i < $n; ++$i) {
if ($this->shutdown) {
return false;
}
\usleep($interval * 1000000);
}
return true;
} | [
"public",
"function",
"sleep",
"(",
"$",
"s",
")",
"{",
"static",
"$",
"interval",
"=",
"0.2",
";",
"$",
"n",
"=",
"$",
"s",
"/",
"$",
"interval",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"n",
";",
"++",
"$",
"i",
")"... | Delays the process execution for the given number of seconds
@param integer Sleep time in seconds
@return boolean Success | [
"Delays",
"the",
"process",
"execution",
"for",
"the",
"given",
"number",
"of",
"seconds"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Thread/Generic.php#L247-L261 |
kakserpom/phpdaemon | PHPDaemon/Thread/Generic.php | Generic.stop | public function stop($kill = false)
{
$this->shutdown = true;
\posix_kill($this->pid, $kill ? SIGKILL : SIGTERM);
} | php | public function stop($kill = false)
{
$this->shutdown = true;
\posix_kill($this->pid, $kill ? SIGKILL : SIGTERM);
} | [
"public",
"function",
"stop",
"(",
"$",
"kill",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"shutdown",
"=",
"true",
";",
"\\",
"posix_kill",
"(",
"$",
"this",
"->",
"pid",
",",
"$",
"kill",
"?",
"SIGKILL",
":",
"SIGTERM",
")",
";",
"}"
] | Terminates the process
@param boolean Kill?
@return void | [
"Terminates",
"the",
"process"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Thread/Generic.php#L268-L272 |
kakserpom/phpdaemon | PHPDaemon/Thread/Generic.php | Generic.registerEventSignals | protected function registerEventSignals()
{
if (!EventLoop::$instance) {
return;
}
foreach (self::$signals as $no => $name) {
if ($name === 'SIGKILL' || $name == 'SIGSTOP') {
continue;
}
$ev = EventLoop::$instance->signal($no, [$this, 'eventSighandler'], [$no]);
if (!$ev) {
$this->log('Cannot event_set for ' . $name . ' signal');
}
$ev->add();
$this->sigEvents[$no] = $ev;
}
} | php | protected function registerEventSignals()
{
if (!EventLoop::$instance) {
return;
}
foreach (self::$signals as $no => $name) {
if ($name === 'SIGKILL' || $name == 'SIGSTOP') {
continue;
}
$ev = EventLoop::$instance->signal($no, [$this, 'eventSighandler'], [$no]);
if (!$ev) {
$this->log('Cannot event_set for ' . $name . ' signal');
}
$ev->add();
$this->sigEvents[$no] = $ev;
}
} | [
"protected",
"function",
"registerEventSignals",
"(",
")",
"{",
"if",
"(",
"!",
"EventLoop",
"::",
"$",
"instance",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"self",
"::",
"$",
"signals",
"as",
"$",
"no",
"=>",
"$",
"name",
")",
"{",
"if",
"(",
... | Register signals.
@return void | [
"Register",
"signals",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Thread/Generic.php#L297-L314 |
kakserpom/phpdaemon | PHPDaemon/Thread/Generic.php | Generic.unregisterSignals | protected function unregisterSignals()
{
foreach ($this->sigEvents as $no => $ev) {
$ev->free();
unset($this->sigEvents[$no]);
}
} | php | protected function unregisterSignals()
{
foreach ($this->sigEvents as $no => $ev) {
$ev->free();
unset($this->sigEvents[$no]);
}
} | [
"protected",
"function",
"unregisterSignals",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"sigEvents",
"as",
"$",
"no",
"=>",
"$",
"ev",
")",
"{",
"$",
"ev",
"->",
"free",
"(",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"sigEvents",
"[",
"$",... | Unregister signals.
@return void | [
"Unregister",
"signals",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Thread/Generic.php#L320-L326 |
kakserpom/phpdaemon | PHPDaemon/Thread/Generic.php | Generic.waitPid | protected function waitPid()
{
start:
$pid = \pcntl_waitpid(-1, $status, WNOHANG);
if ($pid > 0) {
foreach ($this->collections as $col) {
foreach ($col->threads as $k => $t) {
if ($t->pid === $pid) {
$t->setTerminated();
unset($col->threads[$k]);
goto start;
}
}
}
}
return false;
} | php | protected function waitPid()
{
start:
$pid = \pcntl_waitpid(-1, $status, WNOHANG);
if ($pid > 0) {
foreach ($this->collections as $col) {
foreach ($col->threads as $k => $t) {
if ($t->pid === $pid) {
$t->setTerminated();
unset($col->threads[$k]);
goto start;
}
}
}
}
return false;
} | [
"protected",
"function",
"waitPid",
"(",
")",
"{",
"start",
":",
"$",
"pid",
"=",
"\\",
"pcntl_waitpid",
"(",
"-",
"1",
",",
"$",
"status",
",",
"WNOHANG",
")",
";",
"if",
"(",
"$",
"pid",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
... | Checks for SIGCHLD
@return boolean Success | [
"Checks",
"for",
"SIGCHLD"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Thread/Generic.php#L351-L368 |
kakserpom/phpdaemon | PHPDaemon/Thread/Generic.php | Generic.waitAll | protected function waitAll($check)
{
do {
$n = 0;
foreach ($this->collections as &$col) {
$n += $col->removeTerminated($check);
}
if (!$this->waitPid()) {
$this->sigwait(0, 20000);
}
} while ($n > 0);
} | php | protected function waitAll($check)
{
do {
$n = 0;
foreach ($this->collections as &$col) {
$n += $col->removeTerminated($check);
}
if (!$this->waitPid()) {
$this->sigwait(0, 20000);
}
} while ($n > 0);
} | [
"protected",
"function",
"waitAll",
"(",
"$",
"check",
")",
"{",
"do",
"{",
"$",
"n",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"collections",
"as",
"&",
"$",
"col",
")",
"{",
"$",
"n",
"+=",
"$",
"col",
"->",
"removeTerminated",
"(",
"$"... | Waits until children is alive
@param boolean $check
@return void | [
"Waits",
"until",
"children",
"is",
"alive"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Thread/Generic.php#L411-L423 |
kakserpom/phpdaemon | PHPDaemon/Thread/Generic.php | Generic.sigwait | protected function sigwait($sec = 0, $nano = 0.3e9)
{
$siginfo = null;
if (!function_exists('pcntl_sigtimedwait')) {
$signo = $this->sigtimedwait(array_keys(static::$signals), $siginfo, $sec, $nano);
} else {
$signo = @\pcntl_sigtimedwait(array_keys(static::$signals), $siginfo, $sec, $nano);
}
if (is_bool($signo)) {
return $signo;
}
if ($signo > 0) {
$this->sighandler($signo);
return true;
}
return false;
} | php | protected function sigwait($sec = 0, $nano = 0.3e9)
{
$siginfo = null;
if (!function_exists('pcntl_sigtimedwait')) {
$signo = $this->sigtimedwait(array_keys(static::$signals), $siginfo, $sec, $nano);
} else {
$signo = @\pcntl_sigtimedwait(array_keys(static::$signals), $siginfo, $sec, $nano);
}
if (is_bool($signo)) {
return $signo;
}
if ($signo > 0) {
$this->sighandler($signo);
return true;
}
return false;
} | [
"protected",
"function",
"sigwait",
"(",
"$",
"sec",
"=",
"0",
",",
"$",
"nano",
"=",
"0.3e9",
")",
"{",
"$",
"siginfo",
"=",
"null",
";",
"if",
"(",
"!",
"function_exists",
"(",
"'pcntl_sigtimedwait'",
")",
")",
"{",
"$",
"signo",
"=",
"$",
"this",
... | Waits for signals, with a timeout
@param int Seconds
@param int Nanoseconds
@return boolean Success | [
"Waits",
"for",
"signals",
"with",
"a",
"timeout"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Thread/Generic.php#L431-L452 |
kakserpom/phpdaemon | PHPDaemon/Thread/Generic.php | Generic.sigtimedwait | protected function sigtimedwait($signals, $siginfo, $sec, $nano)
{
\pcntl_signal_dispatch();
if (\time_nanosleep($sec, $nano) === true) {
return false;
}
\pcntl_signal_dispatch();
return true;
} | php | protected function sigtimedwait($signals, $siginfo, $sec, $nano)
{
\pcntl_signal_dispatch();
if (\time_nanosleep($sec, $nano) === true) {
return false;
}
\pcntl_signal_dispatch();
return true;
} | [
"protected",
"function",
"sigtimedwait",
"(",
"$",
"signals",
",",
"$",
"siginfo",
",",
"$",
"sec",
",",
"$",
"nano",
")",
"{",
"\\",
"pcntl_signal_dispatch",
"(",
")",
";",
"if",
"(",
"\\",
"time_nanosleep",
"(",
"$",
"sec",
",",
"$",
"nano",
")",
"... | Implementation of pcntl_sigtimedwait for Mac.
@param array Signal
@param null|array SigInfo
@param int Seconds
@param int Nanoseconds
@param integer $sec
@param double $nano
@return boolean Success | [
"Implementation",
"of",
"pcntl_sigtimedwait",
"for",
"Mac",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Thread/Generic.php#L465-L473 |
kakserpom/phpdaemon | PHPDaemon/Network/Connection.php | Connection.setPeername | public function setPeername($host, $port)
{
$this->host = $host;
$this->port = $port;
$this->addr = '[' . $this->host . ']:' . $this->port;
if ($this->pool->allowedClients !== null) {
if (!TCP::netMatch($this->pool->allowedClients, $this->host)) {
Daemon::log('Connection is not allowed (' . $this->host . ')');
$this->ready = false;
$this->finish();
}
}
} | php | public function setPeername($host, $port)
{
$this->host = $host;
$this->port = $port;
$this->addr = '[' . $this->host . ']:' . $this->port;
if ($this->pool->allowedClients !== null) {
if (!TCP::netMatch($this->pool->allowedClients, $this->host)) {
Daemon::log('Connection is not allowed (' . $this->host . ')');
$this->ready = false;
$this->finish();
}
}
} | [
"public",
"function",
"setPeername",
"(",
"$",
"host",
",",
"$",
"port",
")",
"{",
"$",
"this",
"->",
"host",
"=",
"$",
"host",
";",
"$",
"this",
"->",
"port",
"=",
"$",
"port",
";",
"$",
"this",
"->",
"addr",
"=",
"'['",
".",
"$",
"this",
"->"... | Sets peer name
@param string $host Hostname
@param integer $port Port
@return void | [
"Sets",
"peer",
"name"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Connection.php#L179-L191 |
kakserpom/phpdaemon | PHPDaemon/Network/Connection.php | Connection.getSocketName | public function getSocketName(&$addr, &$port)
{
if (func_num_args() === 0) {
\EventUtil::getSocketName($this->bev->fd, $this->locAddr, $this->locPort);
return;
}
\EventUtil::getSocketName($this->bev->fd, $addr, $port);
} | php | public function getSocketName(&$addr, &$port)
{
if (func_num_args() === 0) {
\EventUtil::getSocketName($this->bev->fd, $this->locAddr, $this->locPort);
return;
}
\EventUtil::getSocketName($this->bev->fd, $addr, $port);
} | [
"public",
"function",
"getSocketName",
"(",
"&",
"$",
"addr",
",",
"&",
"$",
"port",
")",
"{",
"if",
"(",
"func_num_args",
"(",
")",
"===",
"0",
")",
"{",
"\\",
"EventUtil",
"::",
"getSocketName",
"(",
"$",
"this",
"->",
"bev",
"->",
"fd",
",",
"$"... | Get socket name
@param string &$addr Addr
@param srting &$port Port
@return void | [
"Get",
"socket",
"name"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Connection.php#L216-L223 |
kakserpom/phpdaemon | PHPDaemon/Network/Connection.php | Connection.onReady | public function onReady()
{
$this->connected = true;
if ($this->onConnected) {
$this->onConnected->executeAll($this);
$this->onConnected = null;
}
} | php | public function onReady()
{
$this->connected = true;
if ($this->onConnected) {
$this->onConnected->executeAll($this);
$this->onConnected = null;
}
} | [
"public",
"function",
"onReady",
"(",
")",
"{",
"$",
"this",
"->",
"connected",
"=",
"true",
";",
"if",
"(",
"$",
"this",
"->",
"onConnected",
")",
"{",
"$",
"this",
"->",
"onConnected",
"->",
"executeAll",
"(",
"$",
"this",
")",
";",
"$",
"this",
... | 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/Connection.php#L248-L255 |
kakserpom/phpdaemon | PHPDaemon/Network/Connection.php | Connection.onFailure | public function onFailure()
{
if ($this->onConnected) {
$this->onConnected->executeAll($this);
$this->onConnected = null;
}
} | php | public function onFailure()
{
if ($this->onConnected) {
$this->onConnected->executeAll($this);
$this->onConnected = null;
}
} | [
"public",
"function",
"onFailure",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"onConnected",
")",
"{",
"$",
"this",
"->",
"onConnected",
"->",
"executeAll",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"onConnected",
"=",
"null",
";",
"}",
"}"
] | Called when the connection failed to be established
@return void | [
"Called",
"when",
"the",
"connection",
"failed",
"to",
"be",
"established"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Connection.php#L270-L276 |
kakserpom/phpdaemon | PHPDaemon/Network/Connection.php | Connection.onFailureEv | public function onFailureEv($bev = null)
{
try {
if (!$this->connected && !$this->failed) {
$this->failed = true;
$this->onFailure();
}
$this->connected = false;
} catch (\Exception $e) {
Daemon::uncaughtExceptionHandler($e);
}
} | php | public function onFailureEv($bev = null)
{
try {
if (!$this->connected && !$this->failed) {
$this->failed = true;
$this->onFailure();
}
$this->connected = false;
} catch (\Exception $e) {
Daemon::uncaughtExceptionHandler($e);
}
} | [
"public",
"function",
"onFailureEv",
"(",
"$",
"bev",
"=",
"null",
")",
"{",
"try",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"connected",
"&&",
"!",
"$",
"this",
"->",
"failed",
")",
"{",
"$",
"this",
"->",
"failed",
"=",
"true",
";",
"$",
"this",... | Called when the connection failed
@param EventBufferEvent $bev
@return void | [
"Called",
"when",
"the",
"connection",
"failed"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Connection.php#L283-L294 |
kakserpom/phpdaemon | PHPDaemon/Network/Connection.php | Connection.write | public function write($data)
{
if ($this->dgram) {
return $this->parentSocket->sendTo($data, $this->finished ? MSG_EOF : 0, $this->host, $this->port);
}
return parent::write($data);
} | php | public function write($data)
{
if ($this->dgram) {
return $this->parentSocket->sendTo($data, $this->finished ? MSG_EOF : 0, $this->host, $this->port);
}
return parent::write($data);
} | [
"public",
"function",
"write",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dgram",
")",
"{",
"return",
"$",
"this",
"->",
"parentSocket",
"->",
"sendTo",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"finished",
"?",
"MSG_EOF",
":",
"0",... | 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/Network/Connection.php#L312-L318 |
kakserpom/phpdaemon | PHPDaemon/Network/Connection.php | Connection.onConnected | public function onConnected($cb)
{
if ($this->connected) {
$cb($this);
} else {
if (!$this->onConnected) {
$this->onConnected = new StackCallbacks;
}
$this->onConnected->push($cb);
}
} | php | public function onConnected($cb)
{
if ($this->connected) {
$cb($this);
} else {
if (!$this->onConnected) {
$this->onConnected = new StackCallbacks;
}
$this->onConnected->push($cb);
}
} | [
"public",
"function",
"onConnected",
"(",
"$",
"cb",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"connected",
")",
"{",
"$",
"cb",
"(",
"$",
"this",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"onConnected",
")",
"{",
"$",
"this"... | Executes the given callback when/if the connection is handshaked
@param callable $cb Callback
@return void | [
"Executes",
"the",
"given",
"callback",
"when",
"/",
"if",
"the",
"connection",
"is",
"handshaked"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Connection.php#L325-L335 |
kakserpom/phpdaemon | PHPDaemon/Network/Connection.php | Connection.initSSLContext | protected function initSSLContext()
{
if (!\EventUtil::sslRandPoll()) {
Daemon::$process->log(get_class($this->pool) . ': EventUtil::sslRandPoll failed');
return false;
}
$params = [
\EventSslContext::OPT_VERIFY_PEER => $this->verifypeer,
\EventSslContext::OPT_ALLOW_SELF_SIGNED => $this->allowselfsigned,
];
if ($this->certfile !== null) {
$params[\EventSslContext::OPT_LOCAL_CERT] = $this->certfile;
}
if ($this->pkfile !== null) {
$params[\EventSslContext::OPT_LOCAL_PK] = $this->pkfile;
}
if ($this->passphrase !== null) {
$params[\EventSslContext::OPT_PASSPHRASE] = $this->passphrase;
}
$hash = igbinary_serialize($params);
if (!self::$contextCache) {
self::$contextCache = new CappedStorageHits(self::$contextCacheSize);
} elseif ($ctx = self::$contextCache->getValue($hash)) {
return $ctx;
}
$ctx = new \EventSslContext(\EventSslContext::TLS_CLIENT_METHOD, $params);
self::$contextCache->put($hash, $ctx);
return $ctx;
} | php | protected function initSSLContext()
{
if (!\EventUtil::sslRandPoll()) {
Daemon::$process->log(get_class($this->pool) . ': EventUtil::sslRandPoll failed');
return false;
}
$params = [
\EventSslContext::OPT_VERIFY_PEER => $this->verifypeer,
\EventSslContext::OPT_ALLOW_SELF_SIGNED => $this->allowselfsigned,
];
if ($this->certfile !== null) {
$params[\EventSslContext::OPT_LOCAL_CERT] = $this->certfile;
}
if ($this->pkfile !== null) {
$params[\EventSslContext::OPT_LOCAL_PK] = $this->pkfile;
}
if ($this->passphrase !== null) {
$params[\EventSslContext::OPT_PASSPHRASE] = $this->passphrase;
}
$hash = igbinary_serialize($params);
if (!self::$contextCache) {
self::$contextCache = new CappedStorageHits(self::$contextCacheSize);
} elseif ($ctx = self::$contextCache->getValue($hash)) {
return $ctx;
}
$ctx = new \EventSslContext(\EventSslContext::TLS_CLIENT_METHOD, $params);
self::$contextCache->put($hash, $ctx);
return $ctx;
} | [
"protected",
"function",
"initSSLContext",
"(",
")",
"{",
"if",
"(",
"!",
"\\",
"EventUtil",
"::",
"sslRandPoll",
"(",
")",
")",
"{",
"Daemon",
"::",
"$",
"process",
"->",
"log",
"(",
"get_class",
"(",
"$",
"this",
"->",
"pool",
")",
".",
"': EventUtil... | Initialize SSL context
@return object|false Context | [
"Initialize",
"SSL",
"context"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Connection.php#L376-L404 |
kakserpom/phpdaemon | PHPDaemon/Network/Connection.php | Connection.connect | public function connect($url, $cb = null)
{
$this->uri = Config\_Object::parseCfgUri($url);
$u =& $this->uri;
if (!$u) {
return false;
}
$this->importParams();
if (!isset($u['port'])) {
if ($this->ssl) {
if (isset($this->pool->config->sslport->value)) {
$u['port'] = $this->pool->config->sslport->value;
}
} else {
if (isset($this->pool->config->port->value)) {
$u['port'] = $this->pool->config->port->value;
}
}
}
if (isset($u['user'])) {
$this->user = $u['user'];
}
if ($this->ssl) {
$this->setContext($this->initSSLContext(), \EventBufferEvent::SSL_CONNECTING);
}
$this->url = $url;
$this->scheme = strtolower($u['scheme']);
$this->host = isset($u['host']) ? $u['host'] : null;
$this->port = isset($u['port']) ? $u['port'] : 0;
if (isset($u['pass'])) {
$this->password = $u['pass'];
}
if (isset($u['path'])) {
$this->path = ltrim($u['path'], '/');
}
if ($cb !== null) {
$this->onConnected($cb);
}
if ($this->scheme === 'unix') {
return $this->connectUnix($u['path']);
}
if ($this->scheme === 'raw') {
return $this->connectRaw($u['host']);
}
if ($this->scheme === 'udp') {
return $this->connectUdp($this->host, $this->port);
}
if ($this->scheme === 'tcp') {
return $this->connectTcp($this->host, $this->port);
}
Daemon::log(get_class($this) . ': connect(): unrecoginized scheme \'' . $this->scheme . '\' (not unix/raw/udp/tcp) in URL: ' . $url);
return false;
} | php | public function connect($url, $cb = null)
{
$this->uri = Config\_Object::parseCfgUri($url);
$u =& $this->uri;
if (!$u) {
return false;
}
$this->importParams();
if (!isset($u['port'])) {
if ($this->ssl) {
if (isset($this->pool->config->sslport->value)) {
$u['port'] = $this->pool->config->sslport->value;
}
} else {
if (isset($this->pool->config->port->value)) {
$u['port'] = $this->pool->config->port->value;
}
}
}
if (isset($u['user'])) {
$this->user = $u['user'];
}
if ($this->ssl) {
$this->setContext($this->initSSLContext(), \EventBufferEvent::SSL_CONNECTING);
}
$this->url = $url;
$this->scheme = strtolower($u['scheme']);
$this->host = isset($u['host']) ? $u['host'] : null;
$this->port = isset($u['port']) ? $u['port'] : 0;
if (isset($u['pass'])) {
$this->password = $u['pass'];
}
if (isset($u['path'])) {
$this->path = ltrim($u['path'], '/');
}
if ($cb !== null) {
$this->onConnected($cb);
}
if ($this->scheme === 'unix') {
return $this->connectUnix($u['path']);
}
if ($this->scheme === 'raw') {
return $this->connectRaw($u['host']);
}
if ($this->scheme === 'udp') {
return $this->connectUdp($this->host, $this->port);
}
if ($this->scheme === 'tcp') {
return $this->connectTcp($this->host, $this->port);
}
Daemon::log(get_class($this) . ': connect(): unrecoginized scheme \'' . $this->scheme . '\' (not unix/raw/udp/tcp) in URL: ' . $url);
return false;
} | [
"public",
"function",
"connect",
"(",
"$",
"url",
",",
"$",
"cb",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"uri",
"=",
"Config",
"\\",
"_Object",
"::",
"parseCfgUri",
"(",
"$",
"url",
")",
";",
"$",
"u",
"=",
"&",
"$",
"this",
"->",
"uri",
";"... | Connects to URL
@param string $url URL
@param callable $cb Callback
@return boolean Success | [
"Connects",
"to",
"URL"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Connection.php#L439-L497 |
kakserpom/phpdaemon | PHPDaemon/Network/Connection.php | Connection.connectUnix | public function connectUnix($path)
{
$this->type = 'unix';
if (!$this->bevConnectEnabled) {
$fd = socket_create(AF_UNIX, SOCK_STREAM, 0);
if (!$fd) {
return false;
}
socket_set_nonblock($fd);
@socket_connect($fd, $path, 0);
$this->setFd($fd);
return true;
}
$this->bevConnect = true;
$this->addr = 'unix:' . $path;
$this->setFd(null);
return true;
} | php | public function connectUnix($path)
{
$this->type = 'unix';
if (!$this->bevConnectEnabled) {
$fd = socket_create(AF_UNIX, SOCK_STREAM, 0);
if (!$fd) {
return false;
}
socket_set_nonblock($fd);
@socket_connect($fd, $path, 0);
$this->setFd($fd);
return true;
}
$this->bevConnect = true;
$this->addr = 'unix:' . $path;
$this->setFd(null);
return true;
} | [
"public",
"function",
"connectUnix",
"(",
"$",
"path",
")",
"{",
"$",
"this",
"->",
"type",
"=",
"'unix'",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"bevConnectEnabled",
")",
"{",
"$",
"fd",
"=",
"socket_create",
"(",
"AF_UNIX",
",",
"SOCK_STREAM",
",",
... | Establish UNIX socket connection
@param string $path Path
@return boolean Success | [
"Establish",
"UNIX",
"socket",
"connection"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Connection.php#L504-L522 |
kakserpom/phpdaemon | PHPDaemon/Network/Connection.php | Connection.connectRaw | public function connectRaw($host)
{
$this->type = 'raw';
if (@inet_pton($host) === false) { // dirty check
\PHPDaemon\Clients\DNS\Pool::getInstance()->resolve($host, function ($result) use ($host) {
if ($result === false) {
Daemon::log(get_class($this) . '->connectRaw : unable to resolve hostname: ' . $host);
$this->onFailureEv();
return;
}
// @TODO stack of addrs
if (is_array($result)) {
srand(Daemon::$process->getPid());
$real = $result[rand(0, sizeof($result) - 1)];
srand();
} else {
$real = $result;
}
$this->connectRaw($real);
});
return true;
}
$this->hostReal = $host;
if ($this->host === null) {
$this->host = $this->hostReal;
}
$this->addr = $this->hostReal . ':raw';
$fd = socket_create(\EventUtil::AF_INET, \EventUtil::SOCK_RAW, 1);
if (!$fd) {
return false;
}
socket_set_nonblock($fd);
@socket_connect($fd, $host, 0);
$this->setFd($fd);
if (!$this->bev) {
return false;
}
return true;
} | php | public function connectRaw($host)
{
$this->type = 'raw';
if (@inet_pton($host) === false) { // dirty check
\PHPDaemon\Clients\DNS\Pool::getInstance()->resolve($host, function ($result) use ($host) {
if ($result === false) {
Daemon::log(get_class($this) . '->connectRaw : unable to resolve hostname: ' . $host);
$this->onFailureEv();
return;
}
// @TODO stack of addrs
if (is_array($result)) {
srand(Daemon::$process->getPid());
$real = $result[rand(0, sizeof($result) - 1)];
srand();
} else {
$real = $result;
}
$this->connectRaw($real);
});
return true;
}
$this->hostReal = $host;
if ($this->host === null) {
$this->host = $this->hostReal;
}
$this->addr = $this->hostReal . ':raw';
$fd = socket_create(\EventUtil::AF_INET, \EventUtil::SOCK_RAW, 1);
if (!$fd) {
return false;
}
socket_set_nonblock($fd);
@socket_connect($fd, $host, 0);
$this->setFd($fd);
if (!$this->bev) {
return false;
}
return true;
} | [
"public",
"function",
"connectRaw",
"(",
"$",
"host",
")",
"{",
"$",
"this",
"->",
"type",
"=",
"'raw'",
";",
"if",
"(",
"@",
"inet_pton",
"(",
"$",
"host",
")",
"===",
"false",
")",
"{",
"// dirty check",
"\\",
"PHPDaemon",
"\\",
"Clients",
"\\",
"D... | Establish raw socket connection
@param string $host Hostname
@return boolean Success | [
"Establish",
"raw",
"socket",
"connection"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Connection.php#L529-L567 |
kakserpom/phpdaemon | PHPDaemon/Network/Connection.php | Connection.connectUdp | public function connectUdp($host, $port)
{
$this->type = 'udp';
$pton = @inet_pton($host);
if ($pton === false) { // dirty check
\PHPDaemon\Clients\DNS\Pool::getInstance()->resolve($host, function ($result) use ($host, $port) {
if (!$result) {
Daemon::log(get_class($this) . '->connectUdp : unable to resolve hostname: ' . $host);
$this->onStateEv($this->bev, \EventBufferEvent::ERROR);
return;
}
// @todo stack of addrs
if (is_array($result)) {
srand(Daemon::$process->getPid());
$real = $result[rand(0, sizeof($result) - 1)];
srand();
} else {
$real = $result;
}
$this->connectUdp($real, $port);
});
return true;
}
$this->hostReal = $host;
if ($this->host === null) {
$this->host = $this->hostReal;
}
$l = mb_orig_strlen($pton);
if ($l === 4) {
$this->addr = $host . ':' . $port;
/* @TODO: use EventUtil::SOCK_DGRAM */
$fd = socket_create(\EventUtil::AF_INET, SOCK_DGRAM, \EventUtil::SOL_UDP);
} elseif ($l === 16) {
$this->addr = '[' . $host . ']:' . $port;
$fd = socket_create(\EventUtil::AF_INET6, SOCK_DGRAM, \EventUtil::SOL_UDP);
} else {
return false;
}
if (!$fd) {
return false;
}
socket_set_nonblock($fd);
@socket_connect($fd, $host, $port);
socket_getsockname($fd, $this->locAddr, $this->locPort);
$this->setFd($fd);
if (!$this->bev) {
return false;
}
return true;
} | php | public function connectUdp($host, $port)
{
$this->type = 'udp';
$pton = @inet_pton($host);
if ($pton === false) { // dirty check
\PHPDaemon\Clients\DNS\Pool::getInstance()->resolve($host, function ($result) use ($host, $port) {
if (!$result) {
Daemon::log(get_class($this) . '->connectUdp : unable to resolve hostname: ' . $host);
$this->onStateEv($this->bev, \EventBufferEvent::ERROR);
return;
}
// @todo stack of addrs
if (is_array($result)) {
srand(Daemon::$process->getPid());
$real = $result[rand(0, sizeof($result) - 1)];
srand();
} else {
$real = $result;
}
$this->connectUdp($real, $port);
});
return true;
}
$this->hostReal = $host;
if ($this->host === null) {
$this->host = $this->hostReal;
}
$l = mb_orig_strlen($pton);
if ($l === 4) {
$this->addr = $host . ':' . $port;
/* @TODO: use EventUtil::SOCK_DGRAM */
$fd = socket_create(\EventUtil::AF_INET, SOCK_DGRAM, \EventUtil::SOL_UDP);
} elseif ($l === 16) {
$this->addr = '[' . $host . ']:' . $port;
$fd = socket_create(\EventUtil::AF_INET6, SOCK_DGRAM, \EventUtil::SOL_UDP);
} else {
return false;
}
if (!$fd) {
return false;
}
socket_set_nonblock($fd);
@socket_connect($fd, $host, $port);
socket_getsockname($fd, $this->locAddr, $this->locPort);
$this->setFd($fd);
if (!$this->bev) {
return false;
}
return true;
} | [
"public",
"function",
"connectUdp",
"(",
"$",
"host",
",",
"$",
"port",
")",
"{",
"$",
"this",
"->",
"type",
"=",
"'udp'",
";",
"$",
"pton",
"=",
"@",
"inet_pton",
"(",
"$",
"host",
")",
";",
"if",
"(",
"$",
"pton",
"===",
"false",
")",
"{",
"/... | Establish UDP connection
@param string $host Hostname
@param integer $port Port
@return boolean Success | [
"Establish",
"UDP",
"connection"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Connection.php#L575-L624 |
kakserpom/phpdaemon | PHPDaemon/Network/Connection.php | Connection.connectTcp | public function connectTcp($host, $port)
{
$this->type = 'tcp';
$pton = @inet_pton($host);
$fd = null;
if ($pton === false) { // dirty check
\PHPDaemon\Clients\DNS\Pool::getInstance()->resolve($this->host, function ($result) use ($host, $port) {
if (!$result) {
Daemon::log(get_class($this) . '->connectTcp : unable to resolve hostname: ' . $host);
$this->onStateEv($this->bev, \EventBufferEvent::ERROR);
return;
}
// @todo stack of addrs
if (is_array($result)) {
if (!sizeof($result)) {
return;
}
srand(Daemon::$process->getPid());
$real = $result[rand(0, sizeof($result) - 1)];
srand();
} else {
$real = $result;
}
$this->connectTcp($real, $port);
});
return true;
}
$this->hostReal = $host;
if ($this->host === null) {
$this->host = $this->hostReal;
}
// TCP
$l = mb_orig_strlen($pton);
if ($l === 4) {
$this->addr = $host . ':' . $port;
if (!$this->bevConnectEnabled) {
$fd = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
}
} elseif ($l === 16) {
$this->addr = '[' . $host . ']:' . $port;
if (!$this->bevConnectEnabled) {
$fd = socket_create(AF_INET6, SOCK_STREAM, SOL_TCP);
}
} else {
return false;
}
if (!$this->bevConnectEnabled && !$fd) {
return false;
}
if (!$this->bevConnectEnabled) {
socket_set_nonblock($fd);
}
if (!$this->bevConnectEnabled) {
$this->fd = $fd;
$this->setTimeouts(
$this->timeoutRead !== null ? $this->timeoutRead : $this->timeout,
$this->timeoutWrite !== null ? $this->timeoutWrite : $this->timeout
);
socket_connect($fd, $host, $port);
socket_getsockname($fd, $this->locAddr, $this->locPort);
} else {
$this->bevConnect = true;
}
$this->setFd($fd);
if (!$this->bev) {
return false;
}
return true;
} | php | public function connectTcp($host, $port)
{
$this->type = 'tcp';
$pton = @inet_pton($host);
$fd = null;
if ($pton === false) { // dirty check
\PHPDaemon\Clients\DNS\Pool::getInstance()->resolve($this->host, function ($result) use ($host, $port) {
if (!$result) {
Daemon::log(get_class($this) . '->connectTcp : unable to resolve hostname: ' . $host);
$this->onStateEv($this->bev, \EventBufferEvent::ERROR);
return;
}
// @todo stack of addrs
if (is_array($result)) {
if (!sizeof($result)) {
return;
}
srand(Daemon::$process->getPid());
$real = $result[rand(0, sizeof($result) - 1)];
srand();
} else {
$real = $result;
}
$this->connectTcp($real, $port);
});
return true;
}
$this->hostReal = $host;
if ($this->host === null) {
$this->host = $this->hostReal;
}
// TCP
$l = mb_orig_strlen($pton);
if ($l === 4) {
$this->addr = $host . ':' . $port;
if (!$this->bevConnectEnabled) {
$fd = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
}
} elseif ($l === 16) {
$this->addr = '[' . $host . ']:' . $port;
if (!$this->bevConnectEnabled) {
$fd = socket_create(AF_INET6, SOCK_STREAM, SOL_TCP);
}
} else {
return false;
}
if (!$this->bevConnectEnabled && !$fd) {
return false;
}
if (!$this->bevConnectEnabled) {
socket_set_nonblock($fd);
}
if (!$this->bevConnectEnabled) {
$this->fd = $fd;
$this->setTimeouts(
$this->timeoutRead !== null ? $this->timeoutRead : $this->timeout,
$this->timeoutWrite !== null ? $this->timeoutWrite : $this->timeout
);
socket_connect($fd, $host, $port);
socket_getsockname($fd, $this->locAddr, $this->locPort);
} else {
$this->bevConnect = true;
}
$this->setFd($fd);
if (!$this->bev) {
return false;
}
return true;
} | [
"public",
"function",
"connectTcp",
"(",
"$",
"host",
",",
"$",
"port",
")",
"{",
"$",
"this",
"->",
"type",
"=",
"'tcp'",
";",
"$",
"pton",
"=",
"@",
"inet_pton",
"(",
"$",
"host",
")",
";",
"$",
"fd",
"=",
"null",
";",
"if",
"(",
"$",
"pton",... | Establish TCP connection
@param string $host Hostname
@param integer $port Port
@return boolean Success | [
"Establish",
"TCP",
"connection"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Connection.php#L632-L700 |
kakserpom/phpdaemon | PHPDaemon/Network/Connection.php | Connection.setKeepalive | public function setKeepalive($bool)
{
$this->keepalive = (bool)$bool;
$this->setOption(\EventUtil::SOL_SOCKET, \EventUtil::SO_KEEPALIVE, $this->keepalive ? true : false);
} | php | public function setKeepalive($bool)
{
$this->keepalive = (bool)$bool;
$this->setOption(\EventUtil::SOL_SOCKET, \EventUtil::SO_KEEPALIVE, $this->keepalive ? true : false);
} | [
"public",
"function",
"setKeepalive",
"(",
"$",
"bool",
")",
"{",
"$",
"this",
"->",
"keepalive",
"=",
"(",
"bool",
")",
"$",
"bool",
";",
"$",
"this",
"->",
"setOption",
"(",
"\\",
"EventUtil",
"::",
"SOL_SOCKET",
",",
"\\",
"EventUtil",
"::",
"SO_KEE... | Set keepalive
@param boolean $bool
@return void | [
"Set",
"keepalive"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Connection.php#L707-L711 |
kakserpom/phpdaemon | PHPDaemon/Network/Connection.php | Connection.setTimeouts | public function setTimeouts($read, $write)
{
parent::setTimeouts($read, $write);
if ($this->fd !== null) {
$this->setOption(
\EventUtil::SOL_SOCKET,
\EventUtil::SO_SNDTIMEO,
['sec' => $this->timeoutWrite, 'usec' => 0]
);
$this->setOption(
\EventUtil::SOL_SOCKET,
\EventUtil::SO_RCVTIMEO,
['sec' => $this->timeoutRead, 'usec' => 0]
);
}
} | php | public function setTimeouts($read, $write)
{
parent::setTimeouts($read, $write);
if ($this->fd !== null) {
$this->setOption(
\EventUtil::SOL_SOCKET,
\EventUtil::SO_SNDTIMEO,
['sec' => $this->timeoutWrite, 'usec' => 0]
);
$this->setOption(
\EventUtil::SOL_SOCKET,
\EventUtil::SO_RCVTIMEO,
['sec' => $this->timeoutRead, 'usec' => 0]
);
}
} | [
"public",
"function",
"setTimeouts",
"(",
"$",
"read",
",",
"$",
"write",
")",
"{",
"parent",
"::",
"setTimeouts",
"(",
"$",
"read",
",",
"$",
"write",
")",
";",
"if",
"(",
"$",
"this",
"->",
"fd",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"set... | 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/Connection.php#L731-L746 |
kakserpom/phpdaemon | PHPDaemon/Network/Connection.php | Connection.setOption | public function setOption($level, $optname, $val)
{
if (is_resource($this->fd)) {
socket_set_option($this->fd, $level, $optname, $val);
} else {
\EventUtil::setSocketOption($this->fd, $level, $optname, $val);
}
} | php | public function setOption($level, $optname, $val)
{
if (is_resource($this->fd)) {
socket_set_option($this->fd, $level, $optname, $val);
} else {
\EventUtil::setSocketOption($this->fd, $level, $optname, $val);
}
} | [
"public",
"function",
"setOption",
"(",
"$",
"level",
",",
"$",
"optname",
",",
"$",
"val",
")",
"{",
"if",
"(",
"is_resource",
"(",
"$",
"this",
"->",
"fd",
")",
")",
"{",
"socket_set_option",
"(",
"$",
"this",
"->",
"fd",
",",
"$",
"level",
",",
... | Set socket option
@param integer $level Level
@param integer $optname Option
@param mixed $val Value
@return void | [
"Set",
"socket",
"option"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Connection.php#L755-L762 |
kakserpom/phpdaemon | PHPDaemon/Network/Connection.php | Connection.onFinish | public function onFinish()
{
if (!$this->connected) {
if ($this->onConnected) {
$this->onConnected->executeAll($this);
$this->onConnected = null;
}
}
parent::onFinish();
} | php | public function onFinish()
{
if (!$this->connected) {
if ($this->onConnected) {
$this->onConnected->executeAll($this);
$this->onConnected = null;
}
}
parent::onFinish();
} | [
"public",
"function",
"onFinish",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"connected",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"onConnected",
")",
"{",
"$",
"this",
"->",
"onConnected",
"->",
"executeAll",
"(",
"$",
"this",
")",
";",
"$",... | Called when connection finishes
@return void | [
"Called",
"when",
"connection",
"finishes"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Network/Connection.php#L768-L777 |
kakserpom/phpdaemon | PHPDaemon/Examples/ExampleWithPostgreSQL.php | ExampleWithPostgreSQLRequest.init | public function init()
{
$this->appInstance->pgsql->getConnection(function ($sql) {
if (!$sql->connected) { // failed to connect
$this->wakeup(); // wake up the request immediately
$sql->release();
return;
}
$sql->query('SELECT 123 as integer, NULL as nul, \'test\' as string', function ($sql, $success) {
$this->queryResult = $sql->resultRows; // save the result
$this->wakeup(); // wake up the request immediately
$sql->release();
});
});
$this->sleep(5);
} | php | public function init()
{
$this->appInstance->pgsql->getConnection(function ($sql) {
if (!$sql->connected) { // failed to connect
$this->wakeup(); // wake up the request immediately
$sql->release();
return;
}
$sql->query('SELECT 123 as integer, NULL as nul, \'test\' as string', function ($sql, $success) {
$this->queryResult = $sql->resultRows; // save the result
$this->wakeup(); // wake up the request immediately
$sql->release();
});
});
$this->sleep(5);
} | [
"public",
"function",
"init",
"(",
")",
"{",
"$",
"this",
"->",
"appInstance",
"->",
"pgsql",
"->",
"getConnection",
"(",
"function",
"(",
"$",
"sql",
")",
"{",
"if",
"(",
"!",
"$",
"sql",
"->",
"connected",
")",
"{",
"// failed to connect",
"$",
"this... | Constructor.
@return void | [
"Constructor",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Examples/ExampleWithPostgreSQL.php#L50-L65 |
kakserpom/phpdaemon | PHPDaemon/Examples/ExampleWithPostgreSQL.php | ExampleWithPostgreSQLRequest.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 PostgreSQL</title>
</head>
<body>
<?php
if ($this->queryResult) {
echo '<h1>It works! Be happy! ;-)</h1>Result of `SELECT 123 as integer, NULL as nul, \'test\' as string`: <pre>';
var_dump($this->queryResult);
echo '</pre>';
} else {
echo '<h1>Something went wrong! We have no result.</h1>';
}
echo '<br />Request (http) took: ' . round(microtime(true) - $_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 PostgreSQL</title>
</head>
<body>
<?php
if ($this->queryResult) {
echo '<h1>It works! Be happy! ;-)</h1>Result of `SELECT 123 as integer, NULL as nul, \'test\' as string`: <pre>';
var_dump($this->queryResult);
echo '</pre>';
} else {
echo '<h1>Something went wrong! We have no result.</h1>';
}
echo '<br />Request (http) took: ' . round(microtime(true) - $_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/ExampleWithPostgreSQL.php#L71-L103 |
kakserpom/phpdaemon | PHPDaemon/Config/_Object.php | _Object.renameSection | public function renameSection($old, $new, $log = false)
{
Daemon::$config->{$new} = Daemon::$config->{$old};
unset(Daemon::$config->{$old});
if ($log) {
Daemon::log('Config section \'' . $old . '\' -> \'' . $new . '\'');
}
} | php | public function renameSection($old, $new, $log = false)
{
Daemon::$config->{$new} = Daemon::$config->{$old};
unset(Daemon::$config->{$old});
if ($log) {
Daemon::log('Config section \'' . $old . '\' -> \'' . $new . '\'');
}
} | [
"public",
"function",
"renameSection",
"(",
"$",
"old",
",",
"$",
"new",
",",
"$",
"log",
"=",
"false",
")",
"{",
"Daemon",
"::",
"$",
"config",
"->",
"{",
"$",
"new",
"}",
"=",
"Daemon",
"::",
"$",
"config",
"->",
"{",
"$",
"old",
"}",
";",
"u... | Renames section
@param string $old
@param string $new
@param boolean $log Log?
@return void | [
"Renames",
"section"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Config/_Object.php#L358-L365 |
kakserpom/phpdaemon | PHPDaemon/Config/_Object.php | _Object.loadFile | public function loadFile($path)
{
$parser = Parser::parse($path, $this);
$this->onLoad();
return !$parser->isErroneous();
} | php | public function loadFile($path)
{
$parser = Parser::parse($path, $this);
$this->onLoad();
return !$parser->isErroneous();
} | [
"public",
"function",
"loadFile",
"(",
"$",
"path",
")",
"{",
"$",
"parser",
"=",
"Parser",
"::",
"parse",
"(",
"$",
"path",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"onLoad",
"(",
")",
";",
"return",
"!",
"$",
"parser",
"->",
"isErroneous",
... | Load config file
@param string Path
@return boolean Success | [
"Load",
"config",
"file"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Config/_Object.php#L372-L377 |
kakserpom/phpdaemon | PHPDaemon/Config/_Object.php | _Object.onLoad | protected function onLoad()
{
if (isset($this->minspareworkers->value) && $this->minspareworkers->value > 0
&& isset($this->maxspareworkers->value) && $this->maxspareworkers->value > 0
) {
if ($this->minspareworkers->value > $this->maxspareworkers->value) {
Daemon::log('\'minspareworkers\' (' . $this->minspareworkers->value . ') cannot be greater than \'maxspareworkers\' (' . $this->maxspareworkers->value . ').');
$this->minspareworkers->value = $this->maxspareworkers->value;
}
}
if (isset($this->minworkers->value) && isset($this->maxworkers->value)) {
if ($this->minworkers->value > $this->maxworkers->value) {
$this->minworkers->value = $this->maxworkers->value;
}
}
} | php | protected function onLoad()
{
if (isset($this->minspareworkers->value) && $this->minspareworkers->value > 0
&& isset($this->maxspareworkers->value) && $this->maxspareworkers->value > 0
) {
if ($this->minspareworkers->value > $this->maxspareworkers->value) {
Daemon::log('\'minspareworkers\' (' . $this->minspareworkers->value . ') cannot be greater than \'maxspareworkers\' (' . $this->maxspareworkers->value . ').');
$this->minspareworkers->value = $this->maxspareworkers->value;
}
}
if (isset($this->minworkers->value) && isset($this->maxworkers->value)) {
if ($this->minworkers->value > $this->maxworkers->value) {
$this->minworkers->value = $this->maxworkers->value;
}
}
} | [
"protected",
"function",
"onLoad",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"minspareworkers",
"->",
"value",
")",
"&&",
"$",
"this",
"->",
"minspareworkers",
"->",
"value",
">",
"0",
"&&",
"isset",
"(",
"$",
"this",
"->",
"maxsparewo... | Called when config is loaded
@return void | [
"Called",
"when",
"config",
"is",
"loaded"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Config/_Object.php#L383-L399 |
kakserpom/phpdaemon | PHPDaemon/Config/_Object.php | _Object.offsetGet | public function offsetGet($prop)
{
$prop = $this->getRealPropertyName($prop);
return isset($this->{$prop}) ? $this->{$prop}->value : null;
} | php | public function offsetGet($prop)
{
$prop = $this->getRealPropertyName($prop);
return isset($this->{$prop}) ? $this->{$prop}->value : null;
} | [
"public",
"function",
"offsetGet",
"(",
"$",
"prop",
")",
"{",
"$",
"prop",
"=",
"$",
"this",
"->",
"getRealPropertyName",
"(",
"$",
"prop",
")",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"{",
"$",
"prop",
"}",
")",
"?",
"$",
"this",
"->",
... | Get property by name
@param string Property name
@return mixed | [
"Get",
"property",
"by",
"name"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Config/_Object.php#L428-L432 |
kakserpom/phpdaemon | PHPDaemon/Config/_Object.php | _Object.offsetSet | public function offsetSet($prop, $value)
{
$prop = $this->getRealPropertyName($prop);
$this->{$prop} = $value;
} | php | public function offsetSet($prop, $value)
{
$prop = $this->getRealPropertyName($prop);
$this->{$prop} = $value;
} | [
"public",
"function",
"offsetSet",
"(",
"$",
"prop",
",",
"$",
"value",
")",
"{",
"$",
"prop",
"=",
"$",
"this",
"->",
"getRealPropertyName",
"(",
"$",
"prop",
")",
";",
"$",
"this",
"->",
"{",
"$",
"prop",
"}",
"=",
"$",
"value",
";",
"}"
] | Set property
@param string Property name
@param mixed Value
@return void | [
"Set",
"property"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Config/_Object.php#L440-L444 |
kakserpom/phpdaemon | PHPDaemon/Config/_Object.php | _Object.parseCfgUri | public static function parseCfgUri($uri, $source = null)
{
if (mb_orig_strpos($uri, '://') === false) {
if (strncmp($uri, 'unix:', 5) === 0) {
$e = explode(':', $uri);
if (sizeof($e) === 4) {
$uri = 'unix://' . $e[1] . ':' . $e[2] . '@localhost' . $e[3];
} elseif (sizeof($e) === 3) {
$uri = 'unix://' . $e[1] . '@localhost' . $e[2];
} else {
$uri = 'unix://localhost' . $e[1];
}
} else {
$uri = 'tcp://' . $uri;
}
}
if (stripos($uri, 'unix:///') === 0) {
$uri = 'unix://localhost/' . substr($uri, 8);
}
$zeroPortNum = false;
$uri = preg_replace_callback('~:0(?:$|/)~', function () use (&$zeroPortNum) {
$zeroPortNum = true;
return '';
}, $uri);
$u = parse_url($uri);
$u['host'] = trim($u['host'], '][');
$u['uri'] = $uri;
if ($zeroPortNum) {
$u['port'] = 0;
}
if (!isset($u['scheme'])) {
$u['scheme'] = '';
}
$u['params'] = [];
if (!isset($u['fragment'])) {
return $u;
}
$hash = '#' . $u['fragment'];
$error = false;
preg_replace_callback('~(#+)(.+?)(?=#|$)|(.+)~', function ($m) use (&$u, &$error, $uri) {
if ($error) {
return;
}
list(, $type, $value) = $m;
if ($type === '#') { // standard value
$e = explode('=', $value, 2);
if (sizeof($e) === 2) {
list($key, $value) = $e;
} else {
$key = $value;
$value = true;
}
$u['params'][$key] = $value;
} elseif ($type === '##') { // Context name
$u['params']['ctxname'] = $value;
} else {
Daemon::log('Malformed URI: ' . var_export($uri, true) . ', unexpected token \'' . $type . '\'');
$error = true;
}
}, $hash);
return $error ? false : $u;
} | php | public static function parseCfgUri($uri, $source = null)
{
if (mb_orig_strpos($uri, '://') === false) {
if (strncmp($uri, 'unix:', 5) === 0) {
$e = explode(':', $uri);
if (sizeof($e) === 4) {
$uri = 'unix://' . $e[1] . ':' . $e[2] . '@localhost' . $e[3];
} elseif (sizeof($e) === 3) {
$uri = 'unix://' . $e[1] . '@localhost' . $e[2];
} else {
$uri = 'unix://localhost' . $e[1];
}
} else {
$uri = 'tcp://' . $uri;
}
}
if (stripos($uri, 'unix:///') === 0) {
$uri = 'unix://localhost/' . substr($uri, 8);
}
$zeroPortNum = false;
$uri = preg_replace_callback('~:0(?:$|/)~', function () use (&$zeroPortNum) {
$zeroPortNum = true;
return '';
}, $uri);
$u = parse_url($uri);
$u['host'] = trim($u['host'], '][');
$u['uri'] = $uri;
if ($zeroPortNum) {
$u['port'] = 0;
}
if (!isset($u['scheme'])) {
$u['scheme'] = '';
}
$u['params'] = [];
if (!isset($u['fragment'])) {
return $u;
}
$hash = '#' . $u['fragment'];
$error = false;
preg_replace_callback('~(#+)(.+?)(?=#|$)|(.+)~', function ($m) use (&$u, &$error, $uri) {
if ($error) {
return;
}
list(, $type, $value) = $m;
if ($type === '#') { // standard value
$e = explode('=', $value, 2);
if (sizeof($e) === 2) {
list($key, $value) = $e;
} else {
$key = $value;
$value = true;
}
$u['params'][$key] = $value;
} elseif ($type === '##') { // Context name
$u['params']['ctxname'] = $value;
} else {
Daemon::log('Malformed URI: ' . var_export($uri, true) . ', unexpected token \'' . $type . '\'');
$error = true;
}
}, $hash);
return $error ? false : $u;
} | [
"public",
"static",
"function",
"parseCfgUri",
"(",
"$",
"uri",
",",
"$",
"source",
"=",
"null",
")",
"{",
"if",
"(",
"mb_orig_strpos",
"(",
"$",
"uri",
",",
"'://'",
")",
"===",
"false",
")",
"{",
"if",
"(",
"strncmp",
"(",
"$",
"uri",
",",
"'unix... | Checks if property exists
@param string Property name
@return boolean Exists? | [
"Checks",
"if",
"property",
"exists"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Config/_Object.php#L462-L523 |
kakserpom/phpdaemon | PHPDaemon/Config/_Object.php | _Object.loadCmdLineArgs | public static function loadCmdLineArgs($settings)
{
$error = false;
static $ktr = [
'-' => '',
];
foreach ($settings as $k => $v) {
$k = strtolower(strtr($k, $ktr));
if ($k === 'config') {
$k = 'configfile';
}
if (($k === 'user') || ($k === 'group')) {
if ($v === '') {
$v = null;
}
}
if (isset(Daemon::$config->{$k})) {
Daemon::$config->{$k}->setHumanValue($v);
Daemon::$config->{$k}->source = 'cmdline';
} else {
Daemon::log('Unrecognized parameter \'' . $k . '\'');
$error = true;
}
}
return !$error;
} | php | public static function loadCmdLineArgs($settings)
{
$error = false;
static $ktr = [
'-' => '',
];
foreach ($settings as $k => $v) {
$k = strtolower(strtr($k, $ktr));
if ($k === 'config') {
$k = 'configfile';
}
if (($k === 'user') || ($k === 'group')) {
if ($v === '') {
$v = null;
}
}
if (isset(Daemon::$config->{$k})) {
Daemon::$config->{$k}->setHumanValue($v);
Daemon::$config->{$k}->source = 'cmdline';
} else {
Daemon::log('Unrecognized parameter \'' . $k . '\'');
$error = true;
}
}
return !$error;
} | [
"public",
"static",
"function",
"loadCmdLineArgs",
"(",
"$",
"settings",
")",
"{",
"$",
"error",
"=",
"false",
";",
"static",
"$",
"ktr",
"=",
"[",
"'-'",
"=>",
"''",
",",
"]",
";",
"foreach",
"(",
"$",
"settings",
"as",
"$",
"k",
"=>",
"$",
"v",
... | Imports parameters from command line args
@param array Settings.
@return boolean - Success. | [
"Imports",
"parameters",
"from",
"command",
"line",
"args"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Config/_Object.php#L530-L560 |
kakserpom/phpdaemon | PHPDaemon/Clients/Asterisk/Pool.php | Pool.prepareEnv | public static function prepareEnv($data)
{
$result = [];
$rows = explode("\n", $data);
for ($i = 0, $s = sizeof($rows); $i < $s; ++$i) {
$e = self::extract($rows[$i]);
$result[$e[0]] = $e[1];
}
return $result;
} | php | public static function prepareEnv($data)
{
$result = [];
$rows = explode("\n", $data);
for ($i = 0, $s = sizeof($rows); $i < $s; ++$i) {
$e = self::extract($rows[$i]);
$result[$e[0]] = $e[1];
}
return $result;
} | [
"public",
"static",
"function",
"prepareEnv",
"(",
"$",
"data",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"rows",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"data",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"s",
"=",
"sizeof",
... | Prepares environment scope
@param string $data Address
@return array | [
"Prepares",
"environment",
"scope"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Asterisk/Pool.php#L27-L36 |
kakserpom/phpdaemon | PHPDaemon/Clients/Asterisk/Pool.php | Pool.extract | public static function extract($line)
{
$e = explode(': ', $line, 2);
$header = strtolower(trim($e[0]));
$value = isset($e[1]) ? trim($e[1]) : null;
$safe = false;
foreach (self::$safeCaseValues as $item) {
if (strncasecmp($header, $item, mb_orig_strlen($item)) === 0) {
$safe = true;
break;
}
if (strncasecmp($value, $item, mb_orig_strlen($item)) === 0) {
$safe = true;
break;
}
}
if (!$safe) {
$value = strtolower($value);
}
return [$header, $value];
} | php | public static function extract($line)
{
$e = explode(': ', $line, 2);
$header = strtolower(trim($e[0]));
$value = isset($e[1]) ? trim($e[1]) : null;
$safe = false;
foreach (self::$safeCaseValues as $item) {
if (strncasecmp($header, $item, mb_orig_strlen($item)) === 0) {
$safe = true;
break;
}
if (strncasecmp($value, $item, mb_orig_strlen($item)) === 0) {
$safe = true;
break;
}
}
if (!$safe) {
$value = strtolower($value);
}
return [$header, $value];
} | [
"public",
"static",
"function",
"extract",
"(",
"$",
"line",
")",
"{",
"$",
"e",
"=",
"explode",
"(",
"': '",
",",
"$",
"line",
",",
"2",
")",
";",
"$",
"header",
"=",
"strtolower",
"(",
"trim",
"(",
"$",
"e",
"[",
"0",
"]",
")",
")",
";",
"$... | Extract key and value pair from line.
@param string $line
@return array | [
"Extract",
"key",
"and",
"value",
"pair",
"from",
"line",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Asterisk/Pool.php#L43-L66 |
kakserpom/phpdaemon | PHPDaemon/Servers/FlashPolicy/Pool.php | Pool.onConfigUpdated | public function onConfigUpdated()
{
parent::onConfigUpdated();
if (Daemon::$process instanceof \PHPDaemon\Thread\Worker) {
$pool = $this;
FileSystem::readfile($this->config->file->value, function ($file, $data) use ($pool) {
$pool->policyData = $data;
$pool->enable();
});
}
} | php | public function onConfigUpdated()
{
parent::onConfigUpdated();
if (Daemon::$process instanceof \PHPDaemon\Thread\Worker) {
$pool = $this;
FileSystem::readfile($this->config->file->value, function ($file, $data) use ($pool) {
$pool->policyData = $data;
$pool->enable();
});
}
} | [
"public",
"function",
"onConfigUpdated",
"(",
")",
"{",
"parent",
"::",
"onConfigUpdated",
"(",
")",
";",
"if",
"(",
"Daemon",
"::",
"$",
"process",
"instanceof",
"\\",
"PHPDaemon",
"\\",
"Thread",
"\\",
"Worker",
")",
"{",
"$",
"pool",
"=",
"$",
"this",... | Called when worker is going to update configuration
@return void | [
"Called",
"when",
"worker",
"is",
"going",
"to",
"update",
"configuration"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/FlashPolicy/Pool.php#L48-L58 |
kakserpom/phpdaemon | PHPDaemon/Utils/Binary.php | Binary.labels | public static function labels($q)
{
$e = explode('.', $q);
$r = '';
for ($i = 0, $s = sizeof($e); $i < $s; ++$i) {
$r .= chr(mb_orig_strlen($e[$i])) . $e[$i];
}
if (mb_orig_substr($r, -1) !== "\x00") {
$r .= "\x00";
}
return $r;
} | php | public static function labels($q)
{
$e = explode('.', $q);
$r = '';
for ($i = 0, $s = sizeof($e); $i < $s; ++$i) {
$r .= chr(mb_orig_strlen($e[$i])) . $e[$i];
}
if (mb_orig_substr($r, -1) !== "\x00") {
$r .= "\x00";
}
return $r;
} | [
"public",
"static",
"function",
"labels",
"(",
"$",
"q",
")",
"{",
"$",
"e",
"=",
"explode",
"(",
"'.'",
",",
"$",
"q",
")",
";",
"$",
"r",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"s",
"=",
"sizeof",
"(",
"$",
"e",
")",
... | Build structure of labels
@param string $q Dot-separated labels list
@return string | [
"Build",
"structure",
"of",
"labels"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Utils/Binary.php#L22-L33 |
kakserpom/phpdaemon | PHPDaemon/Utils/Binary.php | Binary.parseLabels | public static function parseLabels(&$data, $orig = null)
{
$str = '';
while (mb_orig_strlen($data) > 0) {
$l = ord($data[0]);
if ($l >= 192) {
$pos = Binary::bytes2int(chr($l - 192) . mb_orig_substr($data, 1, 1));
$data = mb_orig_substr($data, 2);
$ref = mb_orig_substr($orig, $pos);
return $str . Binary::parseLabels($ref, $orig);
}
$p = mb_orig_substr($data, 1, $l);
$str .= $p . (($l !== 0) ? '.' : '');
$data = mb_orig_substr($data, $l + 1);
if ($l === 0) {
break;
}
}
return $str;
} | php | public static function parseLabels(&$data, $orig = null)
{
$str = '';
while (mb_orig_strlen($data) > 0) {
$l = ord($data[0]);
if ($l >= 192) {
$pos = Binary::bytes2int(chr($l - 192) . mb_orig_substr($data, 1, 1));
$data = mb_orig_substr($data, 2);
$ref = mb_orig_substr($orig, $pos);
return $str . Binary::parseLabels($ref, $orig);
}
$p = mb_orig_substr($data, 1, $l);
$str .= $p . (($l !== 0) ? '.' : '');
$data = mb_orig_substr($data, $l + 1);
if ($l === 0) {
break;
}
}
return $str;
} | [
"public",
"static",
"function",
"parseLabels",
"(",
"&",
"$",
"data",
",",
"$",
"orig",
"=",
"null",
")",
"{",
"$",
"str",
"=",
"''",
";",
"while",
"(",
"mb_orig_strlen",
"(",
"$",
"data",
")",
">",
"0",
")",
"{",
"$",
"l",
"=",
"ord",
"(",
"$"... | Parse structure of labels
@param string &$data Binary data
@param string $orig Original packet
@return string Dot-separated labels list | [
"Parse",
"structure",
"of",
"labels"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Utils/Binary.php#L41-L62 |
kakserpom/phpdaemon | PHPDaemon/Utils/Binary.php | Binary.bytes2int | public static function bytes2int($str, $l = false)
{
if ($l) {
$str = strrev($str);
}
$dec = 0;
$len = mb_orig_strlen($str);
for ($i = 0; $i < $len; ++$i) {
$dec += ord(mb_orig_substr($str, $i, 1)) * pow(0x100, $len - $i - 1);
}
return $dec;
} | php | public static function bytes2int($str, $l = false)
{
if ($l) {
$str = strrev($str);
}
$dec = 0;
$len = mb_orig_strlen($str);
for ($i = 0; $i < $len; ++$i) {
$dec += ord(mb_orig_substr($str, $i, 1)) * pow(0x100, $len - $i - 1);
}
return $dec;
} | [
"public",
"static",
"function",
"bytes2int",
"(",
"$",
"str",
",",
"$",
"l",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"l",
")",
"{",
"$",
"str",
"=",
"strrev",
"(",
"$",
"str",
")",
";",
"}",
"$",
"dec",
"=",
"0",
";",
"$",
"len",
"=",
"mb_o... | Convert bytes into integer
@param string $str Bytes
@param boolean $l Little endian? Default is false
@return integer | [
"Convert",
"bytes",
"into",
"integer"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Utils/Binary.php#L70-L81 |
kakserpom/phpdaemon | PHPDaemon/Utils/Binary.php | Binary.getByte | public static function getByte(&$p)
{
$r = static::bytes2int($p{0});
$p = mb_orig_substr($p, 1);
return (int)$r;
} | php | public static function getByte(&$p)
{
$r = static::bytes2int($p{0});
$p = mb_orig_substr($p, 1);
return (int)$r;
} | [
"public",
"static",
"function",
"getByte",
"(",
"&",
"$",
"p",
")",
"{",
"$",
"r",
"=",
"static",
"::",
"bytes2int",
"(",
"$",
"p",
"{",
"0",
"}",
")",
";",
"$",
"p",
"=",
"mb_orig_substr",
"(",
"$",
"p",
",",
"1",
")",
";",
"return",
"(",
"i... | Parse byte, and remove it
@param string &$p Data
@return integer | [
"Parse",
"byte",
"and",
"remove",
"it"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Utils/Binary.php#L226-L231 |
kakserpom/phpdaemon | PHPDaemon/Utils/Binary.php | Binary.getWord | public static function getWord(&$p, $l = false)
{
$r = static::bytes2int(mb_orig_substr($p, 0, 2), !!$l);
$p = mb_orig_substr($p, 2);
return (int)$r;
} | php | public static function getWord(&$p, $l = false)
{
$r = static::bytes2int(mb_orig_substr($p, 0, 2), !!$l);
$p = mb_orig_substr($p, 2);
return (int)$r;
} | [
"public",
"static",
"function",
"getWord",
"(",
"&",
"$",
"p",
",",
"$",
"l",
"=",
"false",
")",
"{",
"$",
"r",
"=",
"static",
"::",
"bytes2int",
"(",
"mb_orig_substr",
"(",
"$",
"p",
",",
"0",
",",
"2",
")",
",",
"!",
"!",
"$",
"l",
")",
";"... | Parse word (2 bytes)
@param string &$p Data
@param boolean $l Little endian?
@return integer | [
"Parse",
"word",
"(",
"2",
"bytes",
")"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Utils/Binary.php#L251-L256 |
kakserpom/phpdaemon | PHPDaemon/Utils/Binary.php | Binary.getStrWord | public static function getStrWord(&$p, $l = false)
{
$r = mb_orig_substr($p, 0, 2);
$p = mb_orig_substr($p, 2);
if ($l) {
$r = strrev($r);
}
return $r;
} | php | public static function getStrWord(&$p, $l = false)
{
$r = mb_orig_substr($p, 0, 2);
$p = mb_orig_substr($p, 2);
if ($l) {
$r = strrev($r);
}
return $r;
} | [
"public",
"static",
"function",
"getStrWord",
"(",
"&",
"$",
"p",
",",
"$",
"l",
"=",
"false",
")",
"{",
"$",
"r",
"=",
"mb_orig_substr",
"(",
"$",
"p",
",",
"0",
",",
"2",
")",
";",
"$",
"p",
"=",
"mb_orig_substr",
"(",
"$",
"p",
",",
"2",
"... | Get word (2 bytes)
@param string &$p Data
@param boolean $l Little endian?
@return string | [
"Get",
"word",
"(",
"2",
"bytes",
")"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Utils/Binary.php#L264-L272 |
kakserpom/phpdaemon | PHPDaemon/Utils/Binary.php | Binary.getDWord | public static function getDWord(&$p, $l = false)
{
$r = static::bytes2int(mb_orig_substr($p, 0, 4), !!$l);
$p = mb_orig_substr($p, 4);
return (int)$r;
} | php | public static function getDWord(&$p, $l = false)
{
$r = static::bytes2int(mb_orig_substr($p, 0, 4), !!$l);
$p = mb_orig_substr($p, 4);
return (int)$r;
} | [
"public",
"static",
"function",
"getDWord",
"(",
"&",
"$",
"p",
",",
"$",
"l",
"=",
"false",
")",
"{",
"$",
"r",
"=",
"static",
"::",
"bytes2int",
"(",
"mb_orig_substr",
"(",
"$",
"p",
",",
"0",
",",
"4",
")",
",",
"!",
"!",
"$",
"l",
")",
";... | Get double word (4 bytes)
@param string &$p Data
@param boolean $l Little endian?
@return integer | [
"Get",
"double",
"word",
"(",
"4",
"bytes",
")"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Utils/Binary.php#L280-L285 |
kakserpom/phpdaemon | PHPDaemon/Utils/Binary.php | Binary.getQword | public static function getQword(&$p, $l = false)
{
$r = static::bytes2int(mb_orig_substr($p, 0, 8), !!$l);
$p = mb_orig_substr($p, 8);
return (int)$r;
} | php | public static function getQword(&$p, $l = false)
{
$r = static::bytes2int(mb_orig_substr($p, 0, 8), !!$l);
$p = mb_orig_substr($p, 8);
return (int)$r;
} | [
"public",
"static",
"function",
"getQword",
"(",
"&",
"$",
"p",
",",
"$",
"l",
"=",
"false",
")",
"{",
"$",
"r",
"=",
"static",
"::",
"bytes2int",
"(",
"mb_orig_substr",
"(",
"$",
"p",
",",
"0",
",",
"8",
")",
",",
"!",
"!",
"$",
"l",
")",
";... | Parse quadro word (8 bytes)
@param string &$p Data
@param boolean $l Little endian?
@return integer | [
"Parse",
"quadro",
"word",
"(",
"8",
"bytes",
")"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Utils/Binary.php#L293-L298 |
kakserpom/phpdaemon | PHPDaemon/Utils/Binary.php | Binary.getStrQWord | public static function getStrQWord(&$p, $l = false)
{
$r = mb_orig_substr($p, 0, 8);
if ($l) {
$r = strrev($r);
}
$p = mb_orig_substr($p, 8);
return $r;
} | php | public static function getStrQWord(&$p, $l = false)
{
$r = mb_orig_substr($p, 0, 8);
if ($l) {
$r = strrev($r);
}
$p = mb_orig_substr($p, 8);
return $r;
} | [
"public",
"static",
"function",
"getStrQWord",
"(",
"&",
"$",
"p",
",",
"$",
"l",
"=",
"false",
")",
"{",
"$",
"r",
"=",
"mb_orig_substr",
"(",
"$",
"p",
",",
"0",
",",
"8",
")",
";",
"if",
"(",
"$",
"l",
")",
"{",
"$",
"r",
"=",
"strrev",
... | Get quadro word (8 bytes)
@param string &$p Data
@param boolean $l Little endian?
@return string | [
"Get",
"quadro",
"word",
"(",
"8",
"bytes",
")"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Utils/Binary.php#L306-L314 |
kakserpom/phpdaemon | PHPDaemon/Utils/Binary.php | Binary.getString | public static function getString(&$str)
{
$p = mb_orig_strpos($str, "\x00");
if ($p === false) {
return '';
}
$r = mb_orig_substr($str, 0, $p);
$str = mb_orig_substr($str, $p + 1);
return $r;
} | php | public static function getString(&$str)
{
$p = mb_orig_strpos($str, "\x00");
if ($p === false) {
return '';
}
$r = mb_orig_substr($str, 0, $p);
$str = mb_orig_substr($str, $p + 1);
return $r;
} | [
"public",
"static",
"function",
"getString",
"(",
"&",
"$",
"str",
")",
"{",
"$",
"p",
"=",
"mb_orig_strpos",
"(",
"$",
"str",
",",
"\"\\x00\"",
")",
";",
"if",
"(",
"$",
"p",
"===",
"false",
")",
"{",
"return",
"''",
";",
"}",
"$",
"r",
"=",
"... | Parse nul-terminated string
@param string &$str Data
@return string | [
"Parse",
"nul",
"-",
"terminated",
"string"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Utils/Binary.php#L321-L330 |
kakserpom/phpdaemon | PHPDaemon/Utils/Binary.php | Binary.getLV | public static function getLV(&$p, $l = 1, $nul = false, $lrev = false)
{
$s = static::b2i(mb_orig_substr($p, 0, $l), !!$lrev);
$p = mb_orig_substr($p, $l);
if ($s === 0) {
return '';
}
$r = '';
if (mb_orig_strlen($p) < $s) {
Daemon::log('getLV error: buf length (' . mb_orig_strlen($p) . '): ' . Debug::exportBytes($p) . ', must be >= string length (' . $s . ")\n");
} elseif ($nul) {
$lastByte = mb_orig_substr($p, -1);
if ($lastByte !== "\x00") {
Daemon:
log('getLV error: Wrong end of NUL-string (' . Debug::exportBytes($lastByte) . '), len ' . $s . "\n");
} else {
$d = $s - 1;
if ($d < 0) {
$d = 0;
}
$r = mb_orig_substr($p, 0, $d);
$p = mb_orig_substr($p, $s);
}
} else {
$r = mb_orig_substr($p, 0, $s);
$p = mb_orig_substr($p, $s);
}
return $r;
} | php | public static function getLV(&$p, $l = 1, $nul = false, $lrev = false)
{
$s = static::b2i(mb_orig_substr($p, 0, $l), !!$lrev);
$p = mb_orig_substr($p, $l);
if ($s === 0) {
return '';
}
$r = '';
if (mb_orig_strlen($p) < $s) {
Daemon::log('getLV error: buf length (' . mb_orig_strlen($p) . '): ' . Debug::exportBytes($p) . ', must be >= string length (' . $s . ")\n");
} elseif ($nul) {
$lastByte = mb_orig_substr($p, -1);
if ($lastByte !== "\x00") {
Daemon:
log('getLV error: Wrong end of NUL-string (' . Debug::exportBytes($lastByte) . '), len ' . $s . "\n");
} else {
$d = $s - 1;
if ($d < 0) {
$d = 0;
}
$r = mb_orig_substr($p, 0, $d);
$p = mb_orig_substr($p, $s);
}
} else {
$r = mb_orig_substr($p, 0, $s);
$p = mb_orig_substr($p, $s);
}
return $r;
} | [
"public",
"static",
"function",
"getLV",
"(",
"&",
"$",
"p",
",",
"$",
"l",
"=",
"1",
",",
"$",
"nul",
"=",
"false",
",",
"$",
"lrev",
"=",
"false",
")",
"{",
"$",
"s",
"=",
"static",
"::",
"b2i",
"(",
"mb_orig_substr",
"(",
"$",
"p",
",",
"0... | Parse length-value structure
@param string &$p Data
@param integer $l Number of length bytes
@param boolean $nul Nul-terminated? Default is false
@param boolean $lrev Length is little endian?
@return string | [
"Parse",
"length",
"-",
"value",
"structure"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Utils/Binary.php#L340-L368 |
kakserpom/phpdaemon | PHPDaemon/Utils/Binary.php | Binary.flags2bitarray | public static function flags2bitarray($flags, $len = 4)
{
$ret = 0;
foreach ($flags as $v) {
$ret |= $v;
}
return static::i2b($len, $ret);
} | php | public static function flags2bitarray($flags, $len = 4)
{
$ret = 0;
foreach ($flags as $v) {
$ret |= $v;
}
return static::i2b($len, $ret);
} | [
"public",
"static",
"function",
"flags2bitarray",
"(",
"$",
"flags",
",",
"$",
"len",
"=",
"4",
")",
"{",
"$",
"ret",
"=",
"0",
";",
"foreach",
"(",
"$",
"flags",
"as",
"$",
"v",
")",
"{",
"$",
"ret",
"|=",
"$",
"v",
";",
"}",
"return",
"static... | Convert array of flags into bit array
@param array $flags Flags
@param integer $len Length. Default is 4
@return string | [
"Convert",
"array",
"of",
"flags",
"into",
"bit",
"array"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Utils/Binary.php#L388-L395 |
kakserpom/phpdaemon | PHPDaemon/Utils/Binary.php | Binary.bitmap2bytes | public static function bitmap2bytes($bitmap, $check_len = 0)
{
$r = '';
$bitmap = str_pad($bitmap, ceil(mb_orig_strlen($bitmap) / 8) * 8, '0', STR_PAD_LEFT);
for ($i = 0, $n = mb_orig_strlen($bitmap) / 8; $i < $n; ++$i) {
$r .= chr((int)bindec(mb_orig_substr($bitmap, $i * 8, 8)));
}
if ($check_len && (mb_orig_strlen($r) !== $check_len)) {
return false;
}
return $r;
} | php | public static function bitmap2bytes($bitmap, $check_len = 0)
{
$r = '';
$bitmap = str_pad($bitmap, ceil(mb_orig_strlen($bitmap) / 8) * 8, '0', STR_PAD_LEFT);
for ($i = 0, $n = mb_orig_strlen($bitmap) / 8; $i < $n; ++$i) {
$r .= chr((int)bindec(mb_orig_substr($bitmap, $i * 8, 8)));
}
if ($check_len && (mb_orig_strlen($r) !== $check_len)) {
return false;
}
return $r;
} | [
"public",
"static",
"function",
"bitmap2bytes",
"(",
"$",
"bitmap",
",",
"$",
"check_len",
"=",
"0",
")",
"{",
"$",
"r",
"=",
"''",
";",
"$",
"bitmap",
"=",
"str_pad",
"(",
"$",
"bitmap",
",",
"ceil",
"(",
"mb_orig_strlen",
"(",
"$",
"bitmap",
")",
... | Convert bitmap into bytes
@param string $bitmap Bitmap
@param integer $check_len Check length?
@return string|false | [
"Convert",
"bitmap",
"into",
"bytes"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Utils/Binary.php#L403-L414 |
kakserpom/phpdaemon | PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Connection/ConnectionStartOkFrame.php | ConnectionStartOkFrame.create | public static function create(
$clientProperties = null, $mechanism = null, $response = null, $locale = null
)
{
$frame = new self();
if (null !== $clientProperties) {
$frame->clientProperties = $clientProperties;
}
if (null !== $mechanism) {
$frame->mechanism = $mechanism;
}
if (null !== $response) {
$frame->response = $response;
}
if (null !== $locale) {
$frame->locale = $locale;
}
return $frame;
} | php | public static function create(
$clientProperties = null, $mechanism = null, $response = null, $locale = null
)
{
$frame = new self();
if (null !== $clientProperties) {
$frame->clientProperties = $clientProperties;
}
if (null !== $mechanism) {
$frame->mechanism = $mechanism;
}
if (null !== $response) {
$frame->response = $response;
}
if (null !== $locale) {
$frame->locale = $locale;
}
return $frame;
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"clientProperties",
"=",
"null",
",",
"$",
"mechanism",
"=",
"null",
",",
"$",
"response",
"=",
"null",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"frame",
"=",
"new",
"self",
"(",
")",
";",
... | shortstr | [
"shortstr"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Connection/ConnectionStartOkFrame.php#L23-L43 |
kakserpom/phpdaemon | PHPDaemon/Core/ClassFinder.php | ClassFinder.find | public static function find($class, $namespace = null, $rootns = null)
{
$e = explode('\\', $class);
if ($e[0] === '') {
return $class;
}
if ('Pool' === $class || 'TransportContext' === $class) {
return '\\PHPDaemon\\Core\\' . $class;
}
if (strpos($class, '\\') === false && $namespace === null) {
if ('Example' === substr($class, 0, 7)) {
array_unshift($e, 'Examples');
}
if ('Server' === substr($class, -6)) {
$path = '\\PHPDaemon\\Servers\\' . substr($class, 0, -6) . '\\Pool';
$r = str_replace('\\Servers\\Servers', '\\Servers', $path);
Daemon::log('ClassFinder: \'' . $class . '\' -> \'' . $r . '\', you should change your code.');
return $r;
}
if ('Client' === substr($class, -6)) {
$path = '\\PHPDaemon\\Clients\\' . substr($class, 0, -6) . '\\Pool';
$r = str_replace('\\Clients\\Clients', '\\Clients', $path);
Daemon::log('ClassFinder: \'' . $class . '\' -> \'' . $r . '\', you should change your code.');
return $r;
}
if ('ClientAsync' === substr($class, -11)) {
$path = '\\PHPDaemon\\Clients\\' . substr($class, 0, -11) . '\\Pool';
$r = str_replace('\\Client\\Clients', '\\Clients', $path);
Daemon::log('ClassFinder: \'' . $class . '\' -> \'' . $r . '\', you should change your code.');
return $r;
}
}
if ($namespace !== null && sizeof($e) < 2) {
array_unshift($e, $namespace);
}
if ($rootns !== '~') {
array_unshift($e, '\\' . ($rootns !== null ? $rootns : Daemon::$config->defaultns->value));
}
return implode('\\', $e);
} | php | public static function find($class, $namespace = null, $rootns = null)
{
$e = explode('\\', $class);
if ($e[0] === '') {
return $class;
}
if ('Pool' === $class || 'TransportContext' === $class) {
return '\\PHPDaemon\\Core\\' . $class;
}
if (strpos($class, '\\') === false && $namespace === null) {
if ('Example' === substr($class, 0, 7)) {
array_unshift($e, 'Examples');
}
if ('Server' === substr($class, -6)) {
$path = '\\PHPDaemon\\Servers\\' . substr($class, 0, -6) . '\\Pool';
$r = str_replace('\\Servers\\Servers', '\\Servers', $path);
Daemon::log('ClassFinder: \'' . $class . '\' -> \'' . $r . '\', you should change your code.');
return $r;
}
if ('Client' === substr($class, -6)) {
$path = '\\PHPDaemon\\Clients\\' . substr($class, 0, -6) . '\\Pool';
$r = str_replace('\\Clients\\Clients', '\\Clients', $path);
Daemon::log('ClassFinder: \'' . $class . '\' -> \'' . $r . '\', you should change your code.');
return $r;
}
if ('ClientAsync' === substr($class, -11)) {
$path = '\\PHPDaemon\\Clients\\' . substr($class, 0, -11) . '\\Pool';
$r = str_replace('\\Client\\Clients', '\\Clients', $path);
Daemon::log('ClassFinder: \'' . $class . '\' -> \'' . $r . '\', you should change your code.');
return $r;
}
}
if ($namespace !== null && sizeof($e) < 2) {
array_unshift($e, $namespace);
}
if ($rootns !== '~') {
array_unshift($e, '\\' . ($rootns !== null ? $rootns : Daemon::$config->defaultns->value));
}
return implode('\\', $e);
} | [
"public",
"static",
"function",
"find",
"(",
"$",
"class",
",",
"$",
"namespace",
"=",
"null",
",",
"$",
"rootns",
"=",
"null",
")",
"{",
"$",
"e",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"class",
")",
";",
"if",
"(",
"$",
"e",
"[",
"0",
"]",
... | Find class
@param string $class Class
@param string $namespace Namespace
@param string $rootns Root namespace
@return string | [
"Find",
"class"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Core/ClassFinder.php#L43-L82 |
kakserpom/phpdaemon | PHPDaemon/Clients/Redis/Examples/Scan.php | Scan.onReady | public function onReady()
{
$this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance();
$params = [];
foreach (range(0, 100) as $i) {
$params[] = 'myset' . $i;
$params[] = 'value' . $i;
}
$params[] = function ($redis) {
$params = [
function ($redis) {
D('Count: ' . count($redis->result[1]) . '; Next: ' . $redis->result[0]);
}
];
$cbEnd = function ($redis, $scan) {
D('Full scan end!');
};
// test 1
// $this->redis->scan(...$params);
// test 2
$this->redis->autoscan('scan', $params, $cbEnd, 50);
};
$this->redis->mset(...$params);
} | php | public function onReady()
{
$this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance();
$params = [];
foreach (range(0, 100) as $i) {
$params[] = 'myset' . $i;
$params[] = 'value' . $i;
}
$params[] = function ($redis) {
$params = [
function ($redis) {
D('Count: ' . count($redis->result[1]) . '; Next: ' . $redis->result[0]);
}
];
$cbEnd = function ($redis, $scan) {
D('Full scan end!');
};
// test 1
// $this->redis->scan(...$params);
// test 2
$this->redis->autoscan('scan', $params, $cbEnd, 50);
};
$this->redis->mset(...$params);
} | [
"public",
"function",
"onReady",
"(",
")",
"{",
"$",
"this",
"->",
"redis",
"=",
"\\",
"PHPDaemon",
"\\",
"Clients",
"\\",
"Redis",
"\\",
"Pool",
"::",
"getInstance",
"(",
")",
";",
"$",
"params",
"=",
"[",
"]",
";",
"foreach",
"(",
"range",
"(",
"... | Called when the worker is ready to go
@return void | [
"Called",
"when",
"the",
"worker",
"is",
"ready",
"to",
"go"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/Redis/Examples/Scan.php#L24-L51 |
kakserpom/phpdaemon | PHPDaemon/Examples/MongoNode.php | MongoNode.init | public function init()
{
$this->db = \PHPDaemon\Clients\Mongo\Pool::getInstance($this->config->mongoclientname->value);
$this->cache = \PHPDaemon\Clients\Memcache\Pool::getInstance($this->config->memcacheclientname->value);
if (!isset($this->config->limitinstances)) {
$this->log('missing \'limitInstances\' directive');
}
} | php | public function init()
{
$this->db = \PHPDaemon\Clients\Mongo\Pool::getInstance($this->config->mongoclientname->value);
$this->cache = \PHPDaemon\Clients\Memcache\Pool::getInstance($this->config->memcacheclientname->value);
if (!isset($this->config->limitinstances)) {
$this->log('missing \'limitInstances\' directive');
}
} | [
"public",
"function",
"init",
"(",
")",
"{",
"$",
"this",
"->",
"db",
"=",
"\\",
"PHPDaemon",
"\\",
"Clients",
"\\",
"Mongo",
"\\",
"Pool",
"::",
"getInstance",
"(",
"$",
"this",
"->",
"config",
"->",
"mongoclientname",
"->",
"value",
")",
";",
"$",
... | Constructor.
@return void | [
"Constructor",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Examples/MongoNode.php#L24-L31 |
kakserpom/phpdaemon | PHPDaemon/Examples/MongoNode.php | MongoNode.onReady | public function onReady()
{
if ($this->config->enable->value) {
$this->timer = setTimeout(function ($timer) {
$this->touchCursor();
}, 0.3e6);
}
} | php | public function onReady()
{
if ($this->config->enable->value) {
$this->timer = setTimeout(function ($timer) {
$this->touchCursor();
}, 0.3e6);
}
} | [
"public",
"function",
"onReady",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"enable",
"->",
"value",
")",
"{",
"$",
"this",
"->",
"timer",
"=",
"setTimeout",
"(",
"function",
"(",
"$",
"timer",
")",
"{",
"$",
"this",
"->",
"touchC... | Called when the worker is ready to go.
@return void | [
"Called",
"when",
"the",
"worker",
"is",
"ready",
"to",
"go",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Examples/MongoNode.php#L37-L44 |
kakserpom/phpdaemon | PHPDaemon/Examples/MongoNode.php | MongoNode.initSlave | public function initSlave($point)
{
$this->db->{'local.oplog.$main'}->find(
/**
* @param \MongoTimestamp $cursor
*/
function ($cursor) {
$this->cursor = $cursor;
$cursor->state = 1;
$cursor->lastOpId = null;
foreach ($cursor->items as $k => &$item) {
if (\PHPDaemon\Core\Daemon::$config->logevents->value) {
\PHPDaemon\Core\Daemon::log(get_class($this) . ': caught oplog-record with ts = (' . \PHPDaemon\Core\Debug::dump($item['ts']) . ')');
}
$cursor->lastOpId = $item['ts'];
if ($item['op'] === 'i') {
$this->cacheObject($item['o']);
} elseif ($item['op'] === 'd') {
$this->deleteObject($item['o']);
} elseif ($item['op'] === 'u') {
if (
isset($item['b'])
&& ($item['b'] === false)
) {
$item['o']['_id'] = $item['o2']['_id'];
$this->cacheObject($item['o']);
} else {
$cursor->appInstance->{$item['ns']}->findOne(
/**
* @param \MongoTimestamp $item
*/
function ($item) {
$this->cacheObject($item);
},
['where' => ['_id' => $item['o2']['_id']]]
);
}
}
unset($cursor->items[$k]);
}
}, [
'tailable' => true,
'sort' => ['$natural' => 1],
'snapshot' => 1,
'where' => [
'ts' => [
'$gt' => $point
],
'$exists' => [
'_key' => true
]
],
'parse_oplog' => true,
]
);
} | php | public function initSlave($point)
{
$this->db->{'local.oplog.$main'}->find(
/**
* @param \MongoTimestamp $cursor
*/
function ($cursor) {
$this->cursor = $cursor;
$cursor->state = 1;
$cursor->lastOpId = null;
foreach ($cursor->items as $k => &$item) {
if (\PHPDaemon\Core\Daemon::$config->logevents->value) {
\PHPDaemon\Core\Daemon::log(get_class($this) . ': caught oplog-record with ts = (' . \PHPDaemon\Core\Debug::dump($item['ts']) . ')');
}
$cursor->lastOpId = $item['ts'];
if ($item['op'] === 'i') {
$this->cacheObject($item['o']);
} elseif ($item['op'] === 'd') {
$this->deleteObject($item['o']);
} elseif ($item['op'] === 'u') {
if (
isset($item['b'])
&& ($item['b'] === false)
) {
$item['o']['_id'] = $item['o2']['_id'];
$this->cacheObject($item['o']);
} else {
$cursor->appInstance->{$item['ns']}->findOne(
/**
* @param \MongoTimestamp $item
*/
function ($item) {
$this->cacheObject($item);
},
['where' => ['_id' => $item['o2']['_id']]]
);
}
}
unset($cursor->items[$k]);
}
}, [
'tailable' => true,
'sort' => ['$natural' => 1],
'snapshot' => 1,
'where' => [
'ts' => [
'$gt' => $point
],
'$exists' => [
'_key' => true
]
],
'parse_oplog' => true,
]
);
} | [
"public",
"function",
"initSlave",
"(",
"$",
"point",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"{",
"'local.oplog.$main'",
"}",
"->",
"find",
"(",
"/**\n * @param \\MongoTimestamp $cursor\n */",
"function",
"(",
"$",
"cursor",
")",
"{",
"$",
"thi... | Initializes slave session.
@param object Object.
@param \MongoTimestamp $point
@return void | [
"Initializes",
"slave",
"session",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Examples/MongoNode.php#L91-L152 |
kakserpom/phpdaemon | PHPDaemon/Examples/MongoNode.php | MongoNode.cacheObject | public function cacheObject($o)
{
if (\PHPDaemon\Core\Daemon::$config->logevents->value) {
\PHPDaemon\Core\Daemon::log(__METHOD__ . '(' . json_encode($o) . ')');
}
if (isset($o['_key'])) {
$this->cache->set($o['_key'], bson_encode($o));
$this->cache->set('_id.' . ((string)$o['_id']), $o['_key']);
}
if (isset($o['_ev'])) {
$o['name'] = $o['_ev'];
if (\PHPDaemon\Core\Daemon::$config->logevents->value) {
\PHPDaemon\Core\Daemon::log('MongoNode send event ' . $o['name']);
}
}
} | php | public function cacheObject($o)
{
if (\PHPDaemon\Core\Daemon::$config->logevents->value) {
\PHPDaemon\Core\Daemon::log(__METHOD__ . '(' . json_encode($o) . ')');
}
if (isset($o['_key'])) {
$this->cache->set($o['_key'], bson_encode($o));
$this->cache->set('_id.' . ((string)$o['_id']), $o['_key']);
}
if (isset($o['_ev'])) {
$o['name'] = $o['_ev'];
if (\PHPDaemon\Core\Daemon::$config->logevents->value) {
\PHPDaemon\Core\Daemon::log('MongoNode send event ' . $o['name']);
}
}
} | [
"public",
"function",
"cacheObject",
"(",
"$",
"o",
")",
"{",
"if",
"(",
"\\",
"PHPDaemon",
"\\",
"Core",
"\\",
"Daemon",
"::",
"$",
"config",
"->",
"logevents",
"->",
"value",
")",
"{",
"\\",
"PHPDaemon",
"\\",
"Core",
"\\",
"Daemon",
"::",
"log",
"... | Method called when object received.
@param object Object.
@return void | [
"Method",
"called",
"when",
"object",
"received",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Examples/MongoNode.php#L159-L177 |
kakserpom/phpdaemon | PHPDaemon/Examples/MongoNode.php | MongoNode.deleteObject | public function deleteObject($o)
{
if (\PHPDaemon\Core\Daemon::$config->logevents->value) {
\PHPDaemon\Core\Daemon::log(__METHOD__ . '(' . json_encode($o) . ')');
}
$this->cache->get('_id.' . ((string)$o['_id']),
function ($mc) use ($o) {
if (is_string($m->result)) {
$mc->delete($m->result);
$mc->delete('_id.' . $o['_id']);
}
}
);
} | php | public function deleteObject($o)
{
if (\PHPDaemon\Core\Daemon::$config->logevents->value) {
\PHPDaemon\Core\Daemon::log(__METHOD__ . '(' . json_encode($o) . ')');
}
$this->cache->get('_id.' . ((string)$o['_id']),
function ($mc) use ($o) {
if (is_string($m->result)) {
$mc->delete($m->result);
$mc->delete('_id.' . $o['_id']);
}
}
);
} | [
"public",
"function",
"deleteObject",
"(",
"$",
"o",
")",
"{",
"if",
"(",
"\\",
"PHPDaemon",
"\\",
"Core",
"\\",
"Daemon",
"::",
"$",
"config",
"->",
"logevents",
"->",
"value",
")",
"{",
"\\",
"PHPDaemon",
"\\",
"Core",
"\\",
"Daemon",
"::",
"log",
... | Method called when object deleted.
@param object Object.
@return void | [
"Method",
"called",
"when",
"object",
"deleted",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Examples/MongoNode.php#L184-L198 |
kakserpom/phpdaemon | PHPDaemon/Servers/FlashPolicy/Connection.php | Connection.onRead | public function onRead()
{
if (false === ($pct = $this->readExact($this->lowMark))) {
return; // not readed yet
}
if ($pct === "<policy-file-request/>\x00") {
if ($this->pool->policyData) {
$this->write($p = $this->pool->policyData . "\x00");
} else {
$this->write("<error/>\x00");
}
}
$this->finish();
} | php | public function onRead()
{
if (false === ($pct = $this->readExact($this->lowMark))) {
return; // not readed yet
}
if ($pct === "<policy-file-request/>\x00") {
if ($this->pool->policyData) {
$this->write($p = $this->pool->policyData . "\x00");
} else {
$this->write("<error/>\x00");
}
}
$this->finish();
} | [
"public",
"function",
"onRead",
"(",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"$",
"pct",
"=",
"$",
"this",
"->",
"readExact",
"(",
"$",
"this",
"->",
"lowMark",
")",
")",
")",
"{",
"return",
";",
"// not readed yet",
"}",
"if",
"(",
"$",
"pct",
... | Called when new data received
@return void | [
"Called",
"when",
"new",
"data",
"received"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/FlashPolicy/Connection.php#L25-L38 |
kakserpom/phpdaemon | PHPDaemon/Thread/Collection.php | Collection.push | public function push(Generic $thread)
{
$id = ++$this->spawnCounter;
$thread->setId($id);
$this->threads[$id] = $thread;
} | php | public function push(Generic $thread)
{
$id = ++$this->spawnCounter;
$thread->setId($id);
$this->threads[$id] = $thread;
} | [
"public",
"function",
"push",
"(",
"Generic",
"$",
"thread",
")",
"{",
"$",
"id",
"=",
"++",
"$",
"this",
"->",
"spawnCounter",
";",
"$",
"thread",
"->",
"setId",
"(",
"$",
"id",
")",
";",
"$",
"this",
"->",
"threads",
"[",
"$",
"id",
"]",
"=",
... | Pushes certain thread to the collection
@param Generic Generic to push
@return void | [
"Pushes",
"certain",
"thread",
"to",
"the",
"collection"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Thread/Collection.php#L33-L38 |
kakserpom/phpdaemon | PHPDaemon/Thread/Collection.php | Collection.stop | public function stop($kill = false)
{
foreach ($this->threads as $thread) {
$thread->stop($kill);
}
} | php | public function stop($kill = false)
{
foreach ($this->threads as $thread) {
$thread->stop($kill);
}
} | [
"public",
"function",
"stop",
"(",
"$",
"kill",
"=",
"false",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"threads",
"as",
"$",
"thread",
")",
"{",
"$",
"thread",
"->",
"stop",
"(",
"$",
"kill",
")",
";",
"}",
"}"
] | Stop all collected threads
@param boolean Kill?
@return void | [
"Stop",
"all",
"collected",
"threads"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Thread/Collection.php#L56-L61 |
kakserpom/phpdaemon | PHPDaemon/Thread/Collection.php | Collection.removeTerminated | public function removeTerminated()
{
// @TODO: remove
$n = 0;
foreach ($this->threads as $id => $thread) {
if (!$thread->getPid() || !$thread->ifExists()) {
$thread->setTerminated();
unset($this->threads[$id]);
continue;
}
++$n;
}
return $n;
} | php | public function removeTerminated()
{
// @TODO: remove
$n = 0;
foreach ($this->threads as $id => $thread) {
if (!$thread->getPid() || !$thread->ifExists()) {
$thread->setTerminated();
unset($this->threads[$id]);
continue;
}
++$n;
}
return $n;
} | [
"public",
"function",
"removeTerminated",
"(",
")",
"{",
"// @TODO: remove",
"$",
"n",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"threads",
"as",
"$",
"id",
"=>",
"$",
"thread",
")",
"{",
"if",
"(",
"!",
"$",
"thread",
"->",
"getPid",
"(",
... | Remove terminated threads from the collection
@return integer Rest threads count | [
"Remove",
"terminated",
"threads",
"from",
"the",
"collection"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Thread/Collection.php#L76-L89 |
kakserpom/phpdaemon | PHPDaemon/FS/FileSystem.php | FileSystem.init | public static function init()
{
if (!Daemon::$config->eioenabled->value) {
self::$supported = false;
return;
}
if (!self::$supported = Daemon::loadModuleIfAbsent('eio', self::$eioVer)) {
Daemon::log('FS: missing pecl-eio >= ' . self::$eioVer . '. Filesystem I/O performance compromised. Consider installing pecl-eio. `pecl install http://pecl.php.net/get/eio`');
return;
}
self::$fdCache = new CappedStorageHits(self::$fdCacheSize);
eio_init();
} | php | public static function init()
{
if (!Daemon::$config->eioenabled->value) {
self::$supported = false;
return;
}
if (!self::$supported = Daemon::loadModuleIfAbsent('eio', self::$eioVer)) {
Daemon::log('FS: missing pecl-eio >= ' . self::$eioVer . '. Filesystem I/O performance compromised. Consider installing pecl-eio. `pecl install http://pecl.php.net/get/eio`');
return;
}
self::$fdCache = new CappedStorageHits(self::$fdCacheSize);
eio_init();
} | [
"public",
"static",
"function",
"init",
"(",
")",
"{",
"if",
"(",
"!",
"Daemon",
"::",
"$",
"config",
"->",
"eioenabled",
"->",
"value",
")",
"{",
"self",
"::",
"$",
"supported",
"=",
"false",
";",
"return",
";",
"}",
"if",
"(",
"!",
"self",
"::",
... | Initialize FS driver
@return void | [
"Initialize",
"FS",
"driver"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L73-L85 |
kakserpom/phpdaemon | PHPDaemon/FS/FileSystem.php | FileSystem.initEvent | public static function initEvent()
{
if (!self::$supported) {
return;
}
self::updateConfig();
self::$fd = eio_get_event_stream();
self::$ev = EventLoop::$instance->event(self::$fd,
\Event::READ | \Event::PERSIST,
function ($fd, $events, $arg) {
while (eio_nreqs()) {
eio_poll();
}
}
);
self::$ev->add();
} | php | public static function initEvent()
{
if (!self::$supported) {
return;
}
self::updateConfig();
self::$fd = eio_get_event_stream();
self::$ev = EventLoop::$instance->event(self::$fd,
\Event::READ | \Event::PERSIST,
function ($fd, $events, $arg) {
while (eio_nreqs()) {
eio_poll();
}
}
);
self::$ev->add();
} | [
"public",
"static",
"function",
"initEvent",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"supported",
")",
"{",
"return",
";",
"}",
"self",
"::",
"updateConfig",
"(",
")",
";",
"self",
"::",
"$",
"fd",
"=",
"eio_get_event_stream",
"(",
")",
";"... | Initialize main FS event
@return void | [
"Initialize",
"main",
"FS",
"event"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L96-L112 |
kakserpom/phpdaemon | PHPDaemon/FS/FileSystem.php | FileSystem.updateConfig | public static function updateConfig()
{
if (Daemon::$config->eiosetmaxidle->value !== null) {
eio_set_max_idle(Daemon::$config->eiosetmaxidle->value);
}
if (Daemon::$config->eiosetmaxparallel->value !== null) {
eio_set_max_parallel(Daemon::$config->eiosetmaxparallel->value);
}
if (Daemon::$config->eiosetmaxpollreqs->value !== null) {
eio_set_max_poll_reqs(Daemon::$config->eiosetmaxpollreqs->value);
}
if (Daemon::$config->eiosetmaxpolltime->value !== null) {
eio_set_max_poll_time(Daemon::$config->eiosetmaxpolltime->value);
}
if (Daemon::$config->eiosetminparallel->value !== null) {
eio_set_min_parallel(Daemon::$config->eiosetminparallel->value);
}
} | php | public static function updateConfig()
{
if (Daemon::$config->eiosetmaxidle->value !== null) {
eio_set_max_idle(Daemon::$config->eiosetmaxidle->value);
}
if (Daemon::$config->eiosetmaxparallel->value !== null) {
eio_set_max_parallel(Daemon::$config->eiosetmaxparallel->value);
}
if (Daemon::$config->eiosetmaxpollreqs->value !== null) {
eio_set_max_poll_reqs(Daemon::$config->eiosetmaxpollreqs->value);
}
if (Daemon::$config->eiosetmaxpolltime->value !== null) {
eio_set_max_poll_time(Daemon::$config->eiosetmaxpolltime->value);
}
if (Daemon::$config->eiosetminparallel->value !== null) {
eio_set_min_parallel(Daemon::$config->eiosetminparallel->value);
}
} | [
"public",
"static",
"function",
"updateConfig",
"(",
")",
"{",
"if",
"(",
"Daemon",
"::",
"$",
"config",
"->",
"eiosetmaxidle",
"->",
"value",
"!==",
"null",
")",
"{",
"eio_set_max_idle",
"(",
"Daemon",
"::",
"$",
"config",
"->",
"eiosetmaxidle",
"->",
"va... | Called when config is updated
@return void | [
"Called",
"when",
"config",
"is",
"updated"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L142-L159 |
kakserpom/phpdaemon | PHPDaemon/FS/FileSystem.php | FileSystem.stat | public static function stat($path, $cb, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!self::$supported) {
$cb($path, FileSystem::statPrepare(@stat($path)));
return true;
}
return eio_stat($path, $pri, function ($path, $stat) use ($cb) {
$cb($path, FileSystem::statPrepare($stat));
}, $path);
} | php | public static function stat($path, $cb, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!self::$supported) {
$cb($path, FileSystem::statPrepare(@stat($path)));
return true;
}
return eio_stat($path, $pri, function ($path, $stat) use ($cb) {
$cb($path, FileSystem::statPrepare($stat));
}, $path);
} | [
"public",
"static",
"function",
"stat",
"(",
"$",
"path",
",",
"$",
"cb",
",",
"$",
"pri",
"=",
"EIO_PRI_DEFAULT",
")",
"{",
"$",
"cb",
"=",
"CallbackWrapper",
"::",
"forceWrap",
"(",
"$",
"cb",
")",
";",
"if",
"(",
"!",
"self",
"::",
"$",
"support... | Gets stat() information
@param string $path Path
@param callable $cb Callback
@param integer $pri Priority
@return resource|true | [
"Gets",
"stat",
"()",
"information"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L192-L202 |
kakserpom/phpdaemon | PHPDaemon/FS/FileSystem.php | FileSystem.unlink | public static function unlink($path, $cb = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!self::$supported) {
$r = unlink($path);
if ($cb) {
$cb($path, $r);
}
return $r;
}
return eio_unlink($path, $pri, $cb, $path);
} | php | public static function unlink($path, $cb = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!self::$supported) {
$r = unlink($path);
if ($cb) {
$cb($path, $r);
}
return $r;
}
return eio_unlink($path, $pri, $cb, $path);
} | [
"public",
"static",
"function",
"unlink",
"(",
"$",
"path",
",",
"$",
"cb",
"=",
"null",
",",
"$",
"pri",
"=",
"EIO_PRI_DEFAULT",
")",
"{",
"$",
"cb",
"=",
"CallbackWrapper",
"::",
"forceWrap",
"(",
"$",
"cb",
")",
";",
"if",
"(",
"!",
"self",
"::"... | Unlink file
@param string $path Path
@param callable $cb Callback
@param integer $pri Priority
@return resource|boolean | [
"Unlink",
"file"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L211-L222 |
kakserpom/phpdaemon | PHPDaemon/FS/FileSystem.php | FileSystem.rename | public static function rename($path, $newpath, $cb = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!self::$supported) {
$r = rename($path, $newpath);
if ($cb) {
$cb($path, $newpath, $r);
}
return $r;
}
return eio_rename($path, $newpath, $pri, $cb, $path);
} | php | public static function rename($path, $newpath, $cb = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!self::$supported) {
$r = rename($path, $newpath);
if ($cb) {
$cb($path, $newpath, $r);
}
return $r;
}
return eio_rename($path, $newpath, $pri, $cb, $path);
} | [
"public",
"static",
"function",
"rename",
"(",
"$",
"path",
",",
"$",
"newpath",
",",
"$",
"cb",
"=",
"null",
",",
"$",
"pri",
"=",
"EIO_PRI_DEFAULT",
")",
"{",
"$",
"cb",
"=",
"CallbackWrapper",
"::",
"forceWrap",
"(",
"$",
"cb",
")",
";",
"if",
"... | Rename
@param string $path Path
@param string $newpath New path
@param callable $cb Callback
@param integer $pri Priority
@return resource|boolean | [
"Rename"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L232-L243 |
kakserpom/phpdaemon | PHPDaemon/FS/FileSystem.php | FileSystem.statvfs | public static function statvfs($path, $cb, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!self::$supported) {
$cb($path, false);
return false;
}
return eio_statvfs($path, $pri, $cb, $path);
} | php | public static function statvfs($path, $cb, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!self::$supported) {
$cb($path, false);
return false;
}
return eio_statvfs($path, $pri, $cb, $path);
} | [
"public",
"static",
"function",
"statvfs",
"(",
"$",
"path",
",",
"$",
"cb",
",",
"$",
"pri",
"=",
"EIO_PRI_DEFAULT",
")",
"{",
"$",
"cb",
"=",
"CallbackWrapper",
"::",
"forceWrap",
"(",
"$",
"cb",
")",
";",
"if",
"(",
"!",
"self",
"::",
"$",
"supp... | statvfs()
@param string $path Path
@param callable $cb Callback
@param integer $pri Priority
@return resource|false | [
"statvfs",
"()"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L252-L260 |
kakserpom/phpdaemon | PHPDaemon/FS/FileSystem.php | FileSystem.realpath | public static function realpath($path, $cb, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!self::$supported) {
$cb($path, realpath($path));
return true;
}
return eio_realpath($path, $pri, $cb, $path);
} | php | public static function realpath($path, $cb, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!self::$supported) {
$cb($path, realpath($path));
return true;
}
return eio_realpath($path, $pri, $cb, $path);
} | [
"public",
"static",
"function",
"realpath",
"(",
"$",
"path",
",",
"$",
"cb",
",",
"$",
"pri",
"=",
"EIO_PRI_DEFAULT",
")",
"{",
"$",
"cb",
"=",
"CallbackWrapper",
"::",
"forceWrap",
"(",
"$",
"cb",
")",
";",
"if",
"(",
"!",
"self",
"::",
"$",
"sup... | realpath()
@param string $path Path
@param callable $cb Callback
@param integer $pri Priority
@return resource|true | [
"realpath",
"()"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L288-L296 |
kakserpom/phpdaemon | PHPDaemon/FS/FileSystem.php | FileSystem.sync | public static function sync($cb = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!self::$supported) {
if ($cb) {
$cb(false);
}
return false;
}
return eio_sync($pri, $cb);
} | php | public static function sync($cb = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!self::$supported) {
if ($cb) {
$cb(false);
}
return false;
}
return eio_sync($pri, $cb);
} | [
"public",
"static",
"function",
"sync",
"(",
"$",
"cb",
"=",
"null",
",",
"$",
"pri",
"=",
"EIO_PRI_DEFAULT",
")",
"{",
"$",
"cb",
"=",
"CallbackWrapper",
"::",
"forceWrap",
"(",
"$",
"cb",
")",
";",
"if",
"(",
"!",
"self",
"::",
"$",
"supported",
... | sync()
@param callable $cb Callback
@param integer $pri Priority
@return resource|false | [
"sync",
"()"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L304-L314 |
kakserpom/phpdaemon | PHPDaemon/FS/FileSystem.php | FileSystem.syncfs | public static function syncfs($cb = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!self::$supported) {
if ($cb) {
$cb(false);
}
return false;
}
return eio_syncfs($pri, $cb);
} | php | public static function syncfs($cb = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!self::$supported) {
if ($cb) {
$cb(false);
}
return false;
}
return eio_syncfs($pri, $cb);
} | [
"public",
"static",
"function",
"syncfs",
"(",
"$",
"cb",
"=",
"null",
",",
"$",
"pri",
"=",
"EIO_PRI_DEFAULT",
")",
"{",
"$",
"cb",
"=",
"CallbackWrapper",
"::",
"forceWrap",
"(",
"$",
"cb",
")",
";",
"if",
"(",
"!",
"self",
"::",
"$",
"supported",
... | statfs()
@param callable $cb Callback
@param integer $pri Priority
@return resource|false | [
"statfs",
"()"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L322-L332 |
kakserpom/phpdaemon | PHPDaemon/FS/FileSystem.php | FileSystem.touch | public static function touch($path, $mtime, $atime = null, $cb = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!FileSystem::$supported) {
$r = touch($path, $mtime, $atime);
if ($cb) {
$cb($r);
}
return $r;
}
return eio_utime($path, $atime, $mtime, $pri, $cb, $path);
} | php | public static function touch($path, $mtime, $atime = null, $cb = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!FileSystem::$supported) {
$r = touch($path, $mtime, $atime);
if ($cb) {
$cb($r);
}
return $r;
}
return eio_utime($path, $atime, $mtime, $pri, $cb, $path);
} | [
"public",
"static",
"function",
"touch",
"(",
"$",
"path",
",",
"$",
"mtime",
",",
"$",
"atime",
"=",
"null",
",",
"$",
"cb",
"=",
"null",
",",
"$",
"pri",
"=",
"EIO_PRI_DEFAULT",
")",
"{",
"$",
"cb",
"=",
"CallbackWrapper",
"::",
"forceWrap",
"(",
... | touch()
@param string $path Path
@param integer $mtime Last modification time
@param integer $atime Last access time
@param callable $cb Callback
@param integer $pri Priority
@return resource|boolean | [
"touch",
"()"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L343-L354 |
kakserpom/phpdaemon | PHPDaemon/FS/FileSystem.php | FileSystem.rmdir | public static function rmdir($path, $cb = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!FileSystem::$supported) {
$r = rmdir($path);
if ($cb) {
$cb($path, $r);
}
return $r;
}
return eio_rmdir($path, $pri, $cb, $path);
} | php | public static function rmdir($path, $cb = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!FileSystem::$supported) {
$r = rmdir($path);
if ($cb) {
$cb($path, $r);
}
return $r;
}
return eio_rmdir($path, $pri, $cb, $path);
} | [
"public",
"static",
"function",
"rmdir",
"(",
"$",
"path",
",",
"$",
"cb",
"=",
"null",
",",
"$",
"pri",
"=",
"EIO_PRI_DEFAULT",
")",
"{",
"$",
"cb",
"=",
"CallbackWrapper",
"::",
"forceWrap",
"(",
"$",
"cb",
")",
";",
"if",
"(",
"!",
"FileSystem",
... | Removes empty directory
@param string $path Path
@param callable $cb Callback
@param integer $pri Priority
@return resource|boolean | [
"Removes",
"empty",
"directory"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L363-L374 |
kakserpom/phpdaemon | PHPDaemon/FS/FileSystem.php | FileSystem.mkdir | public static function mkdir($path, $mode, $cb = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!FileSystem::$supported) {
$r = mkdir($path, $mode);
if ($cb) {
$cb($path, $r);
}
return $r;
}
return eio_mkdir($path, $mode, $pri, $cb, $path);
} | php | public static function mkdir($path, $mode, $cb = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!FileSystem::$supported) {
$r = mkdir($path, $mode);
if ($cb) {
$cb($path, $r);
}
return $r;
}
return eio_mkdir($path, $mode, $pri, $cb, $path);
} | [
"public",
"static",
"function",
"mkdir",
"(",
"$",
"path",
",",
"$",
"mode",
",",
"$",
"cb",
"=",
"null",
",",
"$",
"pri",
"=",
"EIO_PRI_DEFAULT",
")",
"{",
"$",
"cb",
"=",
"CallbackWrapper",
"::",
"forceWrap",
"(",
"$",
"cb",
")",
";",
"if",
"(",
... | Creates directory
@param string $path Path
@param integer $mode Mode (octal)
@param callable $cb Callback
@param integer $pri Priority
@return resource|boolean | [
"Creates",
"directory"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L384-L395 |
kakserpom/phpdaemon | PHPDaemon/FS/FileSystem.php | FileSystem.readdir | public static function readdir($path, $cb = null, $flags = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!FileSystem::$supported) {
$r = glob($path);
if ($cb) {
$cb($path, $r);
}
return true;
}
return eio_readdir($path, $flags, $pri, $cb, $path);
} | php | public static function readdir($path, $cb = null, $flags = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!FileSystem::$supported) {
$r = glob($path);
if ($cb) {
$cb($path, $r);
}
return true;
}
return eio_readdir($path, $flags, $pri, $cb, $path);
} | [
"public",
"static",
"function",
"readdir",
"(",
"$",
"path",
",",
"$",
"cb",
"=",
"null",
",",
"$",
"flags",
"=",
"null",
",",
"$",
"pri",
"=",
"EIO_PRI_DEFAULT",
")",
"{",
"$",
"cb",
"=",
"CallbackWrapper",
"::",
"forceWrap",
"(",
"$",
"cb",
")",
... | Readdir()
@param string $path Path
@param callable $cb = null Callback
@param integer $flags = null Flags
@param integer $pri = EIO_PRI_DEFAULT Priority
@return resource|true | [
"Readdir",
"()"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L405-L416 |
kakserpom/phpdaemon | PHPDaemon/FS/FileSystem.php | FileSystem.truncate | public static function truncate($path, $offset = 0, $cb = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!FileSystem::$supported) {
$fp = fopen($path, 'r+');
$r = $fp && ftruncate($fp, $offset);
if ($cb) {
$cb($path, $r);
}
return $r;
}
return eio_truncate($path, $offset, $pri, $cb, $path);
} | php | public static function truncate($path, $offset = 0, $cb = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!FileSystem::$supported) {
$fp = fopen($path, 'r+');
$r = $fp && ftruncate($fp, $offset);
if ($cb) {
$cb($path, $r);
}
return $r;
}
return eio_truncate($path, $offset, $pri, $cb, $path);
} | [
"public",
"static",
"function",
"truncate",
"(",
"$",
"path",
",",
"$",
"offset",
"=",
"0",
",",
"$",
"cb",
"=",
"null",
",",
"$",
"pri",
"=",
"EIO_PRI_DEFAULT",
")",
"{",
"$",
"cb",
"=",
"CallbackWrapper",
"::",
"forceWrap",
"(",
"$",
"cb",
")",
"... | Truncate file
@param string $path Path
@param integer $offset Offset
@param callable $cb Callback
@param integer $pri Priority
@return resource|boolean | [
"Truncate",
"file"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L426-L438 |
kakserpom/phpdaemon | PHPDaemon/FS/FileSystem.php | FileSystem.sendfile | public static function sendfile(
$outfd,
$path,
$cb,
$startCb = null,
$offset = 0,
$length = null,
$pri = EIO_PRI_DEFAULT
) {
$cb = CallbackWrapper::forceWrap($cb);
if (!self::$supported) {
$cb($path, false);
return false;
}
$noncache = true;
FileSystem::open(
$path,
'r!',
function ($file) use ($cb, $noncache, $startCb, $path, $pri, $outfd, $offset, $length) {
if (!$file) {
$cb($path, false);
return;
}
$file->sendfile(
$outfd,
function ($file, $success) use ($cb, $noncache) {
$cb($file->path, $success);
if ($noncache) {
$file->close();
}
},
$startCb,
$offset,
$length,
$pri
);
},
$pri
);
return true;
} | php | public static function sendfile(
$outfd,
$path,
$cb,
$startCb = null,
$offset = 0,
$length = null,
$pri = EIO_PRI_DEFAULT
) {
$cb = CallbackWrapper::forceWrap($cb);
if (!self::$supported) {
$cb($path, false);
return false;
}
$noncache = true;
FileSystem::open(
$path,
'r!',
function ($file) use ($cb, $noncache, $startCb, $path, $pri, $outfd, $offset, $length) {
if (!$file) {
$cb($path, false);
return;
}
$file->sendfile(
$outfd,
function ($file, $success) use ($cb, $noncache) {
$cb($file->path, $success);
if ($noncache) {
$file->close();
}
},
$startCb,
$offset,
$length,
$pri
);
},
$pri
);
return true;
} | [
"public",
"static",
"function",
"sendfile",
"(",
"$",
"outfd",
",",
"$",
"path",
",",
"$",
"cb",
",",
"$",
"startCb",
"=",
"null",
",",
"$",
"offset",
"=",
"0",
",",
"$",
"length",
"=",
"null",
",",
"$",
"pri",
"=",
"EIO_PRI_DEFAULT",
")",
"{",
"... | sendfile()
@param mixed $outfd File descriptor
@param string $path Path
@param callable $cb Callback
@param callable $startCb Start callback
@param integer $offset Offset
@param integer $length Length
@param integer $pri Priority
@return true Success | [
"sendfile",
"()"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L451-L495 |
kakserpom/phpdaemon | PHPDaemon/FS/FileSystem.php | FileSystem.chown | public static function chown($path, $uid, $gid = -1, $cb = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!FileSystem::$supported) {
$r = chown($path, $uid);
if ($gid !== -1) {
$r = $r && chgrp($path, $gid);
}
$cb($path, $r);
return $r;
}
return eio_chown($path, $uid, $gid, $pri, $cb, $path);
} | php | public static function chown($path, $uid, $gid = -1, $cb = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!FileSystem::$supported) {
$r = chown($path, $uid);
if ($gid !== -1) {
$r = $r && chgrp($path, $gid);
}
$cb($path, $r);
return $r;
}
return eio_chown($path, $uid, $gid, $pri, $cb, $path);
} | [
"public",
"static",
"function",
"chown",
"(",
"$",
"path",
",",
"$",
"uid",
",",
"$",
"gid",
"=",
"-",
"1",
",",
"$",
"cb",
"=",
"null",
",",
"$",
"pri",
"=",
"EIO_PRI_DEFAULT",
")",
"{",
"$",
"cb",
"=",
"CallbackWrapper",
"::",
"forceWrap",
"(",
... | Changes ownership of file/directory
@param string $path Path
@param integer $uid User ID
@param integer $gid Group ID
@param callable $cb = null Callback
@param integer $pri = EIO_PRI_DEFAULT Priority
@return resource|boolean | [
"Changes",
"ownership",
"of",
"file",
"/",
"directory"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L506-L519 |
kakserpom/phpdaemon | PHPDaemon/FS/FileSystem.php | FileSystem.readfile | public static function readfile($path, $cb, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!FileSystem::$supported) {
$cb($path, file_get_contents($path));
return true;
}
return FileSystem::open($path, 'r!', function ($file) use ($path, $cb, $pri) {
if (!$file) {
$cb($path, false);
return;
}
$file->readAll($cb, $pri);
}, null, $pri);
} | php | public static function readfile($path, $cb, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!FileSystem::$supported) {
$cb($path, file_get_contents($path));
return true;
}
return FileSystem::open($path, 'r!', function ($file) use ($path, $cb, $pri) {
if (!$file) {
$cb($path, false);
return;
}
$file->readAll($cb, $pri);
}, null, $pri);
} | [
"public",
"static",
"function",
"readfile",
"(",
"$",
"path",
",",
"$",
"cb",
",",
"$",
"pri",
"=",
"EIO_PRI_DEFAULT",
")",
"{",
"$",
"cb",
"=",
"CallbackWrapper",
"::",
"forceWrap",
"(",
"$",
"cb",
")",
";",
"if",
"(",
"!",
"FileSystem",
"::",
"$",
... | Reads whole file
@param string $path Path
@param callable $cb Callback (Path, Contents)
@param integer $pri Priority
@return resource|true | [
"Reads",
"whole",
"file"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L528-L542 |
kakserpom/phpdaemon | PHPDaemon/FS/FileSystem.php | FileSystem.readfileChunked | public static function readfileChunked($path, $cb, $chunkcb, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!FileSystem::$supported) {
$chunkcb($path, $r = readfile($path));
$cb($r !== false);
return;
}
FileSystem::open($path, 'r!', function ($file) use ($path, $cb, $chunkcb, $pri) {
if (!$file) {
$cb($path, false);
return;
}
$file->readAllChunked($cb, $chunkcb, $pri);
}, null, $pri);
} | php | public static function readfileChunked($path, $cb, $chunkcb, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!FileSystem::$supported) {
$chunkcb($path, $r = readfile($path));
$cb($r !== false);
return;
}
FileSystem::open($path, 'r!', function ($file) use ($path, $cb, $chunkcb, $pri) {
if (!$file) {
$cb($path, false);
return;
}
$file->readAllChunked($cb, $chunkcb, $pri);
}, null, $pri);
} | [
"public",
"static",
"function",
"readfileChunked",
"(",
"$",
"path",
",",
"$",
"cb",
",",
"$",
"chunkcb",
",",
"$",
"pri",
"=",
"EIO_PRI_DEFAULT",
")",
"{",
"$",
"cb",
"=",
"CallbackWrapper",
"::",
"forceWrap",
"(",
"$",
"cb",
")",
";",
"if",
"(",
"!... | Reads file chunk-by-chunk
@param string $path Path
@param callable $cb Callback (Path, Success)
@param callable $chunkcb Chunk callback (Path, Chunk)
@param integer $pri Priority
@return resource | [
"Reads",
"file",
"chunk",
"-",
"by",
"-",
"chunk"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L552-L567 |
kakserpom/phpdaemon | PHPDaemon/FS/FileSystem.php | FileSystem.genRndTempnam | public static function genRndTempnam($dir = null, $prefix = 'php')
{
if (!$dir) {
$dir = sys_get_temp_dir();
}
static $n = 0;
return $dir . '/' . $prefix . str_shuffle(
md5(
str_shuffle(
microtime(true) . chr(mt_rand(0, 0xFF))
. Daemon::$process->getPid() . chr(mt_rand(0, 0xFF))
. (++$n) . mt_rand(0, mt_getrandmax())
)
)
);
} | php | public static function genRndTempnam($dir = null, $prefix = 'php')
{
if (!$dir) {
$dir = sys_get_temp_dir();
}
static $n = 0;
return $dir . '/' . $prefix . str_shuffle(
md5(
str_shuffle(
microtime(true) . chr(mt_rand(0, 0xFF))
. Daemon::$process->getPid() . chr(mt_rand(0, 0xFF))
. (++$n) . mt_rand(0, mt_getrandmax())
)
)
);
} | [
"public",
"static",
"function",
"genRndTempnam",
"(",
"$",
"dir",
"=",
"null",
",",
"$",
"prefix",
"=",
"'php'",
")",
"{",
"if",
"(",
"!",
"$",
"dir",
")",
"{",
"$",
"dir",
"=",
"sys_get_temp_dir",
"(",
")",
";",
"}",
"static",
"$",
"n",
"=",
"0"... | Returns random temporary file name
@param string $dir Directory
@param string $prefix Prefix
@return string Path | [
"Returns",
"random",
"temporary",
"file",
"name"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/FS/FileSystem.php#L575-L592 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.