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.
connection_status
(PHP 4, PHP 5)
connection_status — Returns connection status bitfield
Description
int connection_status
( void
)
Gets the connection status bitfield.
Return Values
Returns the connection status bitfield, which can be used against the CONNECTION_XXX constants to determine the connection status.
See Also
- connection_aborted() - Check whether client disconnected
- ignore_user_abort() - Set whether a client disconnect should abort script execution
- Connection Handling for a complete description of connection handling in PHP.
connection_status
Michael
21-Mar-2005 06:59
21-Mar-2005 06:59
toppi at kacke dot de
16-Jun-2004 06:06
16-Jun-2004 06: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
carlos at fischerinformatica dot com dot br
31-Jan-2002 03:58
31-Jan-2002 03: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
}
}
?>