php 如何增加php中的执行超时?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3829403/
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
How to increase the execution timeout in php?
提问by Aamir
How to increase transaction timeout? I want to upload videos, but large size of videos not uploaded?
如何增加事务超时?我想上传视频,但是没有上传大尺寸的视频?
It throws error The process *** exceeded the timeout of 60 seconds.
它抛出错误 The process *** exceeded the timeout of 60 seconds.
回答by Hannes
You need to change some setting in your php.ini:
您需要更改 php.ini 中的一些设置:
upload_max_filesize = 2M
;or whatever size you want
max_execution_time = 60
; also, higher if you must - sets the maximum time in seconds
Were your PHP.ini is located depends on your environment, more information: http://php.net/manual/en/ini.list.php
您的 PHP.ini 是否位于取决于您的环境,更多信息:http://php.net/manual/en/ini.list.php
回答by Christoph Strasen
You should be able to do during runtime too using
您也应该能够在运行时使用
set_time_limit(100);
set_time_limit(100);
http://php.net/manual/en/function.set-time-limit.php
http://php.net/manual/en/function.set-time-limit.php
or in your vhost-config
或在您的 vhost-config 中
php_admin_value max_execution_time 10000
php_admin_value max_execution_time 10000
Having a global execution time limit that is LOW is mostly a good idea for performance-reasons on not-so-reliable applications. So you might want to only allow those scripts to run longer that absolutely have to.
对于不太可靠的应用程序,出于性能原因,将全局执行时间限制设为 LOW 通常是一个好主意。因此,您可能只想让这些脚本运行更长的时间,而这绝对是必须的。
p.s.: Dont forget about post_max_size and upload_max_filesize (like the first answer told allready)
ps:不要忘记 post_max_size 和 upload_max_filesize (就像第一个答案告诉 allready 一样)
回答by Lynxi
To complete the answer of Hannes.
完成Hannes的回答。
You need to change some setting in your php.ini:
您需要更改 php.ini 中的一些设置:
upload_max_filesize = 2M
;or whatever size you want
max_execution_time = 60
; also, higher if you must
If someone want put in unlimited (I don't know why but if you want), you can put the twice to 0:
如果有人想放无限(我不知道为什么,但如果你想的话),你可以把两次设为 0:
You need to change some setting in your php.ini:
您需要更改 php.ini 中的一些设置:
upload_max_filesize = 0
max_execution_time = 0
And if you don't know where is your php.ini. You can do a file "name.php" in your server and put:
如果你不知道你的 php.ini 在哪里。您可以在服务器中创建一个文件“name.php”并输入:
<?php phpinfo(); ?>
And on your website, you can see the config of your php.ini and it's marked where is it.
在你的网站上,你可以看到你的 php.ini 的配置,它标有它在哪里。
Edit on 9 January 2015:
2015 年 1 月 9 日编辑:
If you can't access your php.ini, you have two more options.
如果您无法访问 php.ini,您还有两个选择。
You can set this line directly in your "name.php" file but I don't find for upload_max_filesize for this option:
你可以直接在你的“name.php”文件中设置这一行,但我没有找到这个选项的upload_max_filesize:
set_time_limit(0);
Or in ".htaccess"
或者在“.htaccess”中
php_value upload_max_filesize 0
php_value max_execution_time 0
回答by Komang
if what you need to do is specific only for 1 or 2 pages i suggest to use set_time_limitso it did not affect the whole application.
如果您需要做的仅针对 1 或 2 页,我建议使用set_time_limit这样它就不会影响整个应用程序。
set_time_limit(some_values);
but ofcourse these 2 values (post_max_size & upload_max_filesize) are subject to investigate.
但当然这 2 个值(post_max_size 和 upload_max_filesize)有待调查。
you either can set it via ini_setfunction
你可以通过ini_set函数设置它
ini_set('post_max_size','20M');
ini_set('upload_max_filesize','2M');
or directly in php.ini file like response above by Hannes, or even set it iin .htaccess like below
或直接在 php.ini 文件中,如 Hannes 上面的响应,甚至将其设置在 .htaccess 中,如下所示
php_value upload_max_filesize 2M
php_value post_max_size 20M
回答by Tomasz Kowalczyk
As an addition to above answers, you may use set_time_limit()
function:
作为上述答案的补充,您可以使用set_time_limit()
功能:
http://php.net/manual/en/function.set-time-limit.php
http://php.net/manual/en/function.set-time-limit.php
passing 0
as an argument will make your script run with no time limit.
0
作为参数传递将使您的脚本无时间限制地运行。
回答by thanatoid
You had a typo: ini_set('max_input_time','200M') - value set needs to be an int, like ini_set('max_input_time','200')
你有一个错字:ini_set('max_input_time','200M') - 值集需要是一个 int,像 ini_set('max_input_time','200')
回答by Michael
If you happen to be using Microsoft IISserver, in addition to the php.inisettings mentioned by others, you may need to increase the execution timeout settings for the PHP FastCGI application in the IIS Server Manager:
如果你碰巧使用的是微软IIS服务器,除了其他人提到的php.ini设置外,你可能还需要在IIS服务器管理器中增加PHP FastCGI应用的执行超时设置:
Step 1) Open the IIS Server Manager (usually under Server Managerin the Start Menu, then Tools/ Internet Information Services (IIS) Manager).
步骤 1) 打开 IIS 服务器管理器(通常在开始菜单中的服务器管理器下,然后是工具/ Internet 信息服务 (IIS) 管理器)。
Step 2) Click on the main connection (not specific to any particular domain).
步骤 2) 单击主连接(不特定于任何特定域)。
Step 3) Under the IISsection, find FastCGI Settings(shown below).
步骤 3) 在IIS部分下,找到FastCGI Settings(如下所示)。
Step 4) Therein, right-click the PHP application and select Edit....
步骤 4) 其中,右键单击 PHP 应用程序并选择Edit...。
Step 5) Check the timeouts (shown below).
步骤 5)检查超时(如下所示)。
In my case, the default timeouts here were 70 and 90 seconds; the former of which was causing a 500 Internal Server Erroron PHP scripts that took longer than 70 seconds.
就我而言,这里的默认超时是 70 和 90 秒;前者导致PHP 脚本出现500 内部服务器错误,耗时超过 70 秒。
回答by Ashfaq Muhammad
First check the php.ini
file path by phpinfo()
; and then changed PHP.INI
params:
首先检查php.ini
文件路径phpinfo()
;然后更改PHP.INI
参数:
upload_max_filesize = 1000M
memory_limit = 1500M
post_max_size = 1500M
max_execution_time = 30
restarted Apache
重新启动 Apache
set_time_limit(0); // safe_mode is off
ini_set('max_execution_time', 500); //500 seconds
Note: you can also use command to find php.ini
in Linux
注意:您也可以php.ini
在 Linux 中使用命令来查找
locate `php.ini`
回答by Paul Feakins
I know you are specifically asking about the PHP timeout, but what no one else seems to have mentioned is that there can also be a timeout on the webserver and it can look very similar to the PHP timeout.
我知道您专门询问 PHP 超时,但似乎没有其他人提到的是,网络服务器上也可能存在超时,它看起来与 PHP 超时非常相似。
So if you have tried:
因此,如果您尝试过:
- Increasing the timeout in php.ini by adding a line: max_execution_time = {number of seconds i.e. 60 for one minute}
- Increasing the timeout in your script itself by adding: ini_set('max_execution_time','{number of seconds i.e. 60 for one minute}');
- 通过添加一行来增加 php.ini 中的超时时间: max_execution_time = {number of seconds ie 60 for one minute}
- 通过添加以下内容来增加脚本本身的超时: ini_set('max_execution_time','{number of seconds ie 60 for one minute}');
And you have checked with the phpinfo() function that max_execution_time has indeed be increased, then you might want to try adding this to .htaccess which will make sure Apache itself does not time out:
并且您已经使用 phpinfo() 函数检查了 max_execution_time 确实增加了,然后您可能想尝试将其添加到 .htaccess 中,这将确保 Apache 本身不会超时:
RewriteRule .* - [E=noabort:1]
RewriteRule .* - [E=noconntimeout:1]
More info here: https://www.antropy.co.uk/blog/php-script-keeps-timing-out-despite-ini-set/
更多信息在这里:https: //www.antropy.co.uk/blog/php-script-keeps-timing-out-despite-ini-set/
回答by TV-C-15
Test if you are is safe mode - if not - set the time limit (Local Value) to what you want:
测试您是否处于安全模式 - 如果不是 - 将时间限制(本地值)设置为您想要的:
if(!ini_get('safe_mode')){
echo "safe mode off";
set_time_limit(180);// seconds
phpinfo();// see 'max_execution_time'
}
*You cannot set time limit this way if safe mode 'on'.
*如果安全模式“开启”,您不能以这种方式设置时间限制。