search for in the  
<connection_abortedconnection_timeout>
Last updated: Thu, 19 May 2005

connection_status

(PHP 3 >= 3.0.7, PHP 4, PHP 5)

connection_status -- Returns connection status bitfield

Description

int connection_status ( void )

Returns the connection status bitfield. See the Connection Handling description in the Features chapter for a complete explanation.

See also connection_aborted(), and ignore_user_abort().



User Contributed Notes
connection_status
Michael
20-Mar-2005 11:59
Yes it is true. I made some experiments with that functions 'connection_abortes()'. First a source made an error, which I see. They wrote: ignore_user_abort();

But that only gives you the status of the 'Abort-Setting'.
So I try (with little hope)
  'ignore_user_abort(true);'
And as I readout the setting it has changed it...

Next I see that the script runs after I disconnect with the site. But other experiments fail. I try some things and then it
was logical after an experiment: flush() is one of the necessary things. Without those output to the client the function
         'connection_aborted()' stays on 'false'
The Second is that you have to output something. Without that it also doesn't works.
So I now know that you have to echo something and then output the buffer. Only then 'the Script' (or the function)
'knows' that the client is disconnected.
toppi at kacke dot de
16-Jun-2004 11:06
Notice !

if you running a loop (while, foeach etc..)  you have to send something to the browser to check the status.

Example:

while(1){
   if (connection_status()!=0){
   die;
   }
}
doesnt work, if the user break/close the browser.

But a:

while(1){
   Echo "\n"; //<-- send this to the client
   if (connection_status()!=0){
   die;
   }
}
will work :)

i hope it will help some of you to safe some time :)

Toppi
rickyale at ig dot com dot br
13-Dec-2002 06:28
I know why nobody can use the functions connection_XXX(). If the php code do not send anything to buffer, the php dont check the connection, so, the connection_timeout will still NORMAL and will not be ABORTED.

Ex

<?php
Set_Time_Limit
(0);  //this you know what gonna do
Ignore_User_Abort(True); //this will force the script running at the end

While(!Connection_Aborted()) {
   Echo
"\n"; //this will save de while
  
Flush(); //Now php will check de connection
  
While(CONDITION) {
       Echo
"My chat....";
   }
 
Sleep(1);
}
?>

end
carlos at fischerinformatica dot com dot br
30-Jan-2002 08:58
Very very useful!
I was building a chat and I wanted my script to detect when the browser was closed, so the user could be deleted from the online_users table.

<?
echo str_repeat(" ",300);
ignore_user_abort(true); //this way, the user can stop the output, but not the script.
while (true) {
         echo
"test<br>\n";
        
flush();
        
sleep(2);
         if (
connection_status()!=0){
                 include (
'dbconnect.inc');
                
$sql="delete from online_users where online_user=$user";
                
$sql_exec=pg_exec($vChatDB, $sql);
                 die();
//kills the script
        
}
}
?>

<connection_abortedconnection_timeout>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT