Created
June 11, 2014 08:24
-
-
Save lyonsun/21aa78ac0017dec956f8 to your computer and use it in GitHub Desktop.
php script to run something in background every after closing browser.
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 | |
| 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(); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
starring:
http://stackoverflow.com/questions/16294106/continue-php-script-after-connection-close
Red