本文整理汇总了PHP中Workerman\Worker::stopAll方法的典型用法代码示例。如果您正苦于以下问题:PHP Worker::stopAll方法的具体用法?PHP Worker::stopAll怎么用?PHP Worker::stopAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Workerman\Worker
的用法示例。
在下文中一共展示了Worker::stopAll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onWorkerStart
/**
* 当Gateway启动的时候触发的回调函数
* @return void
*/
public function onWorkerStart()
{
// 分配一个内部通讯端口
$this->lanPort = function_exists('posix_getppid') ? $this->startPort - posix_getppid() + posix_getpid() : $this->startPort;
if ($this->lanPort < 0 || $this->lanPort >= 65535) {
$this->lanPort = rand($this->startPort, 65535);
}
// 如果有设置心跳,则定时执行
if ($this->pingInterval > 0) {
$timer_interval = $this->pingNotResponseLimit > 0 ? $this->pingInterval / 2 : $this->pingInterval;
Timer::add($timer_interval, array($this, 'ping'));
}
if (!class_exists('\\Protocols\\GatewayProtocol')) {
class_alias('\\GatewayWorker\\Protocols\\GatewayProtocol', 'Protocols\\GatewayProtocol');
}
// 初始化gateway内部的监听,用于监听worker的连接已经连接上发来的数据
$this->_innerTcpWorker = new Worker("GatewayProtocol://{$this->lanIp}:{$this->lanPort}");
$this->_innerTcpWorker->listen();
$this->_innerUdpWorker = new Worker("GatewayProtocol://{$this->lanIp}:{$this->lanPort}");
$this->_innerUdpWorker->transport = 'udp';
$this->_innerUdpWorker->listen();
// 重新设置自动加载根目录
Autoloader::setRootPath($this->_appInitPath);
// 设置内部监听的相关回调
$this->_innerTcpWorker->onMessage = array($this, 'onWorkerMessage');
$this->_innerUdpWorker->onMessage = array($this, 'onWorkerMessage');
$this->_innerTcpWorker->onConnect = array($this, 'onWorkerConnect');
$this->_innerTcpWorker->onClose = array($this, 'onWorkerClose');
// 注册gateway的内部通讯地址,worker去连这个地址,以便gateway与worker之间建立起TCP长连接
if (!$this->registerAddress()) {
$this->log('registerAddress fail and exit');
Worker::stopAll();
}
if ($this->_onWorkerStart) {
call_user_func($this->_onWorkerStart, $this);
}
}
示例2: timeoutHandler
/**
* 业务超时回调
* @param int $signal
* @throws Exception
*/
public function timeoutHandler($signal)
{
switch ($signal) {
// 超时时钟
case SIGALRM:
// 超时异常
$e = new \Exception("process_timeout", 506);
$trace_str = $e->getTraceAsString();
// 去掉第一行timeoutHandler的调用栈
$trace_str = $e->getMessage() . ":\n" . substr($trace_str, strpos($trace_str, "\n") + 1) . "\n";
// 开发者没有设置超时处理函数,或者超时处理函数返回空则执行退出
if (!$this->processTimeoutHandler || !call_user_func($this->processTimeoutHandler, $trace_str, $e)) {
Worker::stopAll();
}
break;
}
}