1

how can i detect a client disconnection in php. I have a web service that uses nusoap library and I want to detect web service client disconnection. I try with this code:

ignore_user_abort(true);            // Continue running the script even when the client aborts/disconnects
ob_flush();
flush();                           // Clean PHP's output buffer
usleep(500000);                     
echo "0\r\n\r\n"; 
ob_flush();                         // Clean output buffer
flush();                            // Clean PHP's output buffer
if(connection_aborted() != 0) {     
        //do something
}

It works but it has 2 problem:

  • Flush() function adds additional header causing this warning: Warning: Cannot modify header information - headers already sent in .\lib\nusoap-0_9_5\lib\nusoap.php on line...
  • The response of my web service is not well formatted due to additional character that i send echo "0\r\n\r\n" to check client connection.

How can I resolve problems listed above? There are other ways to detect web service client disonnection? Thanks

sri
  • 11
  • 2

0 Answers0