Skip to content

Instantly share code, notes, and snippets.

@matt-schwartz
Last active January 20, 2017 17:55
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 matt-schwartz/d3a28ed342461367bc7935e71c7940e6 to your computer and use it in GitHub Desktop.
Save matt-schwartz/d3a28ed342461367bc7935e71c7940e6 to your computer and use it in GitHub Desktop.
Show PHP shutdown sequence
<?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