PHP Doku:: Überprüft, ob die Verbindung zum Client beendet wurde - function.connection-aborted.html

Verlauf / Chronik / History: (1) anzeigen

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

Ein Service von Reinhard Neidl - Webprogrammierung.

Sonstige Funktionen

<<Sonstige Funktionen



(PHP 4, PHP 5)

connection_abortedÜberprüft, ob die Verbindung zum Client beendet wurde


int connection_aborted ( void )

Überprüft, ob die Verbindung zum Client beendet wurde.


Gibt 1 zurück, falls die Verbindung zum Client beendet wurde, und andernfalls 0.

Siehe auch

4 BenutzerBeiträge:
- Beiträge aktualisieren...
18.12.2009 10:01
In order to detect a disconnection inside the script we need to flush the buffer (it is only when the the server tries to send the buffer content that it will see that the connection is broken).

Thus we need to use the ob_implicit_flush() function to flush automatically the buffer

This is an example of a disconnection detection :

// enables the automatic flush

verifyCommunication() {
$status = (connection_aborted()?"not ":"") ."sent";
persistCommunication(new Communication($status));

// we will check the communication state when the script finished
// this sleep is used to have time to break the connection on the client side

I use such a process to cancel a request if the client didn't get the acknowledgement because he will redo his request...
rickyale at ig dot com dot br
13.11.2009 20:49
(connection_aborted not working)
I had this problem years ago, now the problem came back after upgrading php... i tried everything i found and in the end the function ob_end_flush();  on top of script as post in php bug track solved the problem. Im using windows 7 x64 / php 5.2.4 / apache 2.2.14 (win32)

try adding ob_end_flush(); on top of you script.
i read something about this but can't remember where, it was related to a bug or something.

hope this help.
phpcoder at cyberpimp dot techlab dot info
27.06.2007 20:50
Although the documentation indicates it returns an int, I found comparing the return value with numeric values does not seem to work.

Example (does not work):
if (connection_aborted()==1) {
fwrite($filehandle, 'aborted!');

You're better off just assuming it returns boolean

Example (does work):
if (connection_aborted()) {
fwrite($filehandle, 'aborted!');
rickyale at ig dot com dot br
14.12.2002 1:29
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.


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

While(!Connection_Aborted()) {
"\n"; //this will save de while
Flush(); //Now php will check de connection
"My chat....";


PHP Powered Diese Seite bei
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",...)