Skip to content

Instantly share code, notes, and snippets.

@zgardner
Last active December 29, 2015 10:39
Show Gist options
  • Save zgardner/7658233 to your computer and use it in GitHub Desktop.
Save zgardner/7658233 to your computer and use it in GitHub Desktop.
Debugging PHP scripts that don't finish
<?
global $LOG_FILE_NAME;
$LOG_FILE_NAME = session_save_path() . '/' . uniqid('log_file_') . microtime(true);
file_put_contents($LOG_FILE_NAME . '.START', print_r($_REQUEST, true) . print_r($_SERVER, true) . print_r($_SESSION, true));
function log_file_shutdown_function () {
global $LOG_FILE_NAME;
file_put_contents($LOG_FILE_NAME . '.END', microtime(true));
}
register_shutdown_function('log_file_shutdown_function');
@zgardner
Copy link
Author

This script can be used as an auto_prepend_file for PHP scripts that don't correctly terminate. If you look for a START file without an END, you can see what request caused it. From this blog: http://keyholesoftware.com/2013/11/18/intro-to-scaling-php-part1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment