Detecting user interrupt with output buffering included in PHP

The Notes section in the ignore_user_abort () function documentation assumes that PHP cannot detect that the user has canceled the request if data is not sent to the client. This is true for the function connection_status(). Unfortunately, I need to detect a user interrupt (an ajax request that can be canceled) on a page that uses output buffering (and I cannot easily change this).

Is there any other way to detect user interrupt than using a function connection_status()? Or is there any specific way to make this function return the correct value? PHP should really know that the request was aborted because the packet was FINreceived from the client.

I have tried to analyze the metadata stream php://input, php://output, php://stdinand php://stdoutafter the read / write data is blocked and not blocked before and after the connection has been terminated, but it has not produced any useful changes state.

+3
source share
1 answer

, ... , flush(), ? , , - (), , , .

, , ...

function OBWanCallback($buffer)
{
    if( OBWan::$isFinished )
    {
        // -- Actual callbacks go here ...
    }

   return $buffer;
}

OBWan::startbuffer('OBWanCallback');
[ // -- Example functionality
    self::$callback = $callback;
    ob_start(self::$callback);
]

// -- in some code far, far away ...

OBWan::suspendbuffer();
[ // -- Example functionality
    self::$buffercache = ob_get_clean();
]

echo " ";
flush();

OBWan::resumebuffer();
[ // -- Example functionality
    ob_start(self::$callback);
    echo self::$buffercache;
    self::$buffercache = "";
]

// -- in some code far, far away ...

OBWan::outputbuffer();
[
    self::$isFinished = true;
    return ob_get_clean();
]

-, , , .

+1

All Articles