PHP 脚本在 Apache 中超时,但在 cli 中则不然
我有一个 PHP 脚本,大约需要 30 秒才能完成。当通过 php cli 运行它时,它成功完成(回显确认并将相关结果保存在本地文件系统上的文件中)。如果我通过 Apache 运行同一个文件,它似乎会超时或发生其他情况,大约 30 秒左右后,Firefox 不会提供预期的确认消息,而是让我下载一个空文件(其他浏览器的处理方式有所不同,但基本上是这样的)没有按计划进行)。没有创建应该在文件系统上创建的文件。
知道执行时间可能很长,我在脚本的开头设置了 set_time_limit(400)
。
关于如何调试这个的任何提示?是什么导致脚本在 Apache 中超时,但在 cli 中却不然?
I have a PHP script that takes about 30 seconds to complete. When running it through php cli it finishes successfully (echos a confirmation and saves relevant results in a file on a local file system). If I run the same file through Apache, it seems to time out or something, after about 30 seconds or so, instead of the expected confirmation message, Firefox offers me to download an empty file (other browsers treat it differently, but basically, something did not go as planned). The file that was supposed to be created on the filesystem is not created.
Knowing that the execution time could be long, I set set_time_limit(400)
in the beginning of the script.
Any tips on how I could debug this? What could be causing the script to time out in Apache, but not in cli?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
阅读此处的所有答案和评论后,我相信您的脚本不会超时。
我认为这是你的应用程序的崩溃。
apache 进程以受限制的用户身份运行,而 cli 则不然。
也许您正在将文件写入您无权访问的文件夹(在 apache 用户下)。
我也可能缺少 php 模块。
将 cli php.ini 与 apache php.ini 进行比较。
打开错误日志记录:
也许您处于测试环境中,您还可以启用
display_errors
。但在生产使用中始终将其关闭!
请参阅日志为什么 php 中止。
您可以使用
su
命令在 apache 帐户内的 cli 中运行 php 脚本。这可用于检查权限。
after reading all answers and comments here, i believe that your script does not timeout.
i think its an crash of you application.
the apache process runs in a restricted user your cli does not.
maybe you are writing a file to a folder, you do not have access to (under the apache user).
i is also possible that there are php modules missing.
compare you cli php.ini to the apache php.ini.
turn on error logging:
maybe you are in a test environment you may also enable
display_errors
.but turn this always off in production use!
see log why php aborts.
you can use the
su
command to run the php script from cli within the apache-account.this can be used to checks the rights.
除了 php 时间限制之外,cgi 可能会超时。
如果您在 apache 中使用 mod_fcgid,您还需要增加那里的时间。
看看手册
我认为你需要增加
FcgidIOTimeout 40
additional to the php time limit the cgi can timeout.
if you are using mod_fcgid with your apache you need also increase the time there.
take a look into the manual
i think you need to increase
FcgidIOTimeout 40
PHP CLI 和 PHP via Apache 使用不同的 php.ini 文件。检查 php.ini 文件中的 Apache 版本,并确认
max_execution_time
足够高以满足您的需求。您可以执行 phpinfo() 来获取当前使用的 php.ini 文件的位置。
PHP CLI and PHP via Apache use different php.ini files. Check the php.ini file for the Apache version and confirm that
max_execution_time
is high enough to accomodate your needs.You can execute
phpinfo()
to get the location of the currently-used php.ini file.