Reputation: 57946
Hell all,
I have made use of the following ignore_user_abort.
ignore_user_abort(true); set_time_limit(0); session_start();
However, when I navigate away from the page which I fireoff an AJAX request, the script stops?
What am I doing wrong?
In the PHP manual it says:
PHP will not detect that the user has aborted the connection until an attempt is made to send information to the client. Simply using an echo statement does not guarantee that information is sent, see flush().
It seems to suggest you can use echo and it will just identify that the user has disconnected and it will continue?
Upvotes: 3
Views: 4626
Reputation: 3448
Some things to consider
Are you sure the user abort is causing the problem?
Have you checked the log to see if there are any errors logged.?
Does your server kill the script regardless of the the script itself?
Is the ajax call even being made? I assume it runs when the user navigates away.
You can use wireshark to watch the traffic between your browser and the webserver to make sure what you think is happening is actually happening.
DC
Upvotes: 0
Reputation: 7052
PHP will not detect... until an attemt is made to send information to the client
This sounds to me like: when php can't flush its buffer to the client: stop. So I suggest using ob_start()
to buffer everyting at the start of the page, you can also implement gzip this way: ob_start('ob_gzhandler')
.
Upvotes: 1
Reputation: 91963
Maybe your server has a built-in timeout that kills the script?
You should also note that you shouldn't use echo
in an aborted script, because you have nowhere to send the output.
Upvotes: 0