Skip to content

Instantly share code, notes, and snippets.

@lyonsun
Created June 11, 2014 08:24
Show Gist options
  • Select an option

  • Save lyonsun/21aa78ac0017dec956f8 to your computer and use it in GitHub Desktop.

Select an option

Save lyonsun/21aa78ac0017dec956f8 to your computer and use it in GitHub Desktop.
php script to run something in background every after closing browser.
<?php
function closeOutput($stringToOutput){
set_time_limit(0);
ignore_user_abort(true);
header("Connection: close\r\n");
header("Content-Encoding: none\r\n");
ob_start();
echo $stringToOutput;
$size = ob_get_length();
header("Content-Length: $size",TRUE);
ob_end_flush();
ob_flush();
flush();
}
public function test_background_worker()
{
$outputContent = 'Content Goes Here...';
closeOutput( $outputContent );
sleep(10);
//do some background works ...
file_put_contents(__DIR__ . '/tmp.txt', "Text after 10 sec");
echo "you can not see me...";
exit();
}
@lyonsun

lyonsun commented Jun 11, 2014

Copy link
Copy Markdown
Author

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