Say a user clicked a button, which resulted in a jquery ajax request being sent to my server.
The server begins a complicated process in response to the ajax request. Lets say that process takes 5 minutes to finish.
In the meantime the user gets bored and closes his browser window.
Will the script on the server continue its processing until it finishes on its normal time, or will it stop?
Same thing if the user visits a url, e.g example.com/process.php?data=xxx. This starts process.php which begins to process the data, and will take 5 mins to finish processing.
Will this processing always continue on, or if the user closes the browser, will it stop?
(I'm asking because I'm concerned about the process being left half finished and resulting in corrupt data).
Chapter 1. PHP: What, Why, and Where? PHP is ultimately just text that is taken by your web server and turned into a set of commands and information for your web browser. And because you're just working in text, there's not a lot you have to do to get going as a PHP programmer.
You can use pkill -9 php or if pkill itsn't present you can use ps -efw | grep php | grep -v grep | awk '{print $2}' | xargs kill to kill all php processes.
PHP is a server side scripting language. This means that it is executed on the server. The client applications do not need to have PHP installed.
PHP is not intended for execution in a browser. It is for web servers to execute, or other preprocessing on the PHP-installed computer. PHP runs in several incarnations when installed on a computer: from the command line.
PHP won't notice that the browser closed the connection unless it tries to output something (e.g. echo). If it fails to output something, the script will be terminated unless ignore_user_abort
is On.
So the script will terminate only if the following conditions are met:
ignore_user_abort
setting is off (if the setting is off, php will terminate the script if fails to output something)You can avoid the script from terminating by enabling ignore_user_abort
.
You can use connection_aborted()
at anytime to check is the browser aborted the request.
A script can terminate unexpectedly for other reasons (e.g. max execution time, exception, etc); so you should make use of transactions, so that half-finished changes are canceled if the script terminates abnormally.
See: http://php.net/manual/en/function.ignore-user-abort.php. It depends on the ignore_user_abort setting and a few other conditions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With