致命错误:脚本超出最大执行时间 30 秒
我有一位客户收到与脚本超时相关的错误。我已经包含了下面的代码,但我认为问题是需要延长超时。
这是我可以在代码中设置的内容,还是必须由网络托管服务商 (GoDaddy) 设置?
致命错误:第 170 行 D:\hosting\123\html\siteame\wp-content\plugins\myplugin\myplugin.php 中超出最大执行时间 30 秒
此时的代码是:
function my_copy_recurse($src,$dst){
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) )
{
if (( $file != '.' ) && ( $file != '..' ))
{
if ( is_dir($src . '/' . $file) ) {
my_copy_recurse($src . '/' . $file,$dst . '/' . $file);
}
else {
copy($src . '/' . $file,$dst . '/' . $file);
}
} //THIS IS LINE 170
}
closedir($dir);
}
I have a customer who is getting an error related to a script timeout. I've included the code below, but i think the issue is that the timeout needs to be extended.
Is this something I can set in the code, or does it have to be set by the web host (GoDaddy)?
Fatal error: Maximum execution time of 30 seconds exceeded in D:\hosting\123\html\siteame\wp-content\plugins\myplugin\myplugin.php on line 170
The code at that point is:
function my_copy_recurse($src,$dst){
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) )
{
if (( $file != '.' ) && ( $file != '..' ))
{
if ( is_dir($src . '/' . $file) ) {
my_copy_recurse($src . '/' . $file,$dst . '/' . $file);
}
else {
copy($src . '/' . $file,$dst . '/' . $file);
}
} //THIS IS LINE 170
}
closedir($dir);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
将您的代码更改为:
Change your code to this :
根据您的主机允许的设置,您也许可以使用 set_time_limit () 以秒为单位传递给它您希望它在超时之前花费多长时间(使用 0 表示无限)。例如:
GoDaddy 可能已阻止此操作,因此如果不起作用,请尝试联系他们
Depending on what settings your host has allowed you may be able to use set_time_limit() pass to it in seconds how long you want it to spend before it times out (use 0 for infinite). E.g:
GoDaddy may have blocked this though so if it doesn't work try contacting them
通过在“php.ini”文件中设置“max_execution_time = 600”对我有用。
By setting "max_execution_time = 600" in "php.ini" file worked for me.
吉里什的回答是不完整的。 info.php 中必须包含什么?
您可以使用以下位置提供的简单更新:修复致命错误最大执行时间30秒超过wordpress
Girish's answer is incomplete. What has to be included in info.php?
You may use simple update provided at: fix-for-fatal-error-maximum-execution-time-30-seconds-exceeded-wordpress
如果您在 GoDaddy、Windows 主机上托管您的网站并使用 WordPress,迟早您将面临最大执行超时问题。我面对这个问题已经有一段时间了,在谷歌上搜索了一下,我的头很痛。如果您遇到了如下一系列相同的问题:
这篇文章适合您>
info.php
将 info.php 上传到您的主机的根目录。现在浏览到 http://yourhost/info.php。屏幕上加载的内容都是 PHP 配置。查找已加载的配置文件并记下其值。就我而言,它是 C:\PHP5\php.ini。我们需要在自定义 PHP5.ini 文件中包含所有这些信息,但其信息太多,无法复制和格式化,因此我们将复制 GoDaddy 的默认文件并根据需要进行编辑。
启动文本编辑器并创建以下文件:
获取配置文件
(将 * 替换为加载的配置文件中显示的任何路径)
将文件 getconfig.php 复制到 badaddy,然后浏览到 http ://yourhost/baddaddy/getconfig.php.
一旦您在屏幕上看到“终于”字样,请返回 GoDaddy 控制面板中的文件管理器,转到 baddaddy 文件夹,您将看到那里出现一个新文件 PHP5.ini。下载此文件。这是 GoDaddy 设置的副本。
进行您需要的任何更改(只需知道您要更改什么即可,我不是 PHP 专家,因此如果您搞砸了某些内容,我不承担任何责任)。对于我的问题,我将 max_execution_time = 30 更改为 max_execution_time = 1200。
将编辑后的文件上传到应用程序的根目录,然后返回 GoDaddy 控制面板、IIS 管理,点击回收应用程序池,然后< em>等待一段时间(20 分钟)
浏览回 http://yourhost/info.php 确认新设置已到位
重要**
如果完成所有这些操作后,您在 GoDaddy WordPress 博客上看到“500:内部服务器错误”,
12. 在刚刚编辑的 PHP5.ini 中将 log_errors 从 log_errors = On 更改为 log_errors = Off 并重新上传,回收应用程序池并等待。如果找不到日志文件,则会弹出 500 错误。
我不是 PHP 专家,但这件事对我有用,博客仍然加载缓慢,但从那时起我没有看到任何“致命错误:30 秒超时”。
If you've hosted your site on GoDaddy, Windows Hosting and are using WordPress, sooner or later you will face the max execution time out problem. I faced this problem for quite some time and looked aroung google, hitting my head. If you've faced the same series of problems as below:
this post is for you>
info.php
upload info.php to the root of your hosting. Now browse to http://yourhost/info.php. Whatever loads up on the screen is the PHP config. Look for Loaded Configuration File and note down its value. IN my case it is C:\PHP5\php.ini. We need all this information in our custom PHP5.ini file but its too much info to copy and format, so we will copy GoDaddy's default file and edit it as necessary.
fire your text editor and create the following file:
getconfig.php
<?php copy('C:\PHP5\php.ini'*, 'PHP5.ini'); echo('finally'); ?>
(replace * with whatever path shows up in Loaded Configuration File)
copy file getconfig.php to badaddy and now browse to http://yourhost/baddaddy/getconfig.php.
Once you see "finally" written on screen, go back to the filemanager in GoDaddy Control Panel, goto baddaddy folder and you will see a new file PHP5.ini appear there. Download this file. This is a copy of GoDaddy Settings.
Make whatever changes you need to(just know what you're changing, I am not a PHP expert, so I cannot be responsible if you screw up something). For my problem, I changed the max_execution_time = 30 to max_execution_time = 1200.
Upload the edited file to the root of your application and back in the GoDaddy Control Panel, IIS Management, hit Recycle App Pool, and then WAIT FOR A WHILE (20 minutes)
browse back to http://yourhost/info.php to confirm the new settings are in place
IMPORTANT **
IF you see a "500: Internal Server Error" on your GoDaddy WordPress Blog after doing all this,
12. Change the log_errors from log_errors = On to log_errors = Off in the PHP5.ini you just edited and re-upload, recycle app pool and wait. The 500 error pop up if the log file cannot be found.
I AM NO PHP EXPERT but this thing worked for me, the blog still loads slow but I have not seen any "Fatal Error: 30 second timeout" since then.
要限制最大执行时间,请使用
set_time_limit($seconds)
。如果将
$seconds
设置为零,则不施加时间限制。因此,只需在脚本开头添加set_time_limit(0)
,脚本就会一直运行到最后。但是,如果用户的浏览器由于浏览器超时而断开连接,您的脚本可能会停止,因此您需要在脚本开头添加ignore_user_abort(true)
以忽略它并准确工作到脚本末尾。To limit the maximum execution time use
set_time_limit($seconds)
.If set
$seconds
to zero, no time limit is imposed. So just addset_time_limit(0)
at the beginning of the script and script will work till the end. But if user's browser disconnects due to browser timeout your script could be halted, so you need to addignore_user_abort(true)
at the beginning of the script to ignore it and work exactly till the end of the script.