Skip to content

Instantly share code, notes, and snippets.

@sergeycherepanov
Last active May 12, 2019 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergeycherepanov/f5a64ff0695db906650b7aa5bf34b3fa to your computer and use it in GitHub Desktop.
Save sergeycherepanov/f5a64ff0695db906650b7aa5bf34b3fa to your computer and use it in GitHub Desktop.
<?php
/**
Extension url: https://github.com/runkit7/runkit7
*/
runkit_function_copy('curl_exec', 'curl_exec_orig');
function curl_exec_redefined($ch) {
if (!is_resource($ch)) {
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
throw new \Exception();
}
$response = curl_exec_orig($ch);
$dir = '/tmp/curl/' . date('Ymd_His') . '_' . getmypid();
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
}
ob_start();
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$trace = ob_get_clean();
file_put_contents($dir . '/curl_exec_result_' . microtime(true) . '.log', $response . PHP_EOL .PHP_EOL .$trace);
return $response;
}
runkit_function_redefine('curl_exec', '', 'return curl_exec_redefined(func_get_arg(0));');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment