php 致命错误:超过了最长 30 秒的执行时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5164930/
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:00:08  来源:igfitidea点击:

Fatal error: Maximum execution time of 30 seconds exceeded

phpjson

提问by Harsha M V

I am downloading a JSON file from an online source and and when it runs through the loop I am getting this error:

我正在从在线源下载一个 JSON 文件,当它运行循环时,我收到此错误:

Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\temp\fetch.php on line 24

致命错误:在第 24 行的 C:\wamp\www\temp\fetch.php 中超出了 30 秒的最大执行时间

回答by Michiel Pater

Your loop might be endless. If it is not, you could extend the maximum execution time like this:

你的循环可能是无止境的。如果不是,您可以像这样延长最大执行时间:

ini_set('max_execution_time', 300); //300 seconds = 5 minutes

and

set_time_limit(300);

can be used to temporarily extend the time limit.

可用于临时延长时间限制。

回答by Güilber J. Castillo

I had the same problem and solved it by changing the value for the param max_execution_timein php.ini, like this:

我遇到了同样的问题并通过更改参数max_execution_timein的值来解决它php.ini,如下所示:

max_execution_time = 360      ; Maximum execution time of each script, in seconds (I CHANGED THIS VALUE)
max_input_time = 120          ; Maximum amount of time each script may spend parsing request data
;max_input_nesting_level = 64 ; Maximum input variable nesting level
memory_limit = 128M           ; Maximum amount of memory a script may consume (128MB by default)

I hope this could help you.

我希望这可以帮助你。

回答by Massa

All the answers above are correct, but I use a simple way to avoid it in some cases.

以上所有答案都是正确的,但我在某些情况下使用了一种简单的方法来避免它。

Just put this command in the begining of your script:

只需将此命令放在脚本的开头:

set_time_limit(0);

回答by Fahim Hossain

I ran into this problem while upgrading to WordPress 4.0. By default WordPress limits the maximum execution time to 30 seconds.

我在升级到WordPress 4.0时遇到了这个问题。默认情况下,WordPress 将最长执行时间限制为 30 秒。

Add the following code to your .htaccessfile on your root directory of your WordPress Installationto over-ride the default.

将以下代码添加到WordPress 安装根目录下的.htaccess文件中,以覆盖默认值。

php_value max_execution_time 300  //where 300 = 300 seconds = 5 minutes

回答by Jamil Ahmed

Edit php.ini

编辑php.ini

Find this line:

找到这一行:

max_execution_time

Change its value to 300:

将其值更改为 300:

max_execution_time = 300

300 means 5 minutes of execution time for the http request.

300 表示 http 请求的执行时间为 5 分钟。

回答by tlenss

Your script is timing out. Take a look at the set_time_limit()function to up the execution time. Or profile the script to make it run faster :)

您的脚本超时。查看set_time_limit()函数以延长执行时间。或者分析脚本以使其运行得更快:)

回答by Nassim

if all the above didn't work for you then add an .htaccessfile to the directory where your script is located and put this inside

如果以上所有方法都不适合您,则将.htaccess文件添加到脚本所在的目录并将其放入

<IfModule mod_php5.c>
php_value post_max_size 200M
php_value upload_max_filesize 200M
php_value memory_limit 300M
php_value max_execution_time 259200
php_value max_input_time 259200
php_value session.gc_maxlifetime 1200
</IfModule>

this was the way I solved my problem , neither ini_set('max_execution_time', 86400);nor set_time_limit(86400)solved my problem , but the .htaccess method did.

这是我解决问题的方式,既没有ini_set('max_execution_time', 86400);也没有set_time_limit(86400)解决我的问题,但是 .htaccess 方法做到了。

回答by KarSho

We can solve this problem in 3 different ways.

我们可以通过 3 种不同的方式来解决这个问题。

1) Using php.ini file

1) 使用 php.ini 文件

2) Using .htaccess file

2) 使用 .htaccess 文件

3) Using Wp-config.php file ( for Wordpress )

3)使用 Wp-config.php 文件(用于 Wordpress)

回答by Mwangi Thiga

You can remove the restriction by seting it to zero by adding this line at the top of your script:

您可以通过在脚本顶部添加以下行将其设置为零来删除限制:

<?php ini_set('max_execution_time', 0); ?>

回答by Suchit kumar

Follow the path /etc/php5(your php version)/apache2/php.ini.

按照路径/etc/php5(your php version)/apache2/php.ini

Open it and set the value of max_execution_timeto a desired one.

打开它并将 的值设置max_execution_time为所需的值。