mezzio / mezzio-swoole

Swoole support for Mezzio

Home Page:https://docs.mezzio.dev/mezzio-swoole/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support swoole onWorkerExit

linuxd3v opened this issue · comments

Feature Request

Q A
New Feature yes
RFC not sure
BC Break no

Summary

At the momen mezzio/swoole supports some swoole events - however not all.
Specifically workerstop is supported, but not workerexit for example.

Per docs - workerstop is not triggering for task processes: https://github.com/deminy/swoole-by-examples/blob/master/examples/servers/server-events.php.

Event "onWorkerStop" happens in worker processes only. It won't happen in task worker processes.
Event "onWorkerExit" happens only when option \Swoole\Constant::OPTION_RELOAD_ASYNC is turned on.

this could be problematic if one needs to do some work on task worker exit - like shutdown connection pool for example.

Could probably be easily addressed in Mezzio\Swoole\SwooleRequestHandlerRunner:

    public function run(): void
    {
        if ($this->httpServer->mode === SWOOLE_PROCESS) {
            $this->httpServer->on('start', [$this, 'onStart']);
            $this->httpServer->on('shutdown', [$this, 'onShutdown']);
        }

        $this->httpServer->on('managerstart', [$this, 'onManagerStart']);
        $this->httpServer->on('managerstop', [$this, 'onManagerStop']);
        $this->httpServer->on('workerstart', [$this, 'onWorkerStart']);
        $this->httpServer->on('workerstop', [$this, 'onWorkerStop']);

       //lets add this!
        $this->httpServer->on('workerexit', [$this, 'onWorkerExit']);

        $this->httpServer->on('workererror', [$this, 'onWorkerError']);
        $this->httpServer->on('request', [$this, 'onRequest']);
        $this->httpServer->on('beforereload', [$this, 'onBeforeReload']);
        $this->httpServer->on('afterreload', [$this, 'onAfterReload']);
        $this->httpServer->on('task', [$this, 'onTask']);
        $this->httpServer->on('finish', [$this, 'onTaskFinish']);

        $this->httpServer->start();
    }