Closed NGTmeaty closed 6 years ago
Eek, you're right. The docs are outdated.
Should be more like
$middleware = new GuzzleHttp\Profiling\Middleware(new GuzzleHttp\Profiling\Clockwork\Profiler($clockwork->getTimeline()));
$stack->push($middleware);
Could you double check and send a PR for the README.md file, please?
Cheers
Hey, back again. Can't seem to get this working! Here's my code.
$clockwork = new \Clockwork\Clockwork();
$middleware = new \GuzzleHttp\Profiling\Middleware(new \GuzzleHttp\Profiling\Clockwork\Profiler($clockwork->getTimeline()));
$stack = \GuzzleHttp\HandlerStack::create();
$stack->push($middleware);
That's not enough information for me to find out what's wrong. Looks good to me. I'm not at my computer so I can't help you out.
Figuring stuff like this out without asking for help at every hurdle, is an essential tool for anyone to become a successful developer.
Sorry, was just looking to see if you had any insights into it. It seems like Clockwork isn't getting any of the data being passed.
Check with https://github.com/itsgoingd/clockwork. It's possible that isn't setup correctly to add the X-Clockwork headers to your Response.
Regular clockwork is working. I can see the actual data is being passed to the middleware, the data from Guzzle isn't being put into Clockwork. I'll check over there. Thanks! 👍
Did you new up Guzzle Client with the correct stack that has the middleware?
Yup, I did.
I dealt with the same problem and partially solved it.
For a Vanilla PHP integration (I don't know if that was the case for @NGTmeaty) you have to call $clockwork->requestProcessed();
as described in the docs.
Here is my code:
public function __construct(array $config)
{
$this->stack = HandlerStack::create();
$this->stack->push(Middleware::tap( /* Monolog Logging*/ ), 'log');
$this->clockwork = \Clockwork\Support\Vanilla\Clockwork::init();
$profiler = new \GuzzleHttp\Profiling\Clockwork\Profiler($this->clockwork->getTimeline(););
$middleware = new \GuzzleHttp\Profiling\Middleware($profiler);
$this->stack->push( $middleware, 'clockwork');
$this->client = new Client([
'base_uri' => $this->getOption('base_uri'),
'handler' => $this->stack
]);
}
public function request($method, $path, $data = [])
{
$response = $this->client->request($method, $path, $data);
$this->clockwork->requestProcessed();
}
This is not very elegant, and I have to figure out how to use Clockwork globally in my app (Fatfreeframework), but at least I get the timeline for all calls.
GuzzleHttp\Middleware\Log\Clockwork doesn't exist. I cannot use the example code to get it working.