如何增加交易超时时间?我想上传视频,但是没有上传大尺寸的视频?
引发错误 The process *** exceeded the timeout of 60 seconds.
如何增加交易超时时间?我想上传视频,但是没有上传大尺寸的视频?
引发错误 The process *** exceeded the timeout of 60 seconds.
Answers:
您需要在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
您的PHP.ini所在的位置取决于您的环境,更多信息:http ://php.net/manual/zh/ini.list.php
您也应该能够在运行时使用
set_time_limit(100);
http://php.net/manual/zh/function.set-time-limit.php
或在您的vhost-config中
php_admin_value max_execution_time 10000
对于不太可靠的应用程序,由于性能原因,将全局执行时间限制设为LOW通常是一个好主意。因此,您可能只想允许那些脚本绝对必要地运行更长的时间。
ps:别忘了post_max_size和upload_max_filesize(就像第一个答案告诉allready一样)
完成汉尼斯的答案。
您需要在php.ini中更改一些设置:
upload_max_filesize = 2M
;or whatever size you want
max_execution_time = 60
; also, higher if you must
如果有人想无限输入(我不知道为什么,但是如果您愿意),可以将时间设置为0:
您需要在php.ini中更改一些设置:
upload_max_filesize = 0
max_execution_time = 0
如果您不知道php.ini在哪里。您可以在服务器中执行文件“ name.php”并放入:
<?php phpinfo(); ?>
在您的网站上,您可以看到php.ini的配置,并标记在哪里。
如果您无法访问php.ini,则还有两个选择。
您可以直接在“ name.php”文件中设置此行,但找不到此选项的upload_max_filesize:
set_time_limit(0);
或在“ .htaccess”中
php_value upload_max_filesize 0
php_value max_execution_time 0
如果您需要做的仅是1或2页,我建议使用set_time_limit,这样就不会影响整个应用程序。
set_time_limit(some_values);
但是,当然这两个值(post_max_size和upload_max_filesize)有待调查。
您可以通过ini_set函数进行设置
ini_set('post_max_size','20M');
ini_set('upload_max_filesize','2M');
或直接在php.ini文件中(例如Hannes的响应),甚至将其设置在.htaccess中,如下所示
php_value upload_max_filesize 2M
php_value post_max_size 20M
除了上述答案外,您还可以使用set_time_limit()
函数:
http://php.net/manual/zh/function.set-time-limit.php
0
作为参数传递将使您的脚本无时间限制地运行。
如果您正巧使用Microsoft IIS服务器,除了其他人提到的php.ini设置,您可能需要增加IIS服务器管理器中PHP FastCGI应用程序的执行超时设置:
步骤1)打开IIS服务器管理器(通常在“开始”菜单的“ 服务器管理器”下,然后是“ 工具 / Internet信息服务(IIS)管理器”)。
步骤2)单击主连接(不特定于任何特定域)。
步骤3)在IIS部分下,找到FastCGI设置(如下所示)。
步骤4)其中,右击PHP应用程序,然后选择编辑...。
步骤5)检查超时(如下所示)。
就我而言,这里的默认超时是70秒和90秒。前者导致PHP脚本出现500个内部服务器错误,耗时超过70秒。
我知道您是在特别询问有关PHP超时的问题,但是似乎没有人提到过Web服务器上也可能存在超时,并且它看起来与PHP超时非常相似。
因此,如果您尝试过:
并且您已经使用phpinfo()函数检查了max_execution_time确实已增加,然后您可能想要尝试将其添加到.htaccess中,以确保Apache本身不会超时:
RewriteRule .* - [E=noabort:1]
RewriteRule .* - [E=noconntimeout:1]
此处提供更多信息:https : //www.antropy.co.uk/blog/php-script-keeps-timing-out-despite-ini-set/
首先通过检查php.ini
文件路径phpinfo()
;然后更改PHP.INI
参数:
upload_max_filesize = 1000M
memory_limit = 1500M
post_max_size = 1500M
max_execution_time = 30
重新启动Apache
set_time_limit(0); // safe_mode is off
ini_set('max_execution_time', 500); //500 seconds
注意:您也可以使用命令php.ini
在Linux中查找
locate `php.ini`
可选的:如果您设置了有关php.ini的配置,但仍然无法上传
-这是检查错误代码的php函数
$error_type = [];
$error_type[0] = "There is no error";
$error_type[1] = "The uploaded file exceeds the upload_max_filesize directive in php.ini.";
$error_type[2] = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.";
$error_type[3] = "The uploaded file was only partially uploaded.";
$error_type[4] = "No file was uploaded.";
//$error_type["5"] = "";
$error_type[6] = "Missing a temporary folder. Introduced in PHP 5.0.3.";
$error_type[7] = "Failed to write file to disk. Introduced in PHP 5.1.0.";
$error_type[8] = "A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help. Introduced in PHP 5.2.0.";
//------------------------------
//--> show msg error.
$status_code = $_FILES["uploadfile"]["error"];
if($status_code != 0){
echo $error_type[$status_code];
exit;
}
要真正增加时间限制,我更喜欢先获取当前值。set_time_limit
并不总是增加时间限制。如果当前值(例如来自php.ini
或先前设置的值)大于当前调用中使用的值set_time_limit
,它将降低时间限制!
那么,像这样的小助手呢?
/**
* @param int $seconds Time in seconds
* @return bool
*/
function increase_time_limit(int $seconds): bool
{
return set_time_limit(max(
ini_get('max_execution_time'), $seconds
));
}
// somewhere else in your code
increase_time_limit(180);