当前位置: 首页>>代码示例>>PHP>>正文


PHP Timer::add方法代码示例

本文整理汇总了PHP中Workerman\Lib\Timer::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Timer::add方法的具体用法?PHP Timer::add怎么用?PHP Timer::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Workerman\Lib\Timer的用法示例。


在下文中一共展示了Timer::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onConnect

 public function onConnect($connection)
 {
     $connection->timeout_timerid = Timer::add(10, function () use($connection) {
         echo "timeout\n";
         $connection->close();
     }, null, false);
 }
开发者ID:andy0010,项目名称:GatewayWorker,代码行数:7,代码来源:Register.php

示例2: onRemoteClose

 public static function onRemoteClose()
 {
     echo "Waring channel connection closed and try to reconnect\n";
     self::$_remoteConnection = null;
     self::clearTimer();
     self::$_reconnectTimer = Timer::add(1, 'Channel\\Client::connect', array(self::$_remoteIp, self::$_remotePort));
 }
开发者ID:KovalMax,项目名称:homeproject,代码行数:7,代码来源:Client.php

示例3: scheduleRespawn

 public function scheduleRespawn($delay)
 {
     Timer::add($delay / 1000, function ($self) {
         if ($self->respawnCallback) {
             call_user_func($self->respawnCallback);
         }
     }, array($this), false);
 }
开发者ID:popzhangzhi,项目名称:BrowserQuest-PHP,代码行数:8,代码来源:Item.php

示例4: onWorkerStart

 /**
  * 当进程启动时一些初始化工作
  * @return void
  */
 protected function onWorkerStart()
 {
     Timer::add(1, array($this, 'checkGatewayConnections'));
     $this->checkGatewayConnections();
     \GatewayWorker\Lib\Gateway::setBusinessWorker($this);
     if ($this->_onWorkerStart) {
         call_user_func($this->_onWorkerStart, $this);
     }
 }
开发者ID:highestgoodlikewater,项目名称:workerman,代码行数:13,代码来源:BusinessWorker.php

示例5: doApi

 /**
  * 牌局玩家进度广播
  */
 public static function doApi($player, $data, &$re, $client_id)
 {
     $uid = $player->uid;
     $table = TableDao::getTable($player->tableId);
     if (!$table) {
         return 1;
     }
     if (!Timer::isExistTimer($table->blinkTimeOut)) {
         Gateway::bindUid($client_id, $uid);
         $table->blinkTimeOut = Timer::add(Constants::TABLE_INIT_CHECK_TIME, array($table, 'checkTime'));
         TableDao::addTable($table->tableId, $table);
     }
     if (!isset($table->playerStatus[$uid])) {
         $table->addUid($uid);
         GameDao::addInGamePlayer($uid);
         TableDao::addTable($table->tableId, $table);
     }
     if ($data['st'] == 1) {
         if (!in_array($uid, $table->readyUids)) {
             $table->readyUids[] = $uid;
             TableDao::addTable($table->tableId, $table);
         }
         if (count($table->readyUids) >= 3) {
             $table->recordTime = time();
             TableDao::addTable($table->tableId, $table);
             $re['uid'] = -1;
             Gateway::sendToUid($table->uids, json_encode($re));
         }
     }
     if ($data['addVal'] != -1) {
         $uids = $table->uids;
         $re['uid'] = $uid;
         foreach ($uids as $_uid) {
             if ($_uid == $uid) {
                 continue;
             }
             $re['addVal'] = $data['addVal'];
             $re['oldVal'] = $data['oldVal'];
             Gateway::sendToUid($_uid, json_encode($re));
         }
     }
     return 1;
 }
开发者ID:songsihan,项目名称:doudizhu,代码行数:46,代码来源:Progress.php

示例6: index

 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     require_once '/vendor/workerman/workerman/Autoloader.php';
     $http_worker = new Worker("websocket://0.0.0.0:2345");
     $http_worker->count = 4;
     $http_worker->onConnect = function ($connection) {
         $connection->send('id' . $connection->id);
     };
     $http_worker->onWorkerStart = function ($worker) {
         // 定时,每10秒一次
         \Workerman\Lib\Timer::add(2, function () use($worker) {
             // 遍历当前进程所有的客户端连接,发送当前服务器的时间
             foreach ($worker->connections as $connection) {
                 $connection->send(time());
             }
         });
     };
     $http_worker->onMessage = function ($connection, $data) {
         $connection->send('hello world' . $data);
     };
     worker::runAll();
 }
开发者ID:sunkejl,项目名称:workerManWebSocket,代码行数:27,代码来源:HomeController.php

示例7: initRoaming

 public function initRoaming($mob)
 {
     Timer::add(0.5, array($this, 'initRoamingCallback'));
 }
开发者ID:popzhangzhi,项目名称:BrowserQuest-PHP,代码行数:4,代码来源:MobArea.php

示例8: onGatewayClose

 /**
  * 当与Gateway的连接断开时触发
  * @param TcpConnection $connection
  * @return  void
  */
 public function onGatewayClose($connection)
 {
     $addr = $connection->remoteAddress;
     unset($this->gatewayConnections[$addr], $this->_connectingGatewayAddresses[$addr]);
     if (isset($this->_gatewayAddresses[$addr]) && !isset($this->_waitingConnectGatewayAddresses[$addr])) {
         Timer::add(1, array($this, 'tryToConnectGateway'), array($addr), false);
         $this->_waitingConnectGatewayAddresses[$addr] = $addr;
     }
 }
开发者ID:jiayuanpulto,项目名称:workerman-chat,代码行数:14,代码来源:BusinessWorker.php

示例9: onRegisterConnectionClose

 public function onRegisterConnectionClose()
 {
     Timer::add(1, array($this, 'registerAddress'), null, false);
 }
开发者ID:Lazy-hong,项目名称:QinIM-Server,代码行数:4,代码来源:Gateway.php

示例10: Worker

<?php

use Workerman\Worker;
use Workerman\Lib\Timer;
// composer autoload
include __DIR__ . '/../vendor/autoload.php';
$channel_server = new Channel\Server();
$worker = new Worker();
$worker->onWorkerStart = function () {
    Channel\Client::on('test event', function ($event_data) {
        echo 'test event triggered event_data :';
        var_dump($event_data);
    });
    Timer::add(5, function () {
        Channel\Client::publish('test event', 'some data');
    });
};
Worker::runAll();
开发者ID:KovalMax,项目名称:homeproject,代码行数:18,代码来源:server.php

示例11: check_files_change

use Workerman\Lib\Timer;
// 默认监控Workerman的Applications目录
$monitor_dir = realpath(__DIR__ . '/..');
// worker
$worker = new Worker();
// 名称,方便status时候辨别
$worker->name = 'FileMonitor';
// 该进程收到reload信号不执行reload
$worker->reloadable = false;
// 进程启动后安装定时器
$worker->onWorkerStart = function () {
    global $monitor_dir;
    // 只在debug模式下监控文件,守护进程模式不监控
    if (!Worker::$daemonize) {
        // 定时检查被监控目录文件1秒内是否有修改
        Timer::add(1, 'check_files_change', array($monitor_dir));
    }
};
// 检查文件1秒内是否有修改
function check_files_change($monitor_dir)
{
    // 递归遍历目录
    $dir_iterator = new RecursiveDirectoryIterator($monitor_dir);
    $iterator = new RecursiveIteratorIterator($dir_iterator);
    $time_now = time();
    foreach ($iterator as $file) {
        // 只监控php文件
        if (pathinfo($file, PATHINFO_EXTENSION) != 'php') {
            continue;
        }
        // 在最近1秒内有修改
开发者ID:songsihan,项目名称:doudizhu,代码行数:31,代码来源:start.php

示例12: function

 \Workerman\Lib\Timer::add(0.5, function () use($consumer) {
     if (extension_loaded('sysvmsg')) {
         // 循环取数据
         while (1) {
             $desiredmsgtype = 1;
             $msgtype = 0;
             $message = '';
             $maxsize = 65535;
             // 从队列中获取消息 @see http://php.net/manual/zh/function.msg-receive.php
             @msg_receive($consumer->queue, $desiredmsgtype, $msgtype, $maxsize, $message, true, MSG_IPC_NOWAIT);
             if (!$message) {
                 return;
             }
             // 假设消息数据为json,格式类似{"class":"class_name", "method":"method_name", "args":[]}
             $message = json_decode($message, true);
             // 格式如果是正确的,则尝试执行对应的类方法
             if (isset($message['class']) && isset($message['method']) && isset($message['args'])) {
                 // 要调用的类名,加上Consumer命名空间
                 $class_name = "\\Consumer\\" . $message['class'];
                 // 要调用的方法名
                 $method = $message['method'];
                 // 调用参数,是个数组
                 $args = (array) $message['args'];
                 // 类存在则尝试执行
                 if (class_exists($class_name)) {
                     $class = new $class_name();
                     $callback = array($class, $method);
                     if (is_callable($callback)) {
                         call_user_func_array($callback, $args);
                     } else {
                         echo "{$class_name}::{$method} not exist\n";
                     }
                 } else {
                     echo "{$class_name} not exist\n";
                 }
             } else {
                 echo "unknow message\n";
             }
         }
     }
 });
开发者ID:taohaoge,项目名称:workerman-queue,代码行数:41,代码来源:start.php

示例13: function

                    $sender_io->to($to)->emit('new_msg', @$_POST['content']);
                    // 否则向所有uid推送数据
                } else {
                    $sender_io->emit('new_msg', @$_POST['content']);
                }
                // http接口返回ok
                return $http_connection->send('ok');
        }
        return $http_connection->send('fail');
    };
    // 执行监听
    $inner_http_worker->listen();
    // 一个定时器,定时向所有uid推送当前uid在线数及在线页面数
    Timer::add(1, function () {
        global $uidConnectionMap, $sender_io, $last_online_count, $last_online_page_count;
        $online_count_now = count($uidConnectionMap);
        $online_page_count_now = array_sum($uidConnectionMap);
        // 只有在客户端在线数变化了才广播,减少不必要的客户端通讯
        if ($last_online_count != $online_count_now || $last_online_page_count != $online_page_count_now) {
            $sender_io->emit('update_online_count', "当前<b>{$online_count_now}</b>人在线,共打开<b>{$online_page_count_now}</b>个页面");
            $last_online_count = $online_count_now;
            $last_online_page_count = $online_page_count_now;
        }
    });
});
// 启动一个webserver,用于吐html css js,方便展示
// 这个webserver服务不是必须的,可以将这些html css js文件放到你的项目下用nginx或者apache跑
$web = new WebServer('http://0.0.0.0:2123');
$web->addRoot('localhost', __DIR__ . '/web');
// 运行所有的服务
Worker::runAll();
开发者ID:joy696163,项目名称:web-msg-sender,代码行数:31,代码来源:start.php

示例14: stopAll

 /**
  * Stop.
  * @return void
  */
 public static function stopAll()
 {
     self::$_status = self::STATUS_SHUTDOWN;
     // For master process.
     if (self::$_masterPid === posix_getpid()) {
         self::log("Workerman[" . basename(self::$_startFile) . "] Stopping ...");
         $worker_pid_array = self::getAllWorkerPids();
         // Send stop signal to all child processes.
         foreach ($worker_pid_array as $worker_pid) {
             posix_kill($worker_pid, SIGINT);
             Timer::add(self::KILL_WORKER_TIMER_TIME, 'posix_kill', array($worker_pid, SIGKILL), false);
         }
     } else {
         // Execute exit.
         foreach (self::$_workers as $worker) {
             $worker->stop();
         }
         exit(0);
     }
 }
开发者ID:TongJiankang,项目名称:Workerman,代码行数:24,代码来源:Worker.php

示例15: WebServer

            $connection->close();
        }
        // onWebSocketConnect 里面$_GET $_SERVER是可用的
        // var_dump($_GET, $_SERVER);
    };
}; 
*/
$webserver = new WebServer('http://0.0.0.0:80');
$webserver->addRoot('120.25.163.9', '/workerman/Applications/huicheng/Web');
$webserver->count = 1;
$webserver->onWorkerStart = function ($webserver) {
    //初始化多客服工号对应的昵称
    redisData::Set('HCS1@hc-information', '小汇');
    redisData::Set('HCS2@hc-information', '小承');
    redisData::Set('HCT1@hc-information', '小信');
    redisData::Set('HCT2@hc-information', '小息');
    //初始化定时间隔
    $time_interval = 7000;
    //初始化access_token
    transToWxServer::getaccess_token();
    transToWxServer::getjsapi_ticket();
    //定时获取access_token
    \Workerman\Lib\Timer::add($time_interval, function () {
        transToWxServer::getaccess_token();
        transToWxServer::getjsapi_ticket();
    });
};
// 如果不是在根目录启动,则运行runAll方法
if (!defined('GLOBAL_START')) {
    Worker::runAll();
}
开发者ID:xuanchristy,项目名称:HC-23,代码行数:31,代码来源:start_gateway.php


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