即使在关闭页面后,脚本是否会继续运行? [英] Will a script continue to run even after closing a page?

查看:213
本文介绍了即使在关闭页面后,脚本是否会继续运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我通过jquery ajax调用一个php文件,它包含一个脚本来做一些需要一段时间的东西 - 例如上传一个大视频 - 然后我关闭页面:php脚本是否继续加载视频?

if i call a php file via jquery ajax, that contains a script to do some stuff that takes a while — for instance uploading a big video — and then I close the page: does the php script keep loading the video or not?

推荐答案

见这里:
http://php.net/manual/en/function.ignore-user-abort.php


int ignore_user_abort ([ bool $value ] )

设置客户端断开连接是否会导致脚本中止。

Sets whether a client disconnect should cause a script to be aborted.

将PHP作为命令行脚本运行时,脚本的tty消失而脚本没有被终止然后脚本会在下次尝试写任何东西时死掉,除非将值设置为TRUE

When running PHP as a command line script, and the script's tty goes away without the script being terminated then the script will die the next time it tries to write anything, unless value is set to TRUE

还有一个同名的PHP配置选项:
http://php.net/manual/en/misc.configuration.php

There also is a PHP configuration option of the same name: http://php.net/manual/en/misc.configuration.php

By默认情况下,如果你什么都不做,根据PHP手册,默认是中止脚本。
http://php.net/manual/en/features。 connection-handling.php

By default, if you do nothing, according to the PHP manual the default is to abort the script. http://php.net/manual/en/features.connection-handling.php

必要更新

似乎我(不知不觉中)欺骗了我的方式到声望点,因为我没有提供(正确的)答案,但现在感谢测试并继续轻推 mellamokb

It seems I (unknowingly) tricked my way to "reputation points", because I did NOT supply the (correct) answer, but here it is now thanks to testing and continued nudging from "mellamokb":

引用
好的,我看了一下PHP源代码,如果我没有错过任何内容,我现在有了答案。ignore_user_abort 仅当PHP在尝试向用户输出内容时收到错误时才会检查标志。因此,根据我的理解,没有办法中断不产生任何输出的代码。

Quote: "Ok, I took a look at the PHP source code and, if I didn't miss anything, I now have the answer. The "ignore_user_abort" flag is only checked when PHP receive an error trying to output something to the user. So, in my understanding, there is no way to interrupt code which doesn't produce any output."

好吧,我并没有完全离开,但重要的是要知道这一切看看你的脚本是否产生了任何输出!

Okay, I wasn't totally off, but it is important to know that it all depends on whether or not your script produced any output!

如果你读过这个,也请看看下面的评论。

If you read THIS, also DO check out the comments below.

这篇关于即使在关闭页面后,脚本是否会继续运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆