Last active
January 20, 2017 17:55
-
-
Save matt-schwartz/d3a28ed342461367bc7935e71c7940e6 to your computer and use it in GitHub Desktop.
Show PHP shutdown sequence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Testing shutdown sequence | |
// Adapted from https://evertpot.com/160/ | |
ob_start( | |
function($buffer) { | |
return $buffer . "output buffer flushed\n"; | |
} | |
); | |
$empty = function() { | |
return true; | |
}; | |
$close = function() { | |
echo "session close\n"; | |
return true; | |
}; | |
$write = function() { | |
echo "session write\n"; | |
return true; | |
}; | |
session_set_save_handler($empty, $close, $empty, $write, $empty, $empty); | |
session_start(); | |
register_shutdown_function( | |
function() { | |
echo "register_shutdown_function\n"; | |
} | |
); | |
class MyClass { | |
function __destruct() { | |
echo "object destructor\n"; | |
} | |
} | |
$myObject = new MyClass; | |
# Output (PHP 7): | |
# register_shutdown_function | |
# object destructor | |
# output buffer flushed | |
# session write | |
# session close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment