Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get responseTime() after sending request? #211

Closed
kwazaro opened this issue Sep 10, 2020 · 4 comments
Closed

How to get responseTime() after sending request? #211

kwazaro opened this issue Sep 10, 2020 · 4 comments

Comments

@kwazaro
Copy link
Contributor

kwazaro commented Sep 10, 2020

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
@samdark
Copy link
Member

samdark commented Sep 10, 2020

Save the request instance before passing it for execution.

@samdark samdark closed this as completed Sep 10, 2020
@kwazaro
Copy link
Contributor Author

kwazaro commented Sep 11, 2020

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.

@samdark
Copy link
Member

samdark commented Sep 11, 2020

$request = $client->get('http://test.com');
$response = $request->send();
$time = $request->requestTime();

if ($time > 2000) {
    Yii::$app->db->close();
    Yii::$app->db->open();
}

@samdark
Copy link
Member

samdark commented Sep 11, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants