Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

integer connection_status()


The connection_status function returns an integer describing the status of the
connection to the browser. The integer uses bitfields to signal whether a connection was
aborted or timed out. That is, binary digits are flipped on to signal either of the
conditions. The first bit signals whether the script aborted. The second signals whether
the script reached its maximum execution time. Rather than using 1 or 2, you can use the
convenient constants ABORTED and TIMEOUT. There's also a constant named NORMAL,
which is set to zero, meaning no bitfields are turned on.


An alternative to connection_status is to use connect_aborted and
connection_timeout, which each return TRUE or FALSE.


<?
function cleanUp()
{
$status = connection_status();


$statusMessage = date("Y-m-d H:i:s");
$statusMessage .= " Status was $status. ";


if($status & ABORTED)
{
$statusMessage .= "The script was aborted. ";
}
if($status & TIMEOUT)
{
$statusMessage .= "The script timed out. ";
}


$statusMessage .= "\n";
//write status to log file
error_log($statusMessage, 3, "status.log");
}


//set cleanUp to the shutdown function
register_shutdown_function("cleanUp");


//wait out the max execution time
sleep(35);


print("Fake task finished.\n");
?>


boolean connection_timeout()


The connection_timeout function returns TRUE when the current script has stopped
because the maximum execution time was reached. It is really of use only inside a
function you've registered as a shutdown function with register_shutdown_function.

Free download pdf