on_stats
Summary
: on_stats allows you to get access to transfer statistics of arequest and access the lower level transfer details of the handlerassociated with your client. on_stats is a callable that is invokedwhen a handler has finished sending a request. The callback is invokedwith transfer statistics about the request, the response received, or theerror encountered. Included in the data is the total amount of time takento send the request.
Types : - callable
Constant
: GuzzleHttp\RequestOptions::ON_STATS
The callable accepts a GuzzleHttp\TransferStats object.
1. use GuzzleHttp\TransferStats;
3. $client = new GuzzleHttp\Client();
5. $client->request('GET', 'http://httpbin.org/stream/1024', [
6. 'on_stats' => function (TransferStats $stats) {
7. echo $stats->getEffectiveUri() . "\n";
8. echo $stats->getTransferTime() . "\n";
9. var_dump($stats->getHandlerStats());
11. // You must check if a response was received before using the
12. // response object.
13. if ($stats->hasResponse()) {
14. echo $stats->getResponse()->getStatusCode();
15. } else {
16. // Error data is handler specific. You will need to know what
17. // type of error data your handler uses before using this
18. // value.
19. var_dump($stats->getHandlerErrorData());
20. }
21. }
22. ]);
