简体   繁体   English

停止执行PHP脚本

[英]Stop php script execution

I have php_mod and an apache server. 我有php_mod和一个Apache服务器。 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 process ? 我如何才能停止该过程?

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)). 通常,如果您要发送输出,则不会发生这种情况:如果网络服务器检测到断开连接,则PHP进程也将处于停止状态(这就是为什么我们使用诸如register_shutdown_function功能来确保已完成操作的原因(提示您遇到致命错误)当然))。

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)). 但是,由于HTTP是无状态的,因此Web服务器检测到断开连接的唯一时间点是尝试发送内容的时间(另请参见ignore_user_abort的备注(默认为false,这是您想要的))。 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 . 根据请求的上下文,可行的合并可能会陷入大循环,从而以HTML形式发送空白消息和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. 但是,这可以终止于任何缓冲区(PHP,服务器,网络中的其他位置),因此检测仍然不是100%,但这是不可避免的。 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. 检查是否在脚本中的任何位置设置了ignore_user_abort(true)。 Or if there is a php_value ignore_user_abort directive set in .htaccess 或者如果.htaccess中设置了php_value ignore_user_abort指令

在脚本中使用(如果已经过去了一段时间)

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. 如果您使用的是Windows,则可以使用Apache服务管理器重新启动apache或使用任务管理器将其杀死。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM