在 MYSQL/PHP 中设置最大执行时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18253934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:14:38  来源:igfitidea点击:

Set maximum execution time in MYSQL / PHP

phpmysqlexecution

提问by Harris Geo

I have an XML document that has around 48,000 children (~50MB). I run an INSERT MYSQL query that makes new entries for each one of these children. The problem is that it takes a lot of time due to its size. After it is executed I receive this

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

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

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

How do I set the Maximum execution time to be unlimited?

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

Thanks

谢谢

采纳答案by Imane Fateh

You can make it by setting set_time_limit in you php code (set to 0 for no limit)

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

set_time_limit(0);

Or modifying the value of max_execution_time directly in your php.ini

或者直接在你的 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  

Or changing it with ini_set()

或者用 ini_set() 改变它

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

but note that for this 3rd option :

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

max_execution_time

You can not change this setting with ini_set() when running in safe mode. The only workaround is to turn off safe mode or by changing the time limit in the php.ini.

最大执行时间

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

Source www.php.net

来源www.php.net

回答by Rinku

You can Set maximum execution time in MYSQL / PHP. it's so easy.

您可以在 MYSQL/PHP 中设置最大执行时间。它是如此容易。

To set maximum execution time in single PHP file, place this code just after your first opening php tag.

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

ini_set(‘max_execution_time', 0)

To set maximum execution time in php.ini file. You can set as per your require.

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

max_execution_time=360 //360 seconds = 6 minutes

To set maximum execution time in htaccess file.

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

php_value max_execution_time 0

You can also read step by step here.

您也可以在此处逐步阅读

回答by user1324491

maximum execution time for Apache Web Server is 300 seconds (5 min), so if your script is very long you have to options

Apache Web Server 的最大执行时间为 300 秒(5 分钟),因此如果您的脚本很长,您必须选择

  1. your script can be executed on most 5 minutes open php.ini file and chanage max_execution_time = (seconds)for example to max_execution_time = 300
  1. 您的脚本可以在最多 5 分钟的时间内执行,打开 php.ini 文件并更改 max_execution_time = (seconds)例如max_execution_time = 300

2.if you scripts need mor than 5 minutes you should first change Httpd.conf file (Apache config file)

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

TimeOut (number of seconds you want)

and also in php.ini max_execution_time = (number of seconds you want)

也在 php.ini 中 max_execution_time = (number of seconds you want)

回答by Tdelang

Put this at the top of your script:

将其放在脚本的顶部:

ini_set('max_execution_time', 300);

That'll make it 5 minutes.

这样5分钟就搞定了。

回答by Nick Shears

You can use the ini_set at the start of your application.

您可以在应用程序开始时使用 ini_set。

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