• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP setTimeout函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中setTimeout函数的典型用法代码示例。如果您正苦于以下问题:PHP setTimeout函数的具体用法?PHP setTimeout怎么用?PHP setTimeout使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了setTimeout函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: onHandshake

 /**
  * @TODO DESCR
  * @return void
  */
 public function onHandshake()
 {
     $this->realRoute->client->sendFrameReal('o');
     if (($f = $this->sockjs->config->heartbeatinterval->value) > 0) {
         $this->heartbeatTimer = setTimeout(function ($timer) {
             $this->realRoute->client->sendFrameReal('h');
             $timer->timeout();
         }, $f * 1000000.0);
         $this->realRoute->onHandshake();
     }
 }
开发者ID:kakserpom,项目名称:phpdaemon,代码行数:15,代码来源:WebSocketRouteProxy.php


示例17: onReadUdp

 /**
  * Called when we got UDP packet
  * @param resource $stream Descriptor
  * @param integer $events  Events
  * @param mixed $arg       Attached variable
  * @return boolean Success.
  */
 public function onReadUdp($stream = null, $events = 0, $arg = null)
 {
     if (Daemon::$config->logevents->value) {
         Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' invoked.');
     }
     if (Daemon::$process->reload) {
         return false;
     }
     if ($this->pool->maxConcurrency) {
         if ($this->pool->count() >= $this->pool->maxConcurrency) {
             $this->overload = true;
             return false;
         }
     }
     $host = null;
     do {
         $l = @socket_recvfrom($this->fd, $buf, 10240, MSG_DONTWAIT, $host, $port);
         if (!$l) {
             break;
         }
         $key = '[' . $host . ']:' . $port;
         if (!isset($this->portsMap[$key])) {
             if ($this->pool->allowedClients !== null) {
                 if (!self::netMatch($conn->pool->allowedClients, $host)) {
                     Daemon::log('Connection is not allowed (' . $host . ')');
                 }
                 continue;
             }
             $class = $this->pool->connectionClass;
             $conn = new $class(null, $this->pool);
             $conn->setDgram(true);
             $conn->onWriteEv(null);
             $conn->setPeername($host, $port);
             $conn->setParentSocket($this);
             $this->portsMap[$key] = $conn;
             $conn->timeoutRef = setTimeout(function ($timer) use($conn) {
                 $conn->finish();
                 $timer->finish();
             }, $conn->timeout * 1000000.0);
             $conn->onUdpPacket($buf);
         } else {
             $conn = $this->portsMap[$key];
             $conn->onUdpPacket($buf);
             Timer::setTimeout($conn->timeoutRef);
         }
     } while (true);
     return $host !== null;
 }
开发者ID:zenus,项目名称:phpinx,代码行数:55,代码来源:UDP.php


示例18: setTimeout

<?php

$http = new Event\HTTP();
$srv = $http->createServer(function ($req, $res) {
    $res->write("Hello World immediately\n");
    setTimeout(function () use(&$res) {
        $res->end("Goodbye world 5 seconds later\n");
    }, 5000);
});
$srv->listen(8080, '127.0.0.1');
开发者ID:hinathan,项目名称:edges-php,代码行数:10,代码来源:http-timer.php



注:本文中的setTimeout函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP setTitle函数代码示例发布时间:2022-05-15
下一篇:
PHP setThemeOption函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap