Created
January 1, 2011 02:58
-
-
Save jameshartig/761520 to your computer and use it in GitHub Desktop.
How to get php-cgi to detect if you have reset the connection
This file contains 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
/* | |
The following example shows how to correct detect connection status under php-cgi | |
Works under apache and nginx. Cannot get it to work under lighttpd. | |
*/ | |
ignore_user_abort(true); | |
ob_implicit_flush(true); //put these at the beginning | |
//loop and keep doing something until the user aborts | |
while (true) { | |
//keep the following flushes in this order. you must have them in this order to have php | |
//try to get the connection. I don't know why, but it works. | |
ob_end_flush(); | |
flush(); | |
ob_end_clean(); | |
if(connection_status() != CONNECTION_NORMAL) { | |
//do something before we die? | |
exit(0); | |
} else { | |
//we have a normal operation still | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment