swoole / library

📚 Swoole Library
https://wiki.swoole.com/#/library
Apache License 2.0
237 stars 58 forks source link

FastCGI Proxy Error #29

Closed litaonet closed 4 years ago

litaonet commented 4 years ago

php

$documentRoot = base_path('public');
        if (!$documentRoot || !is_dir($documentRoot)) {
            throw new \InvalidArgumentException('Invalid document root');
        }
        $server = new Server('127.0.0.1', 8009, SWOOLE_BASE);
        $server->set([
            'worker_num' => swoole_cpu_num(),
            'http_parse_cookie' => false,
            'http_parse_post' => false,
            'document_root' => $documentRoot,
            'enable_static_handler' => true,
            'static_handler_locations' => ['/'],
        ]);
        $proxy = new Proxy('127.0.0.1:8000', $documentRoot);
        $server->on('request', function (Request $request, Response $response) use ($proxy) {
            $proxy->pass($request, $response);
        });
        $server->start();

error

Fatal error: Uncaught Swoole\Coroutine\FastCGI\Client\Exception: Connection reset by peer in /Users/code/base-api/library/src/core/Coroutine/FastCGI/Client.php:175
Stack trace:
#0 /Users/code/base-api/library/src/core/Coroutine/FastCGI/Client.php(100): Swoole\Coroutine\FastCGI\Client->ioException(54)
#1 /Users/code/base-api/library/src/core/Coroutine/FastCGI/Proxy.php(183): Swoole\Coroutine\FastCGI\Client->execute(Object(Swoole\FastCGI\HttpRequest), -1)
#2 /Users/code/base-api/app/Console/Commands/SwooleCommand.php(82): Swoole\Coroutine\FastCGI\Proxy->pass(NULL, Object(Swoole\Http\Response))
#3 {main}  thrown in /Users/code/base-api/library/src/core/Coroutine/FastCGI/Client.php on line 175In Client.php line 175:
Uncaught Swoole\Coroutine\FastCGI\Client\Exception: Connection reset by peer in /Users/code/base-api/library/src/core/Coroutine/FastCGI/Client.php:175
  Stack trace:
  #0 /Users/code/base-api/library/src/core/Coroutine/FastCGI/Client.php(100): Swoole\Coroutine\FastCGI\Client->ioException(54)
  #1 /Users/code/base-api/library/src/core/Coroutine/FastCGI/Proxy.php(183): Swoole\Coroutine\FastCGI\Client->execute(Object(Swoole\FastCGI\HttpRequest), -1)
  #2 /Users/code/base-api/app/Console/Commands/SwooleCommand.php(82): Swoole\Coroutine\FastCGI\Proxy->pass(NULL, Object(Swoole\Http\Response))
[2020-04-27 10:25:45 *62588.3]  ERROR   php_swoole_server_rshutdown (ERRNO 503): Fatal error: Uncaught Swoole\Coroutine\FastCGI\Client\Exception: Connection reset by peer in /Users/code/base-api/library/src/core/Coroutine/FastCGI/Client.php:175
sy-records commented 4 years ago

Is your 127.0.0.1:8000 the server side of php-fpm?

You can run grep -R "fastcgi_pass" in the nginx installation directory to get the corresponding ip:port or Unix socket.

deminy commented 4 years ago

Closed due to lack of feedback; also this seems more like a coding/configuration issue on PHP-FPM side.