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

PHP swoole_timer_tick函数代码示例

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

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



在下文中一共展示了swoole_timer_tick函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
         }
     });
 }
开发者ID:jinchunguang,项目名称:swoole-doc,代码行数:12,代码来源:msg_queue.php


示例2: newAfterTimer

 static function newAfterTimer()
 {
     $id = swoole_timer_tick(rand(1000, 10000), 'timer');
     G::$afterTimers[$id] = true;
     self::$index++;
     self::log(__METHOD__ . ": #{$id}");
 }
开发者ID:swoole,项目名称:tests,代码行数:7,代码来源:timer.php


示例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) {
             }
         });
     }
 }
开发者ID:iwillhappy1314,项目名称:laravel-admin,代码行数:29,代码来源:chat_server.php


示例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");
     }
 }
开发者ID:jinchunguang,项目名称:swoole-doc,代码行数:8,代码来源:Timer.php


示例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);
     });
 }
开发者ID:shijl,项目名称:swoole,代码行数:12,代码来源:test.php


示例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);
     });
 }
开发者ID:mawenpei,项目名称:swoole-crontab,代码行数:10,代码来源:Handler.php


示例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__);
     }
 }
开发者ID:JeeLiu,项目名称:tsf,代码行数:14,代码来源:Timer.php


示例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);
    });
}
开发者ID:luokaka,项目名称:dyserver,代码行数:10,代码来源:Timer.php


示例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;
     });
 }
开发者ID:hackers365,项目名称:mitm_inline,代码行数:10,代码来源:server.php


示例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);
    });
}
开发者ID:rambochase,项目名称:swoole-src,代码行数:10,代码来源:server.php


示例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;
     }
 }
开发者ID:delphinBlue,项目名称:tsf,代码行数:15,代码来源:Timer.php


示例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);
         });
     }
 }
开发者ID:zhanglei,项目名称:swPromise,代码行数:11,代码来源:Timer.class.php


示例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();
             }
         }
     });
 }
开发者ID:vucms,项目名称:aha,代码行数:16,代码来源:Asyncworker.php


示例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();
     });
 }
开发者ID:eyehere,项目名称:aha,代码行数:14,代码来源:Redo.php


示例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);
         }
     });
 }
开发者ID:noikiy,项目名称:swoole-crontab,代码行数:14,代码来源:WorkerBase.class.php


示例16: __construct

 public function __construct()
 {
     $fp = stream_socket_client("tcp://127.0.0.1:9504", $code, $msg, 3);
     $http_request = "GET /index.html HTTP/1.1\r\n\r\n";
     fwrite($fp, $http_request);
     swoole_event_add($fp, function ($fp) {
         echo fread($fp, 8192);
         swoole_event_del($fp);
         fclose($fp);
     });
     swoole_timer_after(2000, function () {
         echo "2000ms timeout\n";
     });
     swoole_timer_tick(1000, function () {
         echo "1000ms interval\n";
     });
 }
开发者ID:nosun,项目名称:yaf,代码行数:17,代码来源:async.php


示例17: run

 public function run()
 {
     $this->current_num = $this->min_worker_num;
     for ($i = 0; $i < $this->current_num; $i++) {
         $process = new swoole_process(array($this, 'task_run'), false, 2);
         $pid = $process->start();
         $this->process_list[$pid] = $process;
         $this->process_use[$pid] = 0;
     }
     foreach ($this->process_list as $process) {
         swoole_event_add($process->pipe, function ($pipe) use($process) {
             $data = $process->read();
             var_dump($data);
             $this->process_use[$data] = 0;
         });
     }
     swoole_timer_tick(1000, function ($timer_id) {
         static $index = 0;
         $index = $index + 1;
         $flag = true;
         foreach ($this->process_use as $pid => $used) {
             if ($used == 0) {
                 $flag = false;
                 $this->process_use[$pid] = 1;
                 $this->process_list[$pid]->write($index . "Hello");
                 break;
             }
         }
         if ($flag && $this->current_num < $this->max_worker_num) {
             $process = new swoole_process(array($this, 'task_run'), false, 2);
             $pid = $process->start();
             $this->process_list[$pid] = $process;
             $this->process_use[$pid] = 1;
             $this->process_list[$pid]->write($index . "Hello");
             $this->current_num++;
         }
         var_dump($index);
         if ($index == 10) {
             foreach ($this->process_list as $process) {
                 $process->write("exit");
             }
             swoole_timer_clear($timer_id);
             $this->process->exit();
         }
     });
 }
开发者ID:jinchunguang,项目名称:swoole-doc,代码行数:46,代码来源:dynamic.php


示例18: memoryCheck

 protected function memoryCheck()
 {
     $process = new \swoole_process(function (\swoole_process $worker) {
         $worker->name("kerisy-rpcserver:memoryCheck");
         swoole_timer_tick(1000, function () {
             $serverName = "kerisy-rpcserver:master";
             Reload::load($serverName, 0.8);
             //                echo date('H:i:s')."\r\n";
             if (date('H:i') == '04:00') {
                 Reload::reload($serverName);
                 //休息70s
                 sleep(70);
             }
         });
     });
     $process->start();
 }
开发者ID:kerisy,项目名称:framework,代码行数:17,代码来源:Base.php


示例19: work

 public function work()
 {
     //是否有队列任务,有的话给worker进程发消息
     foreach ($this->workers as $pid => $worker) {
         \Log::info("队列worker{$pid}启动", [], 'tube.work');
         $data = $worker['tube'];
         if ($data) {
             $worker['process']->write($data);
         }
     }
     swoole_timer_tick(5000, function ($timerId) {
         if (!$this->pheanstalk->getConnection()->isServiceListening()) {
             //现在是一旦队列服务器崩溃的话,处理队列的主进程将退出。当然可以设置成等待,知道队列服务器恢复,只要将下列代码注释
             \Log::emergency("队列服务器崩溃了!TubeTick监听器退出", [], 'tube.tick');
             swoole_timer_clear($timerId);
             return;
         }
     });
 }
开发者ID:fucongcong,项目名称:framework,代码行数:19,代码来源:TubeTick.php


示例20: actionRun

 /**
  * 定时任务计时器入口文件
  * @param int    $interval  定时器时间间隔,单位秒
  * @param string $hostinfo  监听主机
  */
 public function actionRun($interval = 3, $hostinfo = '0.0.0.0:9550')
 {
     $interval = $interval * 1000;
     //单位是秒转换为基本单位毫秒
     $this->parseHostPort($hostinfo);
     echo 'timer set ', $interval, ' ms ', PHP_EOL;
     //主定时器,按interval间隔执行,单位毫秒
     swoole_timer_tick($interval, function () {
         $this->execTasks();
     });
     //如果存在额外注册定时器
     if ($this->reg_timer) {
         foreach ($this->reg_timer as $reg) {
             $tick = $reg['interval'] * 1000;
             if (method_exists($this, $reg['func'])) {
                 swoole_timer_tick($interval, [$this, $reg['func']]);
             }
         }
     }
 }
开发者ID:gtyd,项目名称:jira,代码行数:25,代码来源:TaskTimerController.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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