PhpDig.net

What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.




connection_status

Name

connection_status — Gets the current connection state.

Synopsis

int connection_status(void)

Returns

Integer bitfield representing the connection state

Description

connection_status() returns a bitfield containing the current status of the connection. The following table lists the possible values returned.

Status

Integer Value

(PHP 4.0.6 or earlier)

Named Constant

(PHP 4.0.7 or later)

Description
Normal 0 CONNECTION_NORMAL The connection is in a normal state.
Aborted 1 CONNECTION_ABORTED The connection was broken by the user or due to a network error.
Timed Out 2 CONNECTION_TIMEOUT The script ran past the maximum execution time allowed by set_time_limit() or the max_execution_time ini directive.
Aborted and Timed Out 3 CONNECTION_ABORTED & CONNECTION_TIMEOUT The connection has been broken and the script timed out.


See also

To set the maximum execution time:

max_execution_time ini directive

set_time_limit()

To deal with a terminated connection:

register_shutdown_function()

To ignore user aborts:

ignore_user_abort()



Example

Example 185. Mail the connection state somewhere

<?php
$email = 'your-name@your-host.tld';

defined ('CONNECTION_NORMAL')
   or die ("The CONNECTION_* constants are not defined in this version of PHP.");

ignore_user_abort (TRUE);

while ($x++ < 60) {
   print $x;
   sleep (1);
}

switch (connection_status ()) {
case CONNECTION_NORMAL:
   $status = 'Normal';
   break;
case CONNECTION_ABORTED:
   $status = 'User Abort';
   break;
case CONNECTION_TIMEOUT:
   $status = 'Max Execution Time exceeded';
   break;
case (CONNECTION_ABORTED & CONNECTION_TIMEOUT):
   $status = 'Aborted and Timed Out';
   break;
default:
   $status = 'Unknown';
   break;
}

mail ($email, "Connection Status: $status", '');
?>



PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.