Reputation: 3192
I'm trying to get response headers using CURLOPT_HEADERFUNCTION
curl_setopt($ch, CURLOPT_HEADERFUNCTION, function($curl, $headerLine) use($date) {
file_put_contents('/tmp/response-headers.log', $date . " " . print_r($headerLine, true), FILE_APPEND);
});
$response = curl_exec($ch);
Received header is HTTP/1.1 200 OK
, but $response
is empty. However, when I comment out the curl_setopt
function above, everything works fine and I get full response body.
How can I receive full body while dumping headers to file?
Upvotes: 0
Views: 507
Reputation: 10643
The documentation for CURLOPT_HEADERFUNCTION says
A callback accepting two parameters. The first is the cURL resource, the second is a string with the header data to be written. The header data must be written by this callback. Return the number of bytes written.
Your function does not return the number of bytes written.
Upvotes: 1