PHP脚本在45秒后超时 [英] PHP Script Times out after 45 seconds
问题描述
我正在对数据库进行大量导入(大约20万条记录),并且导入脚本超时存在严重问题.我将手机用作秒表,发现每次通过时恰好在45秒时超时(内部服务器错误)...一次一次只能记录约200条记录,有时甚至更少.我扫描了phpinfo(),但没有将其设置为45秒;因此,我不知道为什么会这样做.
I am running a huge import to my database(about 200k records) and I'm having a serious issue with my import script timing out. I used my cell phone as a stop watch and found that it times out at exactly 45 seconds every pass(internal server error)... it only does about 200 records at a time, sometimes less. I scanned my phpinfo() and nothing is set to 45 seconds; so, I am clueless as to why it would be doing this.
我的max_execution_time设置为5分钟,我的max_input_time设置为60秒.我也尝试设置set_time_limit(0); ignore_user_abort(1);在页面顶部,但没有用.
My max_execution_time is set to 5 minutes and my max_input_time is set to 60 seconds. I also tried setting set_time_limit(0); ignore_user_abort(1); at the top of my page but it did not work.
注意,我的错误文件显示为:脚本头过早结束"作为执行错误.
It may also be helpful to note that my error file reads: "Premature end of script headers" as the execution error.
非常感谢您的协助.
推荐答案
我尝试了此页面上的所有解决方案,并且当然是从命令行运行的:
I tried all the solutions on this page and, of course, running from the command line:
php -f filename.php
就像布伦特所说的那样,是明智的选择.
as Brent says is the sensible way round it.
但是,如果您真的想从浏览器中运行一个脚本,该脚本在45秒后因500个内部服务器错误而不断超时(正如我在重建phpBB搜索索引时所发现的),那么可能是由mod_fcgid引起的.
But if you really want to run a script from your browser that keeps timing out after 45 seconds with a 500 internal server error (as I found when rebuilding my phpBB search index) then there's a good chance it's caused by mod_fcgid.
我有一个Plesk VPS,我通过编辑文件对其进行了修复
I have a Plesk VPS and I fixed it by editing the file
/etc/httpd/conf.d/fcgid.conf
具体地说,我改变了
FcgidIOTimeout 45
到
FcgidIOTimeout 3600
3600秒= 1小时.对于大多数人来说应该足够长,但是如果需要的话可以向上调整.我看到一个例子,其中引用了7200秒.
3600 seconds = 1 hour. Should be long enough for most but adjust upwards if required. I saw one example quoting 7200 seconds in there.
最后,重新启动Apache以激活新设置.
Finally, restart Apache to make the new setting active.
apachectl graceful
有人.现在已经困扰了我六个月!
HTH someone. It's been bugging me for 6 months now!
干杯
丰富
这篇关于PHP脚本在45秒后超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!