问题
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.
回答1:
The maximum execution time is not affected by system calls, stream operations etc.
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.
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.
回答2:
It is terminated immediately.
Your answer to 2nd question: No, fclose() is not necessary.
来源:https://stackoverflow.com/questions/17391747/if-php-script-reaches-max-allowed-exec-time-is-it-terminated-immediately-or-rig