diff --git a/example/command.php b/example/command.php index 123c7cdf73a2796c829cd794b6060878562f9c02..e36ad99f5131df1bf9eed87e629cb85e6d05ea00 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', 1, 1); //根据命令执行 if ($command == 'start') diff --git a/src/Process/Linux.php b/src/Process/Linux.php index 4842a2341a749a9a3ba101568a6a218ad3386290..c9d4c6cd1761005d2fb1d7fcf63a4432fe813aa0 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();