致命错误:脚本超出最大执行时间 30 秒

发布于 2024-11-17 13:53:13 字数 761 浏览 1 评论 0原文

我有一位客户收到与脚本超时相关的错误。我已经包含了下面的代码,但我认为问题是需要延长超时。

这是我可以在代码中设置的内容,还是必须由网络托管服务商 (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

网白 2024-11-24 13:53:16

将您的代码更改为:

function my_copy_recurse($src,$dst){
    $dir = opendir($src); 

    @mkdir($dst); 

    while($file = readdir($dir) ) 

    { 

        if ($file == '.' || $file == '..' ) continue; 


            if ( is_dir($src . '/' . $file) ) { 
                my_copy_recurse($src . '/' . $file,$dst . '/' . $file); 
            } 
            else { 
                copy($src . '/' . $file,$dst . '/' . $file); 
            } 
    } 
    closedir($dir); 
}

Change your code to this :

function my_copy_recurse($src,$dst){
    $dir = opendir($src); 

    @mkdir($dst); 

    while($file = readdir($dir) ) 

    { 

        if ($file == '.' || $file == '..' ) continue; 


            if ( is_dir($src . '/' . $file) ) { 
                my_copy_recurse($src . '/' . $file,$dst . '/' . $file); 
            } 
            else { 
                copy($src . '/' . $file,$dst . '/' . $file); 
            } 
    } 
    closedir($dir); 
}
若水微香 2024-11-24 13:53:15

根据您的主机允许的设置,您也许可以使用 set_time_limit () 以秒为单位传递给它您希望它在超时之前花费多长时间(使用 0 表示无限)。例如:

set_time_limit(0);     //script will now run till completes

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:

set_time_limit(0);     //script will now run till completes

GoDaddy may have blocked this though so if it doesn't work try contacting them

八巷 2024-11-24 13:53:15

通过在“php.ini”文件中设置“max_execution_time = 600”对我有用。

By setting "max_execution_time = 600" in "php.ini" file worked for me.

祁梦 2024-11-24 13:53:15

吉里什的回答是不完整的。 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

涫野音 2024-11-24 13:53:14

如果您在 GoDaddy、Windows 主机上托管您的网站并使用 WordPress,迟早您将面临最大执行超时问题。我面对这个问题已经有一段时间了,在谷歌上搜索了一下,我的头很痛。如果您遇到了如下一系列相同的问题:

  1. 您托管在 GoDaddy 上,认为它们很棒,但您发现 WordPress 抛出执行时间错误,
  2. 您联系了支持人员。他们显然要么冷落你,要么要求你编写自定义的 php.ini/php5.ini。
  3. 你不知道该做什么,而你的老板却在你的头上。
  4. 您尝试获取 GoDaddy 的 ini 文件,但您做不到!
  5. 最后,您决定编写自己的 PHP.ini 文件,但要么害怕破坏某些东西,要么只是不知道从哪里开始,

这篇文章适合您>

  1. 打开你的文本编辑器。我推荐记事本++。创建以下文件:
    info.php
  1. 将 info.php 上传到您的主机的根目录。现在浏览到 http://yourhost/info.php。屏幕上加载的内容都是 PHP 配置。查找已加载的配置文件并记下其值。就我而言,它是 C:\PHP5\php.ini。我们需要在自定义 PHP5.ini 文件中包含所有这些信息,但其信息太多,无法复制和格式化,因此我们将复制 GoDaddy 的默认文件并根据需要进行编辑。

  2. 启动文本编辑器并创建以下文件:
    获取配置文件

    (将 * 替换为加载的配置文件中显示的任何路径)

  3. 打开 GoDaddy 托管管理器(是的,通过其网站)。启动文件管理器
  4. 在您的主机根目录上创建一个文件夹“baddaddy”。
  5. 选择新创建的文件夹“baddaddy”并单击权限。 使其可在网络上写入。
  6. 将文件 getconfig.php 复制到 badaddy,然后浏览到 http ://yourhost/baddaddy/getconfig.php.

  7. 一旦您在屏幕上看到“终于”字样,请返回 GoDaddy 控制面板中的文件管理器,转到 baddaddy 文件夹,您将看到那里出现一个新文件 PHP5.ini。下载此文件。这是 GoDaddy 设置的副本。

  8. 进行您需要的任何更改(只需知道您要更改什么即可,我不是 PHP 专家,因此如果您搞砸了某些内容,我不承担任何责任)。对于我的问题,我将 max_execution_time = 30 更改为 max_execution_time = 1200。

  9. 将编辑后的文件上传到应用程序的根目录,然后返回 GoDaddy 控制面板、IIS 管理,点击回收应用程序池,然后< em>等待一段时间(20 分钟)

  10. 浏览回 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:

  1. You are hosted on GoDaddy thinking they are awesome, but you find out wordpress throws execution time errors
  2. you contacted support. they clearly give you either a cold shoulder or ask you to write a custom php.ini/php5.ini.
  3. you dont know what to do and your boss is on your head.
  4. you try to get hold of GoDaddy's ini file, you cannot!
  5. Finally, you decide to write your own PHP.ini file but are either afraid of breaking something or just do not know where to start,

this post is for you>

  1. open up your text editor. I recommend notepad++. create the following file:
    info.php
  1. 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.

  2. 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)

  3. Open up GoDaddy Hosting Manager (yes via their website). Launch the File Manager
  4. On your hosting root create a folder "baddaddy".
  5. select newly created folder "baddaddy" and click permissions. Make it web writable.
  6. copy file getconfig.php to badaddy and now browse to http://yourhost/baddaddy/getconfig.php.

  7. 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.

  8. 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.

  9. 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)

  10. 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.

相思故 2024-11-24 13:53:14

要限制最大执行时间,请使用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 add set_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 add ignore_user_abort(true) at the beginning of the script to ignore it and work exactly till the end of the script.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文