本文整理汇总了PHP中setTimeout函数的典型用法代码示例。如果您正苦于以下问题:PHP setTimeout函数的具体用法?PHP setTimeout怎么用?PHP setTimeout使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setTimeout函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: enableForConsumer
function enableForConsumer($consumerId, $interval, $probeKey)
{
$_this = $this;
$this->enabled = true;
if (!$this->instant) {
// register consumer
$newConsumerId = !isset($this->consumerTimers[$consumerId]);
if ($interval > 0 && $newConsumerId) {
$this->consumerTimers[$consumerId] = setInterval(function () use($_this, $consumerId) {
$_this->sample($consumerId);
}, $interval);
}
// enable with delayed disabling
if (!empty($this->disableDelay)) {
clearTimeout($this->disableDelay);
}
$this->disableDelay = setTimeout(function () use($_this) {
//echo "\ndisabled " . $_this->name;
$_this->enabled = false;
foreach ($_this->consumerTimers as $consumerId => $timer) {
clearInterval($timer);
}
$_this->consumerTimers = array();
}, PROBE_DISABLE_DELAY);
}
}
示例2: onReady
/**
* Called when the worker is ready to go.
* @return void
*/
public function onReady()
{
$appInstance = $this;
// a reference to this application instance for ExampleWebSocketRoute
\PHPDaemon\Servers\WebSocket\Pool::getInstance()->addRoute('ExamplePubSub', function ($client) use($appInstance) {
return new ExamplePubSubWebSocketRoute($client, $appInstance);
});
$this->sql = \PHPDaemon\Clients\MySQL\Pool::getInstance();
$this->pubsub = new \PHPDaemon\PubSub\PubSub();
$this->pubsub->addEvent('usersNum', \PHPDaemon\PubSub\PubSubEvent::init()->onActivation(function ($pubsub) use($appInstance) {
\PHPDaemon\Core\Daemon::log('onActivation');
if (isset($pubsub->event)) {
\PHPDaemon\Core\Timer::setTimeout($pubsub->event, 0);
return;
}
$pubsub->event = setTimeout(function ($timer) use($pubsub, $appInstance) {
$appInstance->sql->getConnection(function ($sql) use($pubsub) {
if (!$sql->connected) {
return;
}
$sql->query('SELECT COUNT(*) `num` FROM `dle_users`', function ($sql, $success) use($pubsub) {
$pubsub->pub(sizeof($sql->resultRows) ? $sql->resultRows[0]['num'] : 'null');
});
});
$timer->timeout(5000000.0);
// 5 seconds
}, 0);
})->onDeactivation(function ($pubsub) {
if (isset($pubsub->event)) {
\PHPDaemon\Core\Timer::cancelTimeout($pubsub->event);
}
}));
}
示例3: onReady
/**
* Called when the worker is ready to go
* @return void
*/
public function onReady()
{
$this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance();
$this->redis->multi(function ($multi) {
// "OK"
D('start multi: ' . $multi->result);
$multi->set('test1', 'value1', function ($redis) use($multi) {
// "QUEUED"
D('in multi 1: ' . $redis->result);
$this->redis->set('test1', 'value1-new', function ($redis) {
// "OK", not "QUEUED"
D('out multi 1: ' . $redis->result);
});
setTimeout(function ($timer) use($multi) {
// "QUEUED"
$multi->set('test2', 'value2', function ($redis) use($multi) {
D('in multi 2: ' . $redis->result);
$multi->exec(function ($redis) {
D('exec');
D($redis->result);
});
});
$timer->free();
}, 200000.0);
});
});
}
示例4: onReady
/**
* Called when the connection is handshaked (at low-level), and peer is ready to recv. data
* @return void
*/
public function onReady()
{
$conn = $this;
$this->keepaliveTimer = setTimeout(function ($timer) use($conn) {
$conn->ping();
}, 10000000.0);
}
示例5: onReady
public function onReady()
{
$appInstance = $this;
setTimeout(function ($event) use($appInstance) {
$appInstance->broadcastCall('hello', [\PHPDaemon\Core\Daemon::$process->getPid()]);
$event->finish();
}, 2000000.0);
}
示例6: onReady
/**
* Called when the worker is ready to go.
* @return void
*/
public function onReady()
{
if ($this->config->enable->value) {
$this->timer = setTimeout(function ($timer) {
$this->touchCursor();
}, 300000.0);
}
}
示例7: onReady
/**
* Called when the connection is handshaked (at low-level), and peer is ready to recv. data
* @return void
*/
public function onReady()
{
$this->createXMLStream();
$this->startXMLStream();
$this->keepaliveTimer = setTimeout(function ($timer) {
$this->ping();
}, 1000000.0 * 30);
}
示例8: onReady
/**
* Called when the worker is ready to go.
* @return void
*/
public function onReady()
{
if ($this->isEnabled()) {
$this->updateTimer = setTimeout(function ($timer) {
$this->updateAllServers();
$timer->timeout(2000000.0);
}, 1);
}
}
示例9: init
/**
* Constructor
* @return void
*/
public function init()
{
$this->sessId = $this->attrs->sessId;
$this->serverId = $this->attrs->serverId;
$this->path = $this->attrs->path;
// @TODO: revert timeout after request
$this->upstream->setTimeouts($this->appInstance->config->networktimeoutread->value, $this->appInstance->config->networktimeoutwrite->value);
$this->opts = $this->appInstance->getRouteOptions($this->attrs->path);
$this->CORS();
if ($this->isFinished()) {
return;
}
if ($this->opts['cookie_needed'] && !$this instanceof Info) {
if (isset($_COOKIE['JSESSIONID'])) {
$val = $_COOKIE['JSESSIONID'];
if (!is_string($val) || $val === '') {
$val = 'dummy';
}
} else {
$val = 'dummy';
}
$this->setcookie('JSESSIONID', $val, 0, '/');
}
$this->contentType($this->contentType);
if (!$this->cacheable) {
$this->noncache();
$this->header('X-Accel-Buffering: no');
}
if ($this->callbackParamEnabled) {
if (!isset($_GET['c']) || !is_string($_GET['c']) || preg_match('~[^_\\.a-zA-Z0-9]~', $_GET['c'])) {
$this->header('500 Internal Server Error');
$this->out('"callback" parameter required');
$this->finish();
return;
}
}
if (($f = $this->appInstance->config->heartbeatinterval->value) > 0) {
$this->heartbeatTimer = setTimeout(function ($timer) {
if (in_array('one-by-one', $this->pollMode)) {
$this->heartbeatOnFinish = true;
$this->stop();
return;
}
$this->sendFrame('h');
if ($this->gcEnabled) {
$this->gcCheck();
}
}, $f * 1000000.0);
}
$this->afterHeaders();
if ($this->poll) {
$this->acquire(function () {
$this->poll();
});
}
}
示例10: __construct
/**
* Manager constructor.
* @param $path
*/
public function __construct($path, $threadsNum)
{
$this->threadsNum = $threadsNum;
$this->path = $path;
$this->queue = new StackCallbacks();
$this->reloadCheckTimer = setTimeout(function ($ev) {
FileSystem::stat($this->path, function ($path, $stat) {
if (!$stat) {
$this->stop();
$this->free();
}
if ($this->reloadCheckLastModified >= $stat['mtime']) {
return;
}
$this->reloadCheckLastModified = $stat['mtime'];
$this->stop();
$this->start();
});
$ev->timeout(static::RELOAD_CHECK_INTERVAL);
}, 1);
}
示例11: __construct
/**
* __construct
* @param Application $appInstance [@todo description]
* @param string $id [@todo description]
* @param array $server [@todo description]
* @return void
*/
public function __construct($appInstance, $id, $server)
{
$this->onWrite = new StackCallbacks();
$this->id = $id;
$this->appInstance = $appInstance;
$this->server = $server;
if (isset($this->server['HTTP_COOKIE'])) {
Generic::parseStr(strtr($this->server['HTTP_COOKIE'], Generic::$hvaltr), $this->cookie);
}
if (isset($this->server['QUERY_STRING'])) {
Generic::parseStr($this->server['QUERY_STRING'], $this->get);
}
$this->addr = $server['REMOTE_ADDR'];
$this->finishTimer = setTimeout(function ($timer) {
$this->finish();
}, $this->timeout * 1000000.0);
$this->appInstance->subscribe('c2s:' . $this->id, [$this, 'c2s']);
$this->appInstance->subscribe('poll:' . $this->id, [$this, 'poll'], function ($redis) {
$this->appInstance->publish('state:' . $this->id, 'started', function ($redis) {
// @TODO: remove this callback
});
});
}
示例12: endRequest
/**
* End request
* @return void
*/
public function endRequest($req, $appStatus, $protoStatus)
{
if ($protoStatus === -1) {
$this->close();
} else {
if ($req->attrs->chunked) {
$this->write("0\r\n\r\n");
}
if (isset($req->keepalive) && $req->keepalive && $this->pool->config->keepalive->value) {
$this->keepaliveTimer = setTimeout(function ($timer) {
$this->finish();
}, $this->pool->config->keepalive->value);
} else {
$this->finish();
}
}
$this->freeRequest($req);
}
示例13: setTimeout
setTimeout($Redis, $arr['key'], $arr['expire']);
break;
case $Redis::REDIS_LIST:
echo "list\n";
foreach ($arr['val'] as $v) {
$Redis->rPush($arr['key'], $v);
}
setTimeout($Redis, $arr['key'], $arr['expire']);
break;
case $Redis::REDIS_SET:
echo "set\n";
foreach ($arr['val'] as $v) {
$Redis->sAdd($arr['key'], $v);
}
setTimeout($Redis, $arr['key'], $arr['expire']);
break;
case $Redis::REDIS_ZSET:
echo "zset\n";
foreach ($arr['val'] as $v => $score) {
$Redis->zAdd($arr['key'], $score, $v);
}
setTimeout($Redis, $arr['key'], $arr['expire']);
break;
default:
//echo "unknown\n";
continue;
break;
}
}
$Redis->close();
fclose($file);
示例14: onReady
public function onReady()
{
if ($this->isEnabled()) {
\PHPDaemon\Servers\WebSocket\Pool::getInstance()->addRoute('Chat', array($this, 'onHandshake'));
$app = $this;
$this->timer = setTimeout(function ($timer) use($app) {
foreach ($app->tags as $tag) {
$tag->touch();
}
$timer->timeout();
}, 300000.0);
}
}
示例15: testTick
function testTick()
{
$check = 0;
setTimeout(function () use(&$check) {
$check++;
}, 1);
nextTick(function () use(&$check) {
$check++;
});
tick();
$this->assertEquals(1, $check);
}