PHP, Log curl requests
Jump to navigation
Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
/*
Option 1: Log to file.
Adapted from https://stackoverflow.com/a/35363599/1071459
Do this before curl_exec to log to file
*/
$file_location = ''; // CHANGE THIS
curl_setopt($curl_handle, CURLOPT_VERBOSE, true);
curl_setopt($curl_handle, CURLOPT_STDERR, fopen($file_location, 'a+'));
/*
Option 2: Get output in in buffer and into a variable.
From https://blog.kettle.io/debugging-curl-requests-in-php/
*/
# init (part 1 of 2)
ob_start();
$output_buffer = fopen('php://output', 'w');
curl_setopt($curl_handle, CURLOPT_VERBOSE, true);
curl_setopt($curl_handle, CURLOPT_STDERR, $output_buffer);
# end (part 1 of 2)
$response = curl_exec($curl_handle);
# init (part 2 of 2)
fclose($output_buffer);
$curl_verbose_debug = ob_get_clean();
# end (part 2 of 2)