PHP Function Reference

PHP connection_status() Function



The PHP connection_status() function is used to get the connection status bitfield.

Syntax

connection_status()

Parameters

No parameter is required.

Return Value

Returns the connection status bitfield, which can be used against the CONNECTION_* constants to determine the connection status.

Example: connection_status() example

In the example below a shutdown function is created which displays a message based on connection status.

<?php
//defining a shutdown function
function shutdown() {
  if(connection_status() == CONNECTION_TIMEOUT) {
     print 'Script timeout!'.PHP_EOL;
  } else {
     print 'Script is executed successfully!'.PHP_EOL;
  }
}

//registering the shutdown function
//it is called when the script ends
register_shutdown_function('shutdown');

//displaying some message
echo "Hello World!\n";
?>

The output of the above code will be similar to:

Hello World!
Script is executed successfully!

❮ PHP Miscellaneous Reference