Skip to content

Connection refused for stream request #5784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
huangdijia opened this issue May 27, 2025 · 3 comments
Closed

Connection refused for stream request #5784

huangdijia opened this issue May 27, 2025 · 3 comments
Labels

Comments

@huangdijia
Copy link

PHP&Swoole 版本

PHP 8.2.28 (cli) (built: Mar 11 2025 17:58:12) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.28, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.28, Copyright (c), by Zend Technologies

swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 6.0.2
Built => May 27 2025 09:11:27
coroutine => enabled with boost asm context
kqueue => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.1.1v  1 Aug 2023
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
curl-version => 8.13.0
zlib => 1.2.12
brotli => E16781312/D16781312
zstd => 1.5.7
mysqlnd => enabled

Directive => Local Value => Master Value
swoole.enable_library => On => On
swoole.enable_fiber_mock => Off => Off
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => Off => Off
swoole.unixsock_buffer_size => 262144 => 262144

代码

// test.php

<?php

require_once __DIR__ . '/vendor/autoload.php';

use Swoole\Coroutine;
use function Swoole\Coroutine\run;

run(function () {
    Coroutine::create(function(){
        $client = new \GuzzleHttp\Client();
        $response = $client->get('https://httpbin.org/stream/20', [
            'stream' => true,
        ]);

        $body = $response->getBody();
        while (!$body->eof()) {
            echo $body->read(1024);
        }
    });
});

运行

php test.php

错误

PHP Fatal error:  Uncaught GuzzleHttp\Exception\ConnectException: Connection refused for URI https://httpbin.org/stream/20 in /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php:341
Stack trace:
#0 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php(254): GuzzleHttp\Handler\StreamHandler->GuzzleHttp\Handler\{closure}()
#1 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php(335): GuzzleHttp\Handler\StreamHandler->createResource(Object(Closure))
#2 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php(70): GuzzleHttp\Handler\StreamHandler->createStream(Object(GuzzleHttp\Psr7\Request), Array)
#3 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php(48): GuzzleHttp\Handler\StreamHandler->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#4 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/PrepareBodyMiddleware.php(35): GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#5 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Middleware.php(31): GuzzleHttp\PrepareBodyMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#6 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php(71): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#7 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Middleware.php(66): GuzzleHttp\RedirectMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#8 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/HandlerStack.php(75): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#9 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Client.php(333): GuzzleHttp\HandlerStack->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#10 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Client.php(169): GuzzleHttp\Client->transfer(Object(GuzzleHttp\Psr7\Request), Array)
#11 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Client.php(189): GuzzleHttp\Client->requestAsync('GET', Object(GuzzleHttp\Psr7\Uri), Array)
#12 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/ClientTrait.php(44): GuzzleHttp\Client->request('GET', 'https://httpbin...', Array)
#13 /Users/hdj/github/huangdijia/odin-demo/test.php(11): GuzzleHttp\Client->get('https://httpbin...', Array)
#14 [internal function]: {closure}()
#15 {main}

Next GuzzleHttp\Exception\ConnectException: Connection refused for URI https://httpbin.org/stream/20 in /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php:84
Stack trace:
#0 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php(48): GuzzleHttp\Handler\StreamHandler->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#1 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/PrepareBodyMiddleware.php(35): GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#2 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Middleware.php(31): GuzzleHttp\PrepareBodyMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#3 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php(71): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#4 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Middleware.php(66): GuzzleHttp\RedirectMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#5 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/HandlerStack.php(75): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#6 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Client.php(333): GuzzleHttp\HandlerStack->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#7 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Client.php(169): GuzzleHttp\Client->transfer(Object(GuzzleHttp\Psr7\Request), Array)
#8 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Client.php(189): GuzzleHttp\Client->requestAsync('GET', Object(GuzzleHttp\Psr7\Uri), Array)
#9 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/ClientTrait.php(44): GuzzleHttp\Client->request('GET', 'https://httpbin...', Array)
#10 /Users/hdj/github/huangdijia/odin-demo/test.php(11): GuzzleHttp\Client->get('https://httpbin...', Array)
#11 [internal function]: {closure}()
#12 {main}
  thrown in /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php on line 84

Fatal error: Uncaught GuzzleHttp\Exception\ConnectException: Connection refused for URI https://httpbin.org/stream/20 in /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php:341
Stack trace:
#0 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php(254): GuzzleHttp\Handler\StreamHandler->GuzzleHttp\Handler\{closure}()
#1 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php(335): GuzzleHttp\Handler\StreamHandler->createResource(Object(Closure))
#2 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php(70): GuzzleHttp\Handler\StreamHandler->createStream(Object(GuzzleHttp\Psr7\Request), Array)
#3 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php(48): GuzzleHttp\Handler\StreamHandler->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#4 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/PrepareBodyMiddleware.php(35): GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#5 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Middleware.php(31): GuzzleHttp\PrepareBodyMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#6 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php(71): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#7 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Middleware.php(66): GuzzleHttp\RedirectMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#8 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/HandlerStack.php(75): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#9 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Client.php(333): GuzzleHttp\HandlerStack->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#10 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Client.php(169): GuzzleHttp\Client->transfer(Object(GuzzleHttp\Psr7\Request), Array)
#11 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Client.php(189): GuzzleHttp\Client->requestAsync('GET', Object(GuzzleHttp\Psr7\Uri), Array)
#12 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/ClientTrait.php(44): GuzzleHttp\Client->request('GET', 'https://httpbin...', Array)
#13 /Users/hdj/github/huangdijia/odin-demo/test.php(11): GuzzleHttp\Client->get('https://httpbin...', Array)
#14 [internal function]: {closure}()
#15 {main}

Next GuzzleHttp\Exception\ConnectException: Connection refused for URI https://httpbin.org/stream/20 in /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php:84
Stack trace:
#0 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php(48): GuzzleHttp\Handler\StreamHandler->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#1 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/PrepareBodyMiddleware.php(35): GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#2 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Middleware.php(31): GuzzleHttp\PrepareBodyMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#3 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php(71): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#4 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Middleware.php(66): GuzzleHttp\RedirectMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#5 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/HandlerStack.php(75): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#6 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Client.php(333): GuzzleHttp\HandlerStack->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#7 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Client.php(169): GuzzleHttp\Client->transfer(Object(GuzzleHttp\Psr7\Request), Array)
#8 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Client.php(189): GuzzleHttp\Client->requestAsync('GET', Object(GuzzleHttp\Psr7\Uri), Array)
#9 /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/ClientTrait.php(44): GuzzleHttp\Client->request('GET', 'https://httpbin...', Array)
#10 /Users/hdj/github/huangdijia/odin-demo/test.php(11): GuzzleHttp\Client->get('https://httpbin...', Array)
#11 [internal function]: {closure}()
#12 {main}
  thrown in /Users/hdj/github/huangdijia/odin-demo/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php on line 84
@huangdijia
Copy link
Author

相关issue:hyperf/odin#9

@huangdijia
Copy link
Author

我找到问题了,问题在于 openssl => OpenSSL 1.1.1v 1 Aug 2023 ,换成 openssl => OpenSSL 3.5.0 8 Apr 2025 就可以了。

@matyhtf
Copy link
Member

matyhtf commented Jun 2, 2025

Connection refused 一般是端口未监听。

如果切换 openssl 版本可以解决,可能问题是出现在 SSL handshake 阶段。建议通过 strace 追踪一下,另外可使用

openssl s_client httpbin.org:443

验证是否可以连接

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants