Skip to content

Instantly share code, notes, and snippets.

@jameshartig
Created January 1, 2011 02:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jameshartig/761520 to your computer and use it in GitHub Desktop.
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
/*
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