webman2.1启用eventloop=swoole::class后,http-client报错

zhengxq

问题描述

procss.php中开启'eventLoop' => \Workerman\Events\Swoole::class,
使用workerman/http-client3.0.5请求http://www.baidu.com在成,但是请求https://www.baidu.com异常了。

程序代码

$url = "https://www.baidu.com";

try {
// 使用协程创建客户端
$client = new Client();

// 发送异步请求并等待结果
$response = $client->request($url, [
    'headers' => [
        'Host' => 'www.baidu.com',
    ],
    'timeout' => 8,
    'connect_timeout' => 5,
    'ssl' => [
    'verify_peer' => false,
    'verify_peer_name' => false,
    'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT,
    ]
]);
return response($response->getBody());

} catch (\Throwable $e) {
return response("请求失败: " . $e->getMessage());
}

报错信息

变成等待30秒后,报错了,
请求失败: read 103.235.46.115:443 timeout after 30 seconds

操作系统及workerman/webman等框架组件具体版本

基于webman2.1、workerman 5.1.7、swoole 6.0.2、workerman/http-client3.0.5、docker中 php 8.3

83 1 1
1个回答

zhengxq

验证了下,改用fiber::class就可以使用协程,channel也能够生效

  • zhengxq 6天前

    找到问题了,是swoole必须要开启openssl,不然无法解析https

🔝