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?