Skip to content

Instantly share code, notes, and snippets.

@rudiedirkx
Created October 15, 2014 20:32
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 rudiedirkx/ec82d2120654c79bffa0 to your computer and use it in GitHub Desktop.
Save rudiedirkx/ec82d2120654c79bffa0 to your computer and use it in GitHub Desktop.
End request, but keep going (Apache)
<?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(
'foo@bar.com',
'Slow stuff is done',
"We're done! That took a while! " . number_format($time, 4) . " sec to be precise.",
"From: bar@foo.com"
);
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