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

Add BeforeServerStartEvent

linuxd3v opened this issue · comments

Feature Request

Q A
New Feature yes
RFC not sure
BC Break no

Summary

With swoole certain operations could only happen before the server start. (one example is - one can only add swoole processes to swoole server before server starts.)
For this reason I think it would be worthwhile to add BeforeServerStartEvent.

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']);
        $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']);

       //lets add this!
        $this->dispatcher->dispatch(new Event\BeforeServerStartEvent($server));

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