我正在尝试使用Guzzle(第6版)从PHP客户端分析对API服务器的请求。
在Guzzle 5.3中,有bad_alloc
和public abstract class Element {
public void accept(Visitor<? extends Element> v) {
v.visit(this);
}
}
public interface Visitor<T extends Element> {
void visit(T element);
}
事件处理。
complete
但是我怎么在v6中这样做?
答案 0 :(得分:2)
刚刚使用中间件找到它。这是代码。
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;
});
};
};
}
}
然后像这样附上探查器。
$stack = \GuzzleHttp\HandlerStack::create();
$stack->push(Profiler::profile());
$client = new \GuzzleHttp\Client([
'handler' => $stack
]);