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

64 lines
1.1 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;
2021-01-04 16:33:46 +08:00
use Snowflake\Event;
2020-09-07 17:31:01 +08:00
use Snowflake\Snowflake;
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-23 03:12:00 +08:00
2021-04-28 12:03:30 +08:00
/**
* 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);
}
/**
* @param Process $process
* @throws Exception
*/
public function _load(Process $process)
{
2021-07-06 16:30:17 +08:00
Snowflake::setProcessId($this->pid);
2021-04-28 12:03:30 +08:00
putenv('environmental=' . Snowflake::PROCESS);
fire(Event::SERVER_WORKER_START);
2021-07-08 18:02:21 +08:00
if (Snowflake::getPlatform()->isLinux()) {
name($this->pid, $this->getProcessName());
2021-04-28 12:03:30 +08:00
}
if (method_exists($this, 'before')) {
$this->before($process);
}
$this->onHandler($process);
}
/**
* @return string
*/
#[Pure] private function getPrefix(): string
{
return static::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
}