在 PHP 中增加 max_execution_time ?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8744107/
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
Increase max_execution_time in PHP?
提问by Chithri Ajay
I'm trying to upload large files to my server (my server support post_max_size
192mb and max_execution_time
600 sec). When I upload 100mb files execution will stop after 600 sec so files are not uploaded to the server. How can I increase max_execution_time
in PHP (only for the file uploading process)? I have tried:
我正在尝试将大文件上传到我的服务器(我的服务器支持post_max_size
192mb 和max_execution_time
600 秒)。当我上传 100mb 文件时,执行将在 600 秒后停止,因此文件不会上传到服务器。如何增加max_execution_time
PHP(仅用于文件上传过程)?我试过了:
ini_set ( 'max_execution_time', 1200);
if(move_uploaded_file($_FILES['Video']['tmp_name'],$tmppath)) {
// ...
}
Any ideas how I can overcome this?
我有什么想法可以克服这个问题吗?
回答by Jeremy Harris
Add this to an htaccess file:
将此添加到 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>
Read more about those settings at:
在以下位置阅读有关这些设置的更多信息:
回答by bardiir
Theres a setting max_input_time
(on Apache) for many webservers that defines how long they will wait for post data, regardless of the size. If this time runs out the connection is closed without even touching the php.
max_input_time
许多网络服务器都有一个设置(在 Apache 上),用于定义无论大小如何,它们都将等待发布数据的时间。如果这个时间用完,连接就关闭了,甚至不接触 php.ini 文件。
So your problem is not necessarily solvable with php only but you will need to change the server settings too.
所以你的问题不一定只能用 php 解决,但你也需要更改服务器设置。
回答by HMagdy
if you have access to WHM you can follow these steps:
如果您有权访问 WHM,您可以按照以下步骤操作:
At some point in time, you'll probably need to adjust PHP's configuration options. Instead of manually editing the PHP.ini file, you can do so from within WHM.
在某个时间点,您可能需要调整 PHP 的配置选项。无需手动编辑 PHP.ini 文件,您可以在 WHM 中进行。
1) Find the Service Configuration menu.
1) 找到服务配置菜单。
2) Click PHP Configuration Editor.
2) 单击 PHP 配置编辑器。
This editor has two modes -- Basic and Advanced. In order to have access to the fullest range of options, you will need to use the advanced mode. It is available by clicking the button at the top of the page.
这个编辑器有两种模式——基本和高级。为了获得最全面的选项,您需要使用高级模式。单击页面顶部的按钮可以使用它。
We recommend that you wait to change any of the advanced settings until you're certain you know what you're doing. If ever you'd like more information about a setting, clicking a link in the Section column will take you to the PHP documentation. The first option in Basic Mode is upload_max_filesize, which limits the maximum size of a file uploaded through PHP. This option will affect the attachment or upload system of a wide variety of software likely to be run on your server, including Joomla and vBulletin. You'll probably want to change this to something quite a bit higher than the default. Specify the size in megabytes by using a number followed by M. You will rarely need to change the include_path from the default. In addition to limiting the max upload size, you can also turn off file upload altogether with the file_uploads setting. Some PHP programmers have a bad habit of using shorthand tags, which aren't enabled on many servers. This means their scripts will not function. Enable asp_tags if you encounter any scripts that require that kind of tag.
我们建议您等待更改任何高级设置,直到您确定自己知道自己在做什么。如果您想了解有关设置的更多信息,单击“部分”列中的链接会将您带到 PHP 文档。基本模式中的第一个选项是upload_max_filesize,它限制了通过PHP 上传的文件的最大大小。此选项将影响可能在您的服务器上运行的各种软件的附件或上传系统,包括 Joomla 和 vBulletin。您可能希望将其更改为比默认值高很多的值。使用数字后跟 M 来指定大小(以兆字节为单位)。您很少需要更改默认的 include_path。除了限制最大上传大小,您还可以使用 file_uploads 设置完全关闭文件上传。一些 PHP 程序员有使用速记标签的坏习惯,许多服务器上都没有启用这些标签。这意味着他们的脚本将无法运行。如果您遇到任何需要这种标记的脚本,请启用 asp_tags。
With memory_limit, you can impose a limit on the amount of memory a particular PHP script can use at any given time. Enabling register_globals is not recommended unless absolutely necessary. It's the source of many security problems and will be removed completely when PHP 6 is released. The max_execution_time setting prevents poorly-written scripts from tying up the server. By default, this option is set to 30 seconds; don't put this too high, or your server's performance may suffer. Similarly, max_input_time places a limit on how long a script is allowed to parse input data, such as forms and file uploads.
使用 memory_limit,您可以对特定 PHP 脚本在任何给定时间可以使用的内存量施加限制。除非绝对必要,否则不建议启用 register_globals。它是许多安全问题的根源,将在 PHP 6 发布时完全删除。max_execution_time 设置可防止编写不当的脚本占用服务器。默认情况下,此选项设置为 30 秒;不要把这个设置得太高,否则你的服务器的性能可能会受到影响。类似地,max_input_time 对允许脚本解析输入数据(例如表单和文件上传)的时间设置了限制。
With enable_dl, all users can include PHP extensions at will. This represents a potential security breach, so you should turn this off unless absolutely necessary. safe_mode is another PHP option that will be removed with the release of PHP 6. It's largely ineffectual, and should probably be left off. The last option, session.save_path, controls where PHP's sessions are saved. The default should be okay for most purposes.
使用 enable_dl,所有用户都可以随意包含 PHP 扩展。这代表潜在的安全漏洞,因此除非绝对必要,否则您应该关闭它。safe_mode 是另一个 PHP 选项,它将随着 PHP 6 的发布而被删除。它在很大程度上是无效的,应该被取消。最后一个选项 session.save_path 控制 PHP 会话的保存位置。对于大多数用途,默认值应该没问题。
If you wish to change this option, you'll need to click here for the text field to appear.
如果您想更改此选项,则需要单击此处以显示文本字段。
3) When finished, click Save.
3) 完成后,单击保存。
The php.ini file has been written automatically.
php.ini 文件已自动写入。
You now know how to configure PHP from within WHM.
您现在知道如何在 WHM 中配置 PHP。
回答by Radames E. Hernandez
Is very easy, this work for me:
很容易,这对我有用:
PHP:
PHP:
set_time_limit(300); // Time in seconds, max_execution_time
Here is the PHP documentation
这是 PHP文档
回答by Abhinav Kumar Singh
For increasing execution time and file size, you need to mention below values in your .htaccess file. It will work.
为了增加执行时间和文件大小,您需要在 .htaccess 文件中提及以下值。它会起作用。
php_value upload_max_filesize 80M
php_value post_max_size 80M
php_value max_input_time 18000
php_value max_execution_time 18000