public function http()
    {
        $this->writeln('Starting swoole http server...');

        $server = new HttpServer(
            $this->swooleConfig['http']['host'] ?? self::DEFAULT_SWOOLE_HOST,
            $this->swooleConfig['http']['port'] ?? self::DEFAULT_SWOOLE_PORT
        );

        $server->on(
            'Request', function ($request, $response) {

                $swooleRequest = (new SwooleRequest())->setSwooleRequest($request);
                $swooleResponse = (new SwooleResponse())->setSwooleResponse($response);
                $sessionId = $swooleRequest->getCookie('swoole_session_id');
                if (!$sessionId) {
                    $sessionId = IdGenerator::component()->generate();
                    $swooleResponse->setCookie('swoole_session_id', $sessionId);
                }
                $swooleRequest->setSessionId($sessionId);
                $swooleResponse->setSessionId($sessionId);

                (new App($swooleRequest, $swooleResponse))->run();

            }
        );

        $server->start();
    }
public function http()
    {
        $this->writeln('Starting swoole http server...');

        $server = new HttpServer(
            $this->swooleConfig['http']['host'] ?? self::DEFAULT_SWOOLE_HOST,
            $this->swooleConfig['http']['port'] ?? self::DEFAULT_SWOOLE_PORT
        );

        $server->on(
            'Request', function ($request, $response) {

                $swooleRequest = (new SwooleRequest())->setSwooleRequest($request);
                $swooleResponse = (new SwooleResponse())->setSwooleResponse($response);
                $sessionId = $swooleRequest->getCookie('swoole_session_id');
                if (!$sessionId) {
                    $sessionId = IdGenerator::component()->generate();
                    $swooleResponse->setCookie('swoole_session_id', $sessionId);
                }
                $swooleRequest->setSessionId($sessionId);
                $swooleResponse->setSessionId($sessionId);

                (new App($swooleRequest, $swooleResponse))->run();

            }
        );

        $server->start();
    }
public function http ( ) { $ this -> writeln ( 'Starting swoole http server...' ) ; $ server = new HttpServer ( $ this -> swooleConfig [ 'http' ] [ 'host' ] ?? self :: DEFAULT_SWOOLE_HOST , $ this -> swooleConfig [ 'http' ] [ 'port' ] ?? self :: DEFAULT_SWOOLE_PORT ) ; $ server -> on ( 'Request' , function ( $ request , $ response ) { $ swooleRequest = ( new SwooleRequest ( ) ) -> setSwooleRequest ( $ request ) ; $ swooleResponse = ( new SwooleResponse ( ) ) -> setSwooleResponse ( $ response ) ; $ sessionId = $ swooleRequest -> getCookie ( 'swoole_session_id' ) ; if ( ! $ sessionId ) { $ sessionId = IdGenerator :: component ( ) -> generate ( ) ; $ swooleResponse -> setCookie ( 'swoole_session_id' , $ sessionId ) ; } $ swooleRequest -> setSessionId ( $ sessionId ) ; $ swooleResponse -> setSessionId ( $ sessionId ) ; ( new App ( $ swooleRequest , $ swooleResponse ) ) -> run ( ) ; } ) ; $ server -> start ( ) ; }
Swoole Http Server
Swoole Http Server