如果PHP脚本达到了允许的最大执行时间,它是立即终止还是在当前指令完成后立即终止? [英] if PHP script reaches max allowed exec time, is it terminated immediately or right after current instruction finishes?

查看:108
本文介绍了如果PHP脚本达到了允许的最大执行时间,它是立即终止还是在当前指令完成后立即终止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经接近服务器上的最大执行时间,并且不允许更改它.该脚本下载数据并将其写入文件.潜在的问题是,在将文件写入磁盘期间,脚本可以达到最大执行时间.因此,对我来说至关重要的是,要知道在达到exec的最大允许时间后脚本是否终止.是立即发生的,并且可能导致磁盘上存储的文件不完整,或者脚本在最后一条指令/功能结束后立即终止,因此我可以确定磁盘上的所有文件都是有效的吗?

该主题的第二个问题:
如果脚本在执行fwrite()函数后终止而不执行fclose()会发生什么情况?它会导致在磁盘上创建未完成(无效)的文件吗?

第三个问题
如果脚本没有立即终止,那么它会在当前指令结束或调用函数后终止吗?因为如果脚本在当前指令之后终止,则执行fwrite()可能无法到达该函数的末尾并停止在函数体内的某个位置.

I'm close to the max execution time on my server and I'm not allowed to change it. The script downloads data and writes it to files. The potential problem is that the script can reach maximum execution time during writing a file to disk. Therefore it is essential to me to know if the termination of a script after reaching max allowed time for exec. is immediately and can lead to an incomplete file stored at disk or the script is terminated right after last instruction/function ends so I can be sure all files at disk are valid?

2nd question to that topic:
What would happen if script will be terminated after fwrite() function without executing fclose() - can it lead to create not complete (invalid) file at disk?

3rd question
if script is not terminated immediately then is it terminated after current instruction ends or call to a function? Because if the script is terminated after current instruction then executing fwrite() can not reach the end of that function and stop somewhere within function body.

推荐答案

最大执行时间不受系统调用,流的影响 操作等.

The maximum execution time is not affected by system calls, stream operations etc.

您的Web服务器可以具有其他超时配置,这些配置也可能 中断PHP执行. Apache有一个Timeout指令,而IIS有一个 CGI超时功能.两者默认为300秒.查看您的网络服务器 有关详细信息的文档.

Your web server can have other timeout configurations that may also interrupt PHP execution. Apache has a Timeout directive and IIS has a CGI timeout function. Both default to 300 seconds. See your web server documentation for specific details.

请参见 PHP手册:运行时配置 由此得出的结论是,fwrite调用将正确执行到最后.服务器(例如apache)也可以强制脚本停止.在这种情况下,fwrite可能会中断.但是由于默认值为300,因此您很可能不会遇到该超时.

see PHP manual: Runtime configuration From that I conclude that the fwrite call will properly be executed to the end. The server (e.g. apache) can also force a script to stop. In this case fwrite might get interupted. But as it is 300 as a default you propably do not run into that timeout.

这篇关于如果PHP脚本达到了允许的最大执行时间,它是立即终止还是在当前指令完成后立即终止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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