本文整理汇总了PHP中swoole_timer_tick函数的典型用法代码示例。如果您正苦于以下问题:PHP swoole_timer_tick函数的具体用法?PHP swoole_timer_tick怎么用?PHP swoole_timer_tick使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了swoole_timer_tick函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run($worker)
{
swoole_timer_tick(1000, function ($timer_id) {
static $index = 0;
$index = $index + 1;
$this->process->push("Hello");
var_dump($index);
if ($index == 10) {
swoole_timer_clear($timer_id);
}
});
}
示例2: newAfterTimer
static function newAfterTimer()
{
$id = swoole_timer_tick(rand(1000, 10000), 'timer');
G::$afterTimers[$id] = true;
self::$index++;
self::log(__METHOD__ . ": #{$id}");
}
示例3: online
private function online($who)
{
if (!isset($this->gens[$who])) {
$this->gens[$who] = $this->messageGenerator($who);
$this->sendUsers();
$this->broadcast($who, $who . " is online.");
}
if ($this->timer == null) {
$this->timer = swoole_timer_tick(3000, function () {
try {
$users = $this->getAllUsers();
foreach ($users as $user) {
if (!isset($this->getMessage[$user]) && !isset($this->getUpdateUsers[$user])) {
if (!isset($this->maybeOffline[$user])) {
$this->maybeOffline[$user] = true;
} else {
$this->offline($user);
}
} else {
if (isset($this->maybeOffline[$user])) {
unset($this->maybeOffline[$user]);
}
}
}
} catch (\Exception $e) {
}
});
}
}
示例4: onWorkerStart
public function onWorkerStart($serv, $worker_id)
{
if ($worker_id == 0) {
$this->test = new Test();
$this->test->index = 1;
swoole_timer_tick(1000, array($this, 'onTick'), "Hello");
}
}
示例5: register_timer
/**
* 注册定时任务
*/
protected static function register_timer()
{
swoole_timer_tick(60000, function ($interval) {
Test::load_config();
});
swoole_timer_tick(1000, function ($interval) {
Test::do_something($interval);
});
}
示例6: registerTimer
public static function registerTimer()
{
\swoole_timer_tick(60000, function ($id) {
self::loadConfig();
defined('PHPKIT_RUN_DEBUG') && syslog(LOG_INFO, 'reload config success');
});
\swoole_timer_tick(1000, function ($id) {
self::loadTask($id);
});
}
示例7: init
/**
* [init 启动定时器]
* @return [type] [description]
*/
public static function init()
{
if (!isset(self::$tickKey)) {
self::$tickKey = swoole_timer_tick(1000 * self::LOOPTIME, function () {
//循环数组,踢出超时情况
self::loop();
});
\SysLog::info(__METHOD__ . " init timer tick key == " . self::$tickKey, __CLASS__);
}
}
示例8: callback_function
function callback_function(swoole_process $worker)
{
global $config;
swoole_timer_tick($config['time'], function () {
$fp = stream_socket_client("tcp://127.0.0.1:9502", $code, $msg, 1);
$http_request = "GET / HTTP/1.1\r\n\r\n";
fwrite($fp, $http_request);
fclose($fp);
});
}
示例9: addTimer
public function addTimer()
{
swoole_timer_tick(10000, function ($timer_id, $params = null) {
if ($this->is_tasking) {
return;
}
$this->server->task();
$this->is_tasking = true;
});
}
示例10: my_process1
function my_process1($process)
{
global $argv;
var_dump($process);
swoole_set_process_name("php {$argv[0]}: my_process1");
swoole_timer_tick(2000, function ($id) {
global $serv;
$serv->sendMessage("hello", 1);
});
}
示例11: init
/**
* [init 启动定时器]
* @return [type] [description]
*/
public static function init()
{
if (!self::$isOnTimer) {
swoole_timer_tick(1000 * self::LOOPTIME, function ($timer_id) {
//循环数组,踢出超时情况
self::loop($timer_id);
self::$isOnTimer = false;
});
self::$isOnTimer = true;
}
}
示例12: init
public static function init()
{
if (self::$timer === null) {
for ($i = 0; $i < self::SLOT_SIZE; $i++) {
self::$eventSlots[$i] = array();
}
self::$timer = swoole_timer_tick(1000 * self::LOOP_TIME, function ($tid) {
self::loop($tid);
});
}
}
示例13: worker
/**
* @brief 子进程做事情
*/
public function worker()
{
$scheduler = $this->_objAha->getScheduler();
swoole_timer_tick(5000, function () use($scheduler) {
for ($i = 0; $i < 50; $i++) {
$coroutine = $this->dbTest();
if ($coroutine instanceof \Generator) {
$scheduler->newTask($coroutine);
$scheduler->run();
}
}
});
}
示例14: _initTimer
protected function _initTimer()
{
$redoConf = $this->_objAha->getConfig()->get('aha', 'redo');
$interval = $redoConf['interval'];
$triggerInterval = $redoConf['trigger_interval'];
//当前周期内 把上个周期内失败的进行重试
swoole_timer_tick($interval, function () {
$this->_redo();
});
//每个时钟周期检查是否有redo没有发完的消息包
swoole_timer_tick($triggerInterval, function () {
$this->_trigger();
});
}
示例15: tick
public function tick($worker)
{
$this->worker = $worker;
swoole_timer_tick(500, function () {
while (true) {
$this->checkExit();
$task = $this->getQueue();
if (empty($task)) {
break;
}
$this->Run($task);
}
});
}