狂饮5.3 - 获取异步请求的请求时间 [英] Guzzle 5.3 - Get request duration for asynchronous requests

查看:415
本文介绍了狂饮5.3 - 获取异步请求的请求时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定时同步请求如下建议:
<一href=\"http://stackoverflow.com/questions/31341254/guzzle-6-get-request-total-time\">guzzle-6-get-request-total-time

I am timing synchronous requests as suggested here: guzzle-6-get-request-total-time

不过,我也有与获得批处理执行异步两个或多个请求的狂饮池。我需要检索每个请求了返回的时间。

But I also have a guzzle pool with two or more requests that get batch-executed asynchronously. I need to retrieve the duration each request took to return.

我敢肯定有一个简单的方法来检索这些信息,我只是俯瞰。该相关信息是在基础袅袅,我只是不知道该如何得到他们。

I am certain there is a simple way to retrieve this information that I am just overlooking. The infos are in the underlying curl, I am just unsure how to get to them.

推荐答案

原来,通过听取完整的情况下,可以捕捉整个transferinfo:

Turns out, by listening to the complete event, one can catch the entire transferinfo:

    $client = new \GuzzleHttp\Client();
    $guzzleRequests = $this->getGuzzleRequests();

    foreach($guzzleRequests as $myRequest)
    {
        $myRequest->getEmitter()->on(
            'complete',
            function (CompleteEvent $e) {
                var_dump($e->getTransferInfo());
                var_dump($e->getTransferInfo()['url']);
                var_dump($e->getTransferInfo()['total_time']);
            }
        );
    }

    // Results is a GuzzleHttp\BatchResults object.
    $results = Pool::batch($client, $guzzleRequests);

该TransferInfo有更多的,但我需要的是请求的URL,以确定正在请求该​​API和总时间的期限。

The TransferInfo has much more, but all I needed was the request url to identify which API was being requested and the total time as the duration.

这篇关于狂饮5.3 - 获取异步请求的请求时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆