當前位置: 首頁>>代碼示例>>PHP>>正文


PHP setTimeout函數代碼示例

本文整理匯總了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);
     }
 }
開發者ID:rstuven,項目名稱:php-notrace,代碼行數:26,代碼來源:probe.php

示例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);
         }
     }));
 }
開發者ID:cobolbaby,項目名稱:phpdaemon,代碼行數:37,代碼來源:ExamplePubSub.php

示例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);
         });
     });
 }
開發者ID:kakserpom,項目名稱:phpdaemon,代碼行數:31,代碼來源:Multi.php

示例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);
 }
開發者ID:shamahan,項目名稱:phpdaemon,代碼行數:11,代碼來源:Connection.php

示例5: onReady

 public function onReady()
 {
     $appInstance = $this;
     setTimeout(function ($event) use($appInstance) {
         $appInstance->broadcastCall('hello', [\PHPDaemon\Core\Daemon::$process->getPid()]);
         $event->finish();
     }, 2000000.0);
 }
開發者ID:shamahan,項目名稱:phpdaemon,代碼行數:8,代碼來源:ExampleBroadcastCall.php

示例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);
     }
 }
開發者ID:cobolbaby,項目名稱:phpdaemon,代碼行數:12,代碼來源:MongoNode.php

示例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);
 }
開發者ID:richp10,項目名稱:phpdaemon,代碼行數:12,代碼來源:Connection.php

示例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);
     }
 }
開發者ID:kakserpom,項目名稱:phpdaemon,代碼行數:13,代碼來源:GameMonitor.php

示例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();
         });
     }
 }
開發者ID:shamahan,項目名稱:phpdaemon,代碼行數:60,代碼來源:Generic.php

示例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);
 }
開發者ID:interpals,項目名稱:hmsearch-server,代碼行數:25,代碼來源:File.php

示例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
         });
     });
 }
開發者ID:kakserpom,項目名稱:phpdaemon,代碼行數:30,代碼來源:Session.php

示例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);
 }
開發者ID:shamahan,項目名稱:phpdaemon,代碼行數:22,代碼來源:Connection.php

示例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);
開發者ID:jcsy521,項目名稱:KVStore-move-tools,代碼行數:31,代碼來源:import.php

示例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);
     }
 }
開發者ID:dreamsxin,項目名稱:phpdaemon-muchat,代碼行數:13,代碼來源:Chat.php

示例15: testTick

 function testTick()
 {
     $check = 0;
     setTimeout(function () use(&$check) {
         $check++;
     }, 1);
     nextTick(function () use(&$check) {
         $check++;
     });
     tick();
     $this->assertEquals(1, $check);
 }
開發者ID:siite,項目名稱:choose-sa-cloud,代碼行數:12,代碼來源:FunctionsTest.php


注:本文中的setTimeout函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。