1

I try to log all requests aborted by users, but I found connection_status() not work as I expected.

<?php
ignore_user_abort(true);
ob_implicit_flush();
//do something
sleep(5);
header('Content-Type: text/json');
echo json_encode($output);
flush();
ob_flush();
if(connection_status() & CONNECTION_ABORTED){
    //log aborted request
}

The client timeout is 2 seconds, and I always got "0" as connection_status().

According to document, connection status will not be checked until script try to output something. So i added flush codes, but it still got "0" as connection_status().

Please help me understand the php connection handler. Thanks.

Gucci Koo
  • 541
  • 4
  • 10
  • I don't think sleep counts towards program execution time so it isn't going to work as a way of testing a timeout response. http://stackoverflow.com/questions/740954/does-sleep-time-count-for-execution-time-limit – GordonM Dec 08 '14 at 09:23

0 Answers0