Swoole Coroutine FastCGI Proxy

Version: Swoole: 4.5.0+

Swoole Coroutine FastCGI Proxy can be used to communicate with FastCGI servers like PHP-FPM.

Methods

  • Swoole\Coroutine\FastCGI\Proxy::__construct
  • Swoole\Coroutine\FastCGI\Proxy->withTimeout
  • Swoole\Coroutine\FastCGI\Proxy->withHttps
  • Swoole\Coroutine\FastCGI\Proxy->withIndex
  • Swoole\Coroutine\FastCGI\Proxy->getParam
  • Swoole\Coroutine\FastCGI\Proxy->withParam
  • Swoole\Coroutine\FastCGI\Proxy->withoutParam
  • Swoole\Coroutine\FastCGI\Proxy->getParams
  • Swoole\Coroutine\FastCGI\Proxy->withParams
  • Swoole\Coroutine\FastCGI\Proxy->withAddedParams
  • Swoole\Coroutine\FastCGI\Proxy->withStaticFileFilter
  • Swoole\Coroutine\FastCGI\Proxy->translateRequest
  • Swoole\Coroutine\FastCGI\Proxy->translateResponse
  • Swoole\Coroutine\FastCGI\Proxy->pass
  • Swoole\Coroutine\FastCGI\Proxy->staticFileFiltrate

    HTTP to FastCGI proxy

    <?php
    use Swoole\Constant;
    use Swoole\Coroutine\FastCGI\Proxy;
    use Swoole\Http\Request;
    use Swoole\Http\Response;
    use Swoole\Http\Server;
    
    $documentRoot = '/var/www/html';
    $server = new Server('0.0.0.0', 80, SWOOLE_BASE);
    $server->set([
        Constant::OPTION_WORKER_NUM => swoole_cpu_num() * 2,
        Constant::OPTION_HTTP_PARSE_COOKIE => false,
        Constant::OPTION_HTTP_PARSE_POST => false,
        Constant::OPTION_DOCUMENT_ROOT => $documentRoot,
        Constant::OPTION_ENABLE_STATIC_HANDLER => true,
        Constant::OPTION_STATIC_HANDLER_LOCATIONS => ['/wp-admin', '/wp-content', '/wp-includes'],
    ]);
    $proxy = new Proxy('127.0.0.1:9000', $documentRoot);
    $server->on('request', function (Request $request, Response $response) use ($proxy) {
        $proxy->pass($request, $response);
    });
    $server->start();