Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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