开发者

Stop php script execution

开发者 https://www.devze.com 2023-01-19 05:22 出处:网络
I have php_mod and an apache server. If I start a script from the browser it will persist until the execution is complete ( even if i close the browser )

I have php_mod and an apache server. If I start a script from the browser it will persist until the execution is complete ( even if i close the browser )

How can i stop the proces开发者_高级运维s ?


Normally, if you're sending output, this doesn't happen: if the webserver detects a disconnect, the PHP process is also stoppend (which is why we have functions like register_shutdown_function to make sure something is done (unelss you encounter a fatal error of course)).

However, as HTTP is stateless, the only point in time the webserver will detect a disconnect is when it is trying to send content (see also the remarks at ignore_user_abort (default is false, which is what you want)). Depending on the context of the request, a workable kludge could be in big loops to send non-displayed data to the user, in HTML that could be to send whitespace and flush. This can end up in any buffer though, (PHP's, servers, other places in the network) so detection is still not 100%, but that is about unavoidable. A sane time limit to avoid infinite looping, and only upping that limit for requests that actually need them is about the best you can do.


Check whether ignore_user_abort(true) is being set anywhere in the script. Or if there is a php_value ignore_user_abort directive set in .htaccess


use in your script (if an amount of time has passed)

die();


Closing the browser does not kill the running process. If you want to stop the background process, you will have to kill the process.

If you are using windows, you can restart apache using Apache service manager or kill it using Task Manager.

0

精彩评论

暂无评论...
验证码 换一张
取 消