From 1dee8f80de89372bec7533fc37e4ffbbfa2a76ea Mon Sep 17 00:00:00 2001 From: Qi <392223903@qq.com> Date: Tue, 11 Feb 2020 17:23:23 +0800 Subject: [PATCH 1/3] =?UTF-8?q?Event=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/command.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/example/command.php b/example/command.php index 123c7cd..aa74d90 100644 --- a/example/command.php +++ b/example/command.php @@ -4,6 +4,15 @@ require '../vendor/autoload.php'; use \EasyTask\Task; +class Mail +{ + public function send() + { + echo '1024' . PHP_EOL; + echo date('Y-m-d H:i:s').PHP_EOL; + } +} + //获取命令行输入参数 $cliArgv = $_SERVER['argv']; $command = empty($cliArgv['1']) ? '' : $cliArgv['1']; //获取输入的是start,status,stop中的哪一个 @@ -14,9 +23,7 @@ $task = new Task(); $task->setDaemon(false) ->setCloseInOut(false) ->setWriteLog(false, true) - ->addFunc(function () { - echo '1122'.PHP_EOL; - }, 'request', 10, 1); + ->addClass('Mail', 'send', 'req', 0.1, 1); //根据命令执行 if ($command == 'start') -- Gitee From eeb8152a8ef2bd799062e8e6aa275f60147cb682 Mon Sep 17 00:00:00 2001 From: Qi <392223903@qq.com> Date: Tue, 11 Feb 2020 17:34:10 +0800 Subject: [PATCH 2/3] =?UTF-8?q?Event=E4=BA=8B=E4=BB=B6=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/command.php | 2 +- src/Helper.php | 2 +- src/Process/Linux.php | 18 +++--------------- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/example/command.php b/example/command.php index aa74d90..e36ad99 100644 --- a/example/command.php +++ b/example/command.php @@ -23,7 +23,7 @@ $task = new Task(); $task->setDaemon(false) ->setCloseInOut(false) ->setWriteLog(false, true) - ->addClass('Mail', 'send', 'req', 0.1, 1); + ->addClass('Mail', 'send', 'req', 1, 1); //根据命令执行 if ($command == 'start') diff --git a/src/Helper.php b/src/Helper.php index 739242c..b7f5323 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -41,7 +41,7 @@ class Helper */ public static function canEvent() { - return (extension_loaded('event')); + return (!extension_loaded('event')); } /** diff --git a/src/Process/Linux.php b/src/Process/Linux.php index 4842a23..c9d4c6c 100644 --- a/src/Process/Linux.php +++ b/src/Process/Linux.php @@ -20,12 +20,6 @@ class Linux */ private $task; - /** - * 进程休息时间 - * @var int - */ - private $sleepTime; - /** * 进程启动时间 * @var int @@ -53,17 +47,11 @@ class Linux { $this->task = $task; $this->startTime = time(); - if (!$task->canAsync) - { - $this->sleepTime = 1; - } - else + $this->commander = new Command(); + if (!$task->canEvent && $task->canAsync) { - $this->sleepTime = 100; pcntl_async_signals(true); } - - $this->commander = new Command(); } /** @@ -289,7 +277,7 @@ class Linux while (true) { //CPU休息 - sleep($this->sleepTime); + sleep(1); //同步模式(调用信号处理) if (!$this->task->canAsync) pcntl_signal_dispatch(); -- Gitee From 97fca8349de0eb42e8af0e0479eb62807b3f4399 Mon Sep 17 00:00:00 2001 From: Qi <392223903@qq.com> Date: Tue, 11 Feb 2020 17:35:26 +0800 Subject: [PATCH 3/3] =?UTF-8?q?Event=E4=BA=8B=E4=BB=B6=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Helper.php b/src/Helper.php index b7f5323..739242c 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -41,7 +41,7 @@ class Helper */ public static function canEvent() { - return (!extension_loaded('event')); + return (extension_loaded('event')); } /** -- Gitee