PHP, Log curl requests

From Wiki de Flat Estrategia Digital
Jump to: navigation, search
/*
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)

Facebook Comments