How to get responseTime() after sending request?
kwazaro opened this issue · 4 comments
What steps will reproduce the problem?
Send simple request, like $response = $client->get('http://test.com')->send();
What's expected?
I want to get total request time, like $response->requestTime();
What do you get instead?
Calling unknown method: yii\httpclient\Response::responseTime()
Additional info
$response also has no ability to get request object in which this method is present.
Q | A |
---|---|
Yii version | 2.0.37 |
Yii HTTP Client version | 2.0.12 |
PHP version | 7.0 |
Operating system | Windows 10 |
Save the request instance before passing it for execution.
I will tell you what I'm trying to achieve. There is some problem in closing database after some timeout, so I should do the trick:
Yii::$app->db->close();
Yii::$app->db->open();
I want to do this after every request via HttpClient if the response time bigger than some value (for example, 15 seconds).
It is the convenient way to do this on EVENT_AFTER_SEND, but for Response class or for Request class? Maybe, there is more simple way. I have no ability to change mysql timeout configs on server.
$request = $client->get('http://test.com');
$response = $request->send();
$time = $request->requestTime();
if ($time > 2000) {
Yii::$app->db->close();
Yii::$app->db->open();
}
But overall the problem sounds very weird as well as solution. I don't get how database re-connect is related to HTTP request time.