From 69a1f7cad5907e404e4cb93f4ac68c90c03d7f11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 7 Sep 2020 17:31:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HttpServer/Server.php | 12 ++---------- System/Process/Process.php | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/HttpServer/Server.php b/HttpServer/Server.php index ac750640..549fff1e 100644 --- a/HttpServer/Server.php +++ b/HttpServer/Server.php @@ -184,18 +184,10 @@ class Server extends Application $application = Snowflake::app(); foreach ($processes as $name => $process) { - $class = Snowflake::createObject($process); - if (!method_exists($class, 'onHandler')) { - continue; - } - $this->debug(sprintf('Process %s', $process)); - $system = new Process([$class, 'onHandler'], ...[false, 1, true]); - if (Snowflake::isLinux()) { - $system->name($name); - } + $system = new $process(Snowflake::app(), $name); $this->baseServer->addProcess($system); - $application->set(get_class($class), $system); + $application->set(get_class($process), $system); } } diff --git a/System/Process/Process.php b/System/Process/Process.php index 4f7b30a4..b0102596 100644 --- a/System/Process/Process.php +++ b/System/Process/Process.php @@ -7,6 +7,7 @@ namespace Snowflake\Process; use Snowflake\Abstracts\Component; use Snowflake\Application; use Snowflake\Exception\ComponentException; +use Snowflake\Snowflake; use Swoole\Coroutine\Socket; use Swoole\Process\Pool; @@ -14,7 +15,28 @@ use Swoole\Process\Pool; * Class Process * @package Snowflake\Snowflake\Service */ -abstract class Process extends Component +abstract class Process extends \Swoole\Process { + /** @var Application $application */ + protected $application; + + + /** + * Process constructor. + * @param $application + * @param $name + * @throws \Exception + */ + public function __construct($application, $name) + { + parent::__construct([$this, 'onHandler'], false, 1, true); + $this->application = $application; + if (Snowflake::isLinux()) { + $this->name($name); + } + Snowflake::setWorkerId($this->pid); + } + + }