我使用Workerman\Http\Client來(lái)對(duì)外請(qǐng)求(并開啟了協(xié)程),我發(fā)現(xiàn)在請(qǐng)求個(gè)別網(wǎng)站時(shí)會(huì)提示has been closed,我在本站和google上搜索與此有關(guān)的問題,有些人說(shuō)ssl問題,于是我Workerman\Http\ConnectionPool的create中記錄是否關(guān)閉ssl,事實(shí)上已關(guān)閉,我嘗試寫一個(gè)普通的curl來(lái)請(qǐng)求,卻可以拿到數(shù)據(jù),請(qǐng)問是什么回事呢
$http = new Client();
$option=[
'method' => 'get',
'version' => '1.1',
];
$testnet=$http->request('【域名】',$option);
#ConnectionPool 的create
protected function create($address, bool $ssl = false, string $proxy = ''): AsyncTcpConnection
{
$log = Log::channel('log2');//<----
$context = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
],
'http' => [
'proxy' => $proxy,
]
];
if (!empty( $this->options['context'])) {
$context = array_merge($context, $this->options['context']);
}
if (!$ssl) {
unset($context['ssl']);
}
if (empty($proxy)) {
unset($context['http']['proxy']);
}
if (!class_exists(Worker::class) || is_null(Worker::$globalEvent)) {
throw new Exception('Only the workerman environment is supported.');
}
$log->info('create:'.json_encode($context));
$connection = new AsyncTcpConnection($address, $context);
if ($ssl) {
$connection->transport = 'ssl';//<----
}
ProxyHelper::setConnectionProxy($connection, $context);
$connection->address = ProxyHelper::addressKey($address, $proxy);
$connection->connect();
$connection->pool = ['connect_time' => time()];
return $connection;
}
##日志結(jié)果:[2025-04-07 18:58:59] log2.INFO: create:{"ssl":{"verify_peer":false,"verify_peer_name":false,"allow_self_signed":true},"http":[]}
RuntimeException: The connection to 【域名】 has been closed. in /www/wwwroot/【項(xiàng)目】/vendor/workerman/http-client/src/Request.php:551
Stack trace:
#0 /www/wwwroot/【項(xiàng)目】/vendor/workerman/workerman/src/Connection/TcpConnection.php(1062): Workerman\Http\Request->onUnexpectClose()
#1 /www/wwwroot/【項(xiàng)目】/vendor/workerman/workerman/src/Connection/TcpConnection.php(874): Workerman\Connection\TcpConnection->destroy()
#2 /www/wwwroot/【項(xiàng)目】/vendor/workerman/workerman/src/Connection/AsyncTcpConnection.php(398): Workerman\Connection\TcpConnection->doSslHandshake()
#3 /www/wwwroot/【項(xiàng)目】/vendor/workerman/workerman/src/Events/Swoole.php(288): Workerman\Connection\AsyncTcpConnection->checkConnection()
#4 [internal function]: Workerman\Events\Swoole->Workerman\Events\{closure}()
#5 {main}
linux
-------composer.json--------
workerman/http-client ^3.0
workerman/webman-framework ^2.1