首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我如何分析口香糖6请求?

我如何分析口香糖6请求?
EN

Stack Overflow用户
提问于 2015-08-07 04:28:23
回答 1查看 1.3K关注 0票数 7

我试图使用Guzzle (v 6)分析来自PHP客户端的API服务器的请求。

在guese5.3中有这样的completebefore事件处理。

代码语言:javascript
复制
class GuzzleProfiler implements SubscriberInterface
{
    public function getEvents()
    {
        return [
            'before'   => ['onBefore'],
            'complete' => ['onComplete']
        ];
    }

    public function onBefore(BeforeEvent $event, $name)
    {
         start_profiling();
    }

    public function onComplete(CompleteEvent $event, $name)
    {
         end_profiling();
    }
}

但是我如何在v6中做到这一点呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-07 05:10:24

是用中间件发现的。这是密码。

代码语言:javascript
复制
class Profiler {

    /**
     * @return callable
     */
    public static function profile() {
        return function(callable $handler) {
            return function(\Psr\Http\Message\RequestInterface $request, array $options) use ($handler) {
                start_profiling();
                return $handler($request, $options)->then(function(\Psr\Http\Message\ResponseInterface $response) use ($token) {
                    end_profiling();
                    return $response;
                });
            };
        };
    }
}

然后像这样连接分析器。

代码语言:javascript
复制
$stack = \GuzzleHttp\HandlerStack::create();
$stack->push(Profiler::profile());
$client = new \GuzzleHttp\Client([
   'handler' => $stack
]);
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31869708

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档