0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.