swoole-src icon indicating copy to clipboard operation
swoole-src copied to clipboard

guzzlehttp在stream=true时,设置超时无效

Open huelsgp27 opened this issue 9 months ago • 5 comments

Please answer these questions before submitting your issue.

  1. What did you do? If possible, provide a simple script for reproducing the error. 使用guzzleHttp请求一个被防火墙拦截的端口:
<?php
use GuzzleHttp\Client;

require 'vendor/autoload.php';

$http = new Swoole\Http\Server('127.0.0.1', 9501);
            $http->set(['hook_flags' => SWOOLE_HOOK_ALL]);

            $http->on('request', function ($request, $response) {
                $result = [];
                $client = new Client([
                    'timeout' => 5,
                    'connect_timeout' => 5,
                    'read_timeout' => 3,
                    'stream' => true
                ]);
                print_r(date("Y-m-d H:i:s")." 准备发起请求\n");
                $client->post("https://i.cmd.center:38000");
                print_r(date("Y-m-d H:i:s")." 发起请求之后\n");
                $response->end(json_encode($result));
            });
echo "http start";
$http->start();
  1. What did you expect to see? 发起一个请求:
time curl 127.0.0.1:9501

期望:在5秒内返回,代码抛出超时异常。

  1. What did you see instead? 超时设置并没有生效,超过1分钟才抛出异常。
 time curl 127.0.0.1:9501

real    1m5.592s
user    0m0.009s
sys     0m0.003s
  1. What version of Swoole are you using (show your php --ri swoole)? swoole

Swoole => enabled Author => Swoole Team [email protected] Version => 5.1.2 Built => Apr 29 2024 21:13:47 coroutine => enabled with boost asm context epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled sockets => enabled openssl => OpenSSL 3.0.11 19 Sep 2023 dtls => enabled http2 => enabled json => enabled curl-native => enabled zlib => 1.2.13 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled mysqlnd => enabled async_redis => enabled coroutine_pgsql => enabled

Directive => Local Value => Master Value swoole.enable_coroutine => On => On 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 => On => On swoole.unixsock_buffer_size => 8388608 => 8388608

  1. What is your machine environment used (show your uname -a & php -v & gcc -v) ? PHP 8.2.15 (cli) (built: Feb 13 2024 06:34:40) (NTS) Linux 462719e020fd 5.15.0-71-generic #78-Ubuntu SMP Tue Apr 18 09:00:29 UTC 2023 x86_64 GNU/Linux gcc version 12.2.0 (Debian 12.2.0-14)

huelsgp27 avatar May 16 '24 03:05 huelsgp27