Open webrobot1 opened 6 months ago
Hi webrobot1
Workerman support timer in the master process, and the code is similar to this
$worker = new Worker('http://0.0.0.0:1234');
// The timer will only run in master process
Timer::add(1, function() {
echo "hello";
});
Worker::runAll();
take care The timer of the main process only supports second level. It is not recommended to initialize database or Redis resource class connections in the main process, as these connection resources may be inherited by child processes, leading to unforeseen problems
At some situation i need add Timer at master process, but it look like imposible because master have
monitorWorkersForLinux
method withpcntl_wait
function what will be block master process until worker will not shutdown or master will get somу signal. While it was blocking no one Event library can't run timer...but...Some Event library has own
pcntl_wait
analogs , likeSwoole\Coroutine\System::wait
in Swoole (https://wiki.swoole.com/#/coroutine/system?id=wait). It will do same things aspcntl_wait
but additional Timer can be work in master processIs it possible change
monitorWorkersForLinux
$pid = \pcntl_wait($status, \WUNTRACED);
->static::$globalEvent->wait()
? And EventInterface need be abstract with share methodwait
by default havepcntl_wait
(except Swoole) and return array['pid'=>$pid, 'signal'=>$status]
(like aSwoole\Coroutine\System::wait
return array's format) or stay like Interface but need have abstract methodwait():array
(but in this realisation each Event needwait
method withpcntl_wait
except Swoole)Because not it impossible change
monitorWorkersForLinux
by extends class , because it have private property , additionaly this method have a lot of code, but only need change one line of code@walkor