tags:

views:

103

answers:

2

I can't seem to get the function connection_aborted to work with nginx. The code I used to test is as follow:

<?php
ignore_user_abort(true);
ob_implicit_flush();
$i = 0;
while (!connection_aborted()) {
    echo $i;
    $i++;
    sleep(1);
}
file_put_contents('test',$i);

In Apache, it works correctly, although it delays a little. i.e. When I press stop button on browser when "3", the 'test' file shows "8". That is an acceptable margin, but on nginx, it doesn't seem to output anything to the 'test' file.

A: 

My guess is that "connection_aborted()" is unable to detect the "ABORTED" connection
(and the script is still running)

Bob Fanger
That's also my guess, but I'm looking for a solution, unless you're telling me it's nginx's bug...
TheOnly92
I've only used nginx and lighttpd for static content. Sorry...
Bob Fanger
+1  A: 

Check your Nginx configuration, it should have

fastcgi_ignore_client_abort off;

This configuration key has off as the default, so even if you have no fastcgi_ignore_client_abort at all, your script should work as expected.

By the way, it is not possible to turn FastCGI buffering off in Nginx. It means Nginx will always use buffering when reading from a FastCGI script and thus there are two buffers involved: Nginx's own buffer and TCP buffer as well. This will potentially increase the delay.

Alexander Azarov