【问题标题】:Set maximum execution time in MYSQL / PHP在 MYSQL/PHP 中设置最大执行时间
【发布时间】:2013-08-17 17:11:11
【问题描述】:

我有一个包含大约 48,000 个子项 (~50MB) 的 XML 文档。我运行一个 INSERT MYSQL 查询,为这些孩子中的每一个创建新条目。问题是由于它的大小,它需要很多时间。执行后我收到这个

Fatal error: Maximum execution time of 60 seconds exceeded in /path/test.php on line 18

如何将最大执行时间设置为无限制?

谢谢

【问题讨论】:

标签: php mysql execution


【解决方案1】:

您可以通过在您的 php 代码中设置 set_time_limit 来实现(设置为 0 表示无限制)

set_time_limit(0);

或者直接在你的php.ini中修改max_execution_time的值

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

; Maximum execution time of each script, in seconds
; http://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 120  

或者用 ini_set() 改变它

ini_set('max_execution_time', 120); //120 seconds

但请注意,对于第 3 个选项:

最大执行时间

在安全运行时,您不能使用 ini_set() 更改此设置 模式。唯一的解决方法是关闭安全模式或更改 php.ini 中的时间限制。

来源www.php.net

【讨论】:

  • 是否可以在 mysql 配置中进行设置?我没有使用 php。
【解决方案2】:

把它放在脚本的顶部:

ini_set('max_execution_time', 300);

5 分钟就可以了。

【讨论】:

  • 如果我将它设置为 0,它会花费尽可能多的时间吗?
  • 它将设置为无限制。
【解决方案3】:

您可以在应用程序的开头使用 ini_set。

ini_set('max_execution_time', *number of seconds here*); //300 seconds = 5 minutes

【讨论】:

    【解决方案4】:

    您可以在 MYSQL / PHP 中设置最大执行时间。就是这么简单。

    要在单个 PHP 文件中设置最长执行时间,请将此代码放在第一个打开的 php 标记之后。

    ini_set(‘max_execution_time’, 0)
    

    在 php.ini 文件中设置最大执行时间。您可以根据自己的需要进行设置。

    max_execution_time=360 //360 seconds = 6 minutes
    

    在 htaccess 文件中设置最大执行时间。

    php_value max_execution_time 0
    

    你也可以read step by step here。

    【讨论】:

      【解决方案5】:

      Apache Web Server 的最长执行时间是 300 秒(5 分钟),所以如果你的脚本很长,你必须选择

      1. 您的脚本最多可以执行 5 分钟 打开 php.ini 文件并更改 max_execution_time = (seconds) 例如到max_execution_time = 300

      2.如果您的脚本需要超过 5 分钟,您应该首先更改 Httpd.conf 文件(Apache 配置文件)

      TimeOut (number of seconds you want)
      

      还有在 php.ini max_execution_time = (number of seconds you want)

      【讨论】:

        猜你喜欢
        • 2010-09-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-19
        • 2011-07-04
        相关资源
        最近更新 更多