38 lines
773 B
PHP
38 lines
773 B
PHP
<?php
|
|
|
|
namespace App\Bootstrap;
|
|
|
|
use App\Support\Packet;
|
|
use App\Support\SocketIOParser;
|
|
use Hyperf\Framework\Bootstrap\ServerStartCallback;
|
|
use Swoole\Timer;
|
|
use Hyperf\Redis\Redis;
|
|
|
|
/**
|
|
* 自定义服务启动前回调事件
|
|
*
|
|
* Class ServerStart
|
|
* @package App\Bootstrap
|
|
*/
|
|
class ServerStart extends ServerStartCallback
|
|
{
|
|
/**
|
|
* 回调事件
|
|
*/
|
|
public function beforeStart()
|
|
{
|
|
stdout_log()->info(sprintf('服务运行ID : %s', SERVER_RUN_ID));
|
|
|
|
// 维护服务运行状态
|
|
$this->setTimeOut();
|
|
Timer::tick(15000, function () {
|
|
$this->setTimeOut();
|
|
});
|
|
}
|
|
|
|
public function setTimeOut()
|
|
{
|
|
container()->get(Redis::class)->hset('SERVER_RUN_ID', SERVER_RUN_ID, time());
|
|
}
|
|
}
|