协程下似乎请求重定向的接口会无响应,测试请求非重定向的接口正常,不使用协程方式也请求正常
$requestOption = [
"method" => "GET",
'version' => '1.1',
'headers' => [
'X-Forwarded-For' => $ip,
'User-Agent' => $ua,
'Connection' => 'keep-alive'
],
'allow_redirects' => [
'max' => 10
],
//'success' => function ($response) {
//return $response->getBody();
// return $response;
//},
'error' => function ($exception) {
return $exception;
}
];
try{
//$tracingUrl = "https://www.workerman.net/";
$requestRs = $this->coroutineHttp->request(trim($tracingUrl),$requestOption);
$rrs = $requestRs->getStatusCode();
//$rrs = $requestRs;
}catch (\Exception $e) {
$this->logger->info("Test caught exception:". $e->getMessage());
$rrs = $e->getMessage();
} catch (\Throwable $e) {
$this->logger->info("Test caught exception:". $e->getMessage());
$rrs = $e->getMessage();
}
"workerman/workerman": "^5.0.0",
"revolt/event-loop": "^1.0.0",
"workerman/http-client": "^2.2.8"
找到个问题点。$options是复制的变量,$task是后置引用修改的,导致302重新建立请求对象时丢失了success回调,补上引用应该就解决了。