The connection-handling functions allow PHP developers to handle user aborts and script timeouts gracefully.
OverviewThe Zend engine tracks basic information about the state of the HTTP connection between a remote client and a PHP script. The connection can be in one of the following states: NORMAL, ABORTED, or TIMEOUT. The connection state is usually NORMAL. If the remote client disconnects (or experiences certain kinds of network errors), the status will become ABORTED. If the PHP script runs past the time limit imposed by the set_time_limit() function or the corresponding max_execution_time php.ini or Apache conf file directive, the state will become TIMEOUT.
It's possible for a connection to be in both the ABORTED and TIMEOUT states. This will happen in cases where ignore_user_abort has been set via the ignore_user_abort() function or the corresponding ignore_user_abort in php.ini or Apache conf file directive, the user has attempted to abort the script, and the script has run past the maximum execution time.
Connection handling may not operate properly on all platforms. Most notably, do not rely on these functions under the Windows family of operating systems.
Connection-Handling ConstantsThe following constants should be used to compare against the values returned by the connection_status() function. These constants were added in PHP 4.0.7. Prior to this version, direct comparison against the integer values returned by connection_status() was required.
| Constant Name | Description |
|---|---|
| CONNECTION_NORMAL | The connection is in (or ended in) a normal state. |
| CONNECTION_ABORTED | The script was aborted. |
| CONNECTION_TIMEOUT | The script exceeded the maximum execution time. |
php.ini Directives Related to the Connection-Handling FunctionsThe following configuration directives can be used to control the behavior of the connection-handling functions.
| Directive Name | Value Type | Description |
|---|---|---|
| ignore_user_abort | Boolean (On/Off) | If this setting is enabled, PHP continues running the script even after the user aborts the script or disconnects. |
| max_execution_time | integer | The maximum amount of time that a script can run before execution is halted. |
Installing Connection-Handling SupportConnection handling is one of the PHP core functions and doesn't need to be built in.
Table of Contents