Files
kiri-http-server/Handler/OnServer.php
T

65 lines
1.4 KiB
PHP
Raw Normal View History

2022-01-09 03:49:02 +08:00
<?php
2022-01-10 11:39:55 +08:00
namespace Kiri\Server\Handler;
2022-01-09 03:49:02 +08:00
2023-04-16 02:41:03 +08:00
use Kiri\Di\Inject\Container;
2022-01-09 03:49:02 +08:00
use Kiri\Events\EventDispatch;
use Kiri\Exception\ConfigException;
2022-06-16 17:38:22 +08:00
use Kiri\Server\Events\OnAfterReload;
use Kiri\Server\Events\OnBeforeReload;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
2022-01-09 03:49:02 +08:00
use ReflectionException;
2022-01-10 11:39:55 +08:00
use Kiri\Server\Abstracts\Server;
use Kiri\Server\Events\OnBeforeShutdown;
use Kiri\Server\Events\OnShutdown;
use Kiri\Server\Events\OnStart;
2022-06-16 17:38:22 +08:00
use Swoole\Server as SServer;
2022-01-09 03:49:02 +08:00
/**
* Class OnServerDefault
* @package Server\Manager
*/
class OnServer extends Server
{
2022-06-16 17:38:22 +08:00
2022-01-09 03:49:02 +08:00
2022-06-16 17:38:22 +08:00
/**
* @param SServer $server
2022-01-09 03:49:02 +08:00
* @throws ReflectionException
2022-06-16 17:38:22 +08:00
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
2023-04-21 22:26:43 +08:00
public function onStart(SServer $server): void
2022-06-16 17:38:22 +08:00
{
\Kiri::setProcessName(sprintf('start[%d].server', $server->master_pid));
2023-04-21 22:26:43 +08:00
event(new OnStart($server));
2022-06-16 17:38:22 +08:00
}
/**
* @param SServer $server
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException
2022-01-09 03:49:02 +08:00
*/
2023-04-21 22:26:43 +08:00
public function onBeforeShutdown(SServer $server): void
2022-01-09 03:49:02 +08:00
{
2023-04-21 22:26:43 +08:00
event(new OnBeforeShutdown($server));
2022-06-16 17:38:22 +08:00
}
2022-01-09 03:49:02 +08:00
2022-06-16 17:38:22 +08:00
/**
* @param SServer $server
2023-04-21 22:26:43 +08:00
* @throws
2022-06-16 17:38:22 +08:00
*/
2023-04-19 15:21:09 +08:00
public function onShutdown(SServer $server): void
2022-06-16 17:38:22 +08:00
{
2023-04-19 15:21:09 +08:00
@unlink(storage('.swoole.pid'));
2023-04-21 22:26:43 +08:00
event(new OnShutdown($server));
2022-01-09 03:49:02 +08:00
}
}