PHP Doku:: Liefert den Verbindungsstatus als Bitfeld - function.connection-status.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzSonstige GrunderweiterungenMiscellaneous FunctionsSonstige Funktionenconnection_status

Ein Service von Reinhard Neidl - Webprogrammierung.

Sonstige Funktionen

<<connection_aborted

connection_timeout>>

connection_status

(PHP 4, PHP 5)

connection_statusLiefert den Verbindungsstatus als Bitfeld

Beschreibung

int connection_status ( void )

Gibt den Verbindungsstatus als Bitfeld zurück.

Rückgabewerte

Der Verbindungsstatus als Bitfeld, der zusammen mit den CONNECTION_XXX-Konstanten verwendet werden kann, um den Verbindungsstatus zu ermitteln.

Siehe auch


5 BenutzerBeiträge:
- Beiträge aktualisieren...
jorge dot hebrard at gmail dot com
27.01.2009 1:01
You can always send chr(0) to check if browser is still alive, that will show no output in browser page (at least in Firefox).
ivo_gelov at gmx dot net
9.04.2008 19:01
Good idea for DB engines like MySQL with MyISAM which do not support transactions. But imagine that user requests a page with many (hundred) image thumbnails. Or if a PDF is generated from a HTML on-the-fly. This usually takes several minutes and if the user does not want to wait and aborts connection - PHP continues until all work is done.
In my opinion it will be MUCH more smarter (PHP is mature enough) to use signalling and terminate script immediately when connection is aborted instead of making presumptions that script author will continuously doing output and periodically flushing output buffer just in order to detect connection abort.
Mhm ....
Michael
21.03.2005 6: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.06.2004 18: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.01.2002 3: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
        
}
}
?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)