如何在php中检测用户中止连接?

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.