Name
connection_status()
Synopsis
int connection_status ( void )
The connection_status()
function takes no parameters and returns 0 if the connection is live and execution is still taking place; 1 if the connection is aborted; 2 if the connection has been aborted; and 3 if the connection has been aborted and subsequently timed out.
The last situation is only possible if ignore_user_abort(true)
has been used, and the script subsequently timed out. The values 0, 1, 2, and 3 evaluate to the constants CONNECTION_NORMAL
, CONNECTION_ABORTED
, CONNECTION_TIMEOUT
, and CONNECTION_ABORTED | CONNECTION_TIMEOUT
(a bitwise OR of the previous two).
This script can tell the difference between shutdown occurring because the script finished or because script timeout was reached:
function say_goodbye() { if (connection_status() = = CONNECTION_TIMEOUT) { print "Script timeout!\n"; } else { print "Goodbye!\n"; } } register_shutdown_function("say_goodbye"); set_time_limit(1); print "Sleeping...\n"; sleep(2); print "Done!\n";
Get PHP in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.