Files
zhamao-framework/src/ZM/Event/SwooleEvent/OnWorkerExit.php

34 lines
844 B
PHP
Raw Normal View History

<?php
/** @noinspection PhpUnusedParameterInspection */
declare(strict_types=1);
namespace ZM\Event\SwooleEvent;
2021-07-09 01:38:30 +08:00
use Swoole\Coroutine;
use Swoole\Server;
use Swoole\Timer;
use ZM\Annotation\Swoole\SwooleHandler;
use ZM\Console\Console;
use ZM\Event\SwooleEvent;
2021-07-09 01:38:30 +08:00
use ZM\Store\LightCacheInside;
/**
* Class OnWorkerExit
* @SwooleHandler("WorkerExit")
*/
class OnWorkerExit implements SwooleEvent
{
public function onCall(Server $server, $worker_id)
{
Timer::clearAll();
foreach ((LightCacheInside::get('wait_api', 'wait_api') ?? []) as $v) {
if (($v['worker_id'] ?? -1) == $worker_id && isset($v['coroutine'])) {
Coroutine::resume($v['coroutine']);
2021-07-09 01:38:30 +08:00
}
2021-07-04 15:45:30 +08:00
}
Console::info('正在结束 Worker #' . $worker_id . ',进程内可能有事务在运行...');
}
}