Files
kiri-core/HttpServer/Events/OnShutdown.php
T

55 lines
1.1 KiB
PHP
Raw Normal View History

2020-09-02 11:38:47 +08:00
<?php
namespace HttpServer\Events;
use Exception;
2020-09-04 01:05:33 +08:00
use HttpServer\Abstracts\Callback;
2020-09-02 11:38:47 +08:00
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
2020-09-04 01:05:33 +08:00
use Snowflake\Abstracts\Config;
2020-09-02 11:38:47 +08:00
use Snowflake\Core\JSON;
use Snowflake\Error\Logger;
use Snowflake\Event;
2020-09-02 17:33:48 +08:00
use Snowflake\Exception\ComponentException;
2020-09-02 11:38:47 +08:00
use Snowflake\Exception\ConfigException;
use Snowflake\Snowflake;
2020-09-07 15:54:53 +08:00
use Swoole\Coroutine;
2020-09-02 11:38:47 +08:00
use Swoole\Server;
use Closure;
/**
* Class OnShutdown
* @package HttpServer\Events
*/
class OnShutdown extends Callback
{
/**
* @param Server $server
2020-09-02 19:09:32 +08:00
* @throws ComponentException
2020-09-02 17:33:48 +08:00
* @throws Exception
2020-09-02 11:38:47 +08:00
*/
public function onHandler(Server $server)
{
2020-10-21 15:50:43 +08:00
$this->debug('server shutdown~');
2020-10-21 15:55:56 +08:00
$workers = glob(storage(null, 'worker') . '/*');
foreach ($workers as $worker) {
$content = file_get_contents($worker);
posix_kill($content, 9);
}
$content = '[error]: ' . date('Y-m-d H:i:s') . PHP_EOL;
$content .= print_r(swoole_last_error(), true);
Snowflake::writeFile(storage('shutdown.log'), $content, FILE_APPEND);
2020-09-09 18:50:46 +08:00
$this->system_mail('server shutdown~');
2020-09-03 11:39:20 +08:00
$event = Snowflake::app()->getEvent();
2020-09-02 17:33:48 +08:00
$event->trigger(Event::SERVER_SHUTDOWN);
2020-09-02 11:38:47 +08:00
}
}