Created
October 15, 2014 20:32
-
-
Save rudiedirkx/ec82d2120654c79bffa0 to your computer and use it in GitHub Desktop.
End request, but keep going (Apache)
This file contains hidden or 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 | |
_liveLongStart(); | |
echo "Processing the hell outta everything....\n"; | |
echo "\n"; | |
echo "We'll email you as soon as this is done.\n"; | |
_liveLongEnd(); | |
// Do lots of slow stuff here | |
$time = microtime(1) - $GLOBALS['_liveLongStart']; | |
mail( | |
'[email protected]', | |
'Slow stuff is done', | |
"We're done! That took a while! " . number_format($time, 4) . " sec to be precise.", | |
"From: [email protected]" | |
); | |
function _liveLongStart() { | |
$GLOBALS['_liveLongStart'] = microtime(); | |
// Start buffering, first thing | |
ob_start(); | |
} | |
function _liveLongEnd() { | |
// Catch output and start writing | |
$size = ob_get_length(); | |
header("Content-Encoding: none"); | |
header("Content-Length: $size"); | |
header('Connection: close'); | |
// Print output here | |
ob_end_flush(); | |
ob_flush(); | |
flush(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment