2020-11-07 22:57:10 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Bootstrap;
|
|
|
|
|
2020-11-20 19:17:11 +08:00
|
|
|
use App\Support\Packet;
|
|
|
|
use App\Support\SocketIOParser;
|
2020-11-07 22:57:10 +08:00
|
|
|
use Hyperf\Framework\Bootstrap\ServerStartCallback;
|
2020-11-08 17:10:05 +08:00
|
|
|
use Swoole\Timer;
|
|
|
|
use Hyperf\Redis\Redis;
|
2020-11-07 22:57:10 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 自定义服务启动前回调事件
|
|
|
|
*
|
|
|
|
* Class ServerStart
|
|
|
|
* @package App\Bootstrap
|
|
|
|
*/
|
|
|
|
class ServerStart extends ServerStartCallback
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 回调事件
|
|
|
|
*/
|
|
|
|
public function beforeStart()
|
|
|
|
{
|
2020-11-08 17:10:05 +08:00
|
|
|
stdout_log()->info(sprintf('服务运行ID : %s', SERVER_RUN_ID));
|
2020-11-07 22:57:10 +08:00
|
|
|
|
2020-11-08 22:58:17 +08:00
|
|
|
$this->setTimeOut();
|
2020-11-08 17:10:05 +08:00
|
|
|
Timer::tick(15000, function () {
|
2020-11-08 22:58:17 +08:00
|
|
|
$this->setTimeOut();
|
2020-11-08 17:10:05 +08:00
|
|
|
});
|
|
|
|
}
|
2020-11-07 22:57:10 +08:00
|
|
|
|
2020-11-08 22:58:17 +08:00
|
|
|
public function setTimeOut()
|
2020-11-08 17:10:05 +08:00
|
|
|
{
|
|
|
|
container()->get(Redis::class)->hset('SERVER_RUN_ID', SERVER_RUN_ID, time());
|
2020-11-07 22:57:10 +08:00
|
|
|
}
|
2020-11-08 17:10:05 +08:00
|
|
|
}
|