Files
kiri-core/System/Process/Process.php
T

67 lines
1.4 KiB
PHP
Raw Normal View History

2020-08-31 01:27:08 +08:00
<?php
2020-10-29 18:17:25 +08:00
declare(strict_types=1);
2020-08-31 01:27:08 +08:00
namespace Snowflake\Process;
2020-10-29 18:17:25 +08:00
use Exception;
2021-03-01 16:46:10 +08:00
use JetBrains\PhpStorm\Pure;
2020-08-31 01:27:08 +08:00
use Snowflake\Application;
2021-01-04 16:33:46 +08:00
use Snowflake\Event;
2021-03-01 16:46:10 +08:00
use Snowflake\Exception\ComponentException;
2020-09-07 17:31:01 +08:00
use Snowflake\Snowflake;
2021-04-11 19:02:42 +08:00
use Swoole\Coroutine\System;
2020-08-31 01:27:08 +08:00
/**
* Class Process
2020-08-31 12:38:32 +08:00
* @package Snowflake\Snowflake\Service
2020-08-31 01:27:08 +08:00
*/
2020-12-31 15:27:27 +08:00
abstract class Process extends \Swoole\Process implements SProcess
2020-08-31 01:27:08 +08:00
{
2021-04-11 19:08:36 +08:00
/** @var Application $application */
protected Application $application;
/**
* Process constructor.
* @param $application
* @param $name
* @param bool $enable_coroutine
* @throws Exception
*/
public function __construct($application, $name, $enable_coroutine = true)
{
parent::__construct([$this, '_load'], false, 1, $enable_coroutine);
$this->application = $application;
Snowflake::setProcessId($this->pid);
}
/**
* @param Process $process
* @throws Exception
*/
public function _load(Process $process)
{
putenv('environmental=' . Snowflake::PROCESS);
fire(Event::SERVER_WORKER_START);
if (Snowflake::getPlatform()->isLinux()) {
name($process->pid, $this->getPrefix());
}
$this->onHandler($process);
}
/**
* @return string
*/
#[Pure] private function getPrefix(): string
{
return get_called_class();
}
2021-02-27 15:27:22 +08:00
2020-09-07 17:31:01 +08:00
2020-08-31 01:27:08 +08:00
}