Closed harusakura924 closed 8 months ago
In addition, it works for me to use the following method, but I still can't get the connection timeout message. If I use $response->getStatusCode()
, you will only get Unable to get status code: referred header information is missing.
, you know there is a problem, but you don’t know where the problem is. It may be a client setting error, it may be a network problem...
header('content-Type: text/plain; charset=utf-8');
try
{
$client = new \yii\httpclient\Client();
$request = $client->createRequest()
->setMethod('GET')
->setUrl(Url::to(['time-out'], 'https'))
->setOptions([
'timeout' => 5,
]);
\yii\helpers\VarDumper::dump($request->toString(), $depth=10, $highlight=false); echo "\n";
$response = $request->send();
\yii\helpers\VarDumper::dump('ok', $depth=10, $highlight=false); echo "\n";
// time out, Unless you call isOk or statusCode, you will not be told time out.
\yii\helpers\VarDumper::dump($response, $depth=10, $highlight=false); echo "\n";
} catch (\yii\httpclient\Exception $e) {
\yii\helpers\VarDumper::dump('error', $depth=10, $highlight=false); echo "\n";
\yii\helpers\VarDumper::dump($e, $depth=10, $highlight=false); echo "\n";
}
exit();
By default client is using StreamTransport instead of CurlTransport as described here so your options don't apply. Is it the case?
By default client is using StreamTransport instead of CurlTransport as described here so your options don't apply. Is it the case?
Thank you for your reminder. I originally used StreamTransport
with CURL Options, but it had no effect.
If you use TimeOut of StreamTransport
you cannot get the information that the connection was interrupted due to TimeOut, but when I change to CurlTransport
I will be able to get the information I want.
What steps will reproduce the problem?
Use
yii\httpclient\Client
to create a Request and set Options CURLOPT_TIMEOUT => 10 and CURLOPT_CONNECTTIMEOUT => 5What's expected?
If you use php curl.
You will get the following message within 10 seconds.
What do you get instead?
abnormal waiting.
Additional info