When calling curl with php, I'm able to hook callback on CURLOPT_PROGRESSFUNCTION
and read headers during the request progress using curl_multi_getcontent($handle)
$handle = curl_init()
curl_setopt(CURLOPT_NOPROGRESS, false)
curl_setopt(CURLOPT_RETURNTRANSFER, true)
curl_setopt(CURLOPT_PROGRESSFUNCTION, function($handle) {
$response = curl_multi_getcontent($handle);
// some logic here
})
curl_exec($handle)
How can I do that with Guzzle?
The problem is that I cannot use curl_multi_getcontent($handle)
without setting CURLOPT_RETURNTRANSFER
to true
.
But when I set CURLOPT_RETURNTRANSFER
to guzzle' curl config, I can read headers in progress function $response = curl_multi_getcontent($handle);
However the response stream contains empty content.
$request->getResponse()->getBody()->getContents(); // always outputs ""
Edit: I have made this change https://github.com/guzzle/guzzle/pull/2173 so I can access handle in progress callback with progress settings:
'progress' => function($handle) {
$response = curl_multi_getcontent($handle);
// some logic here
})
That works as long as CURLOPT_RETURNTRANSFER
is true
. However as I mentioned earlier, the response contents is ""
then.