php post请求的大小限制是多少?

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

What is the size limit of a post request?

phpinternet-explorerhttppost

提问by invertedSpear

Sorry if this is duplicate,I would think it would be but couldn't find anything.

对不起,如果这是重复的,我认为它会是但找不到任何东西。

I have a flex application that I am posting data back to a php/mysql server via IE. I haven't run into any problems yet, but knowing this ahead of time might save me a bunch of frustration and work. Is there a size limit to posting data via http?

我有一个 flex 应用程序,我通过 IE 将数据发布回 php/mysql 服务器。我还没有遇到任何问题,但提前知道这一点可能会为我节省很多挫折和工作。通过 http 发布数据是否有大小限制?

This article says no: http://www.netlobo.com/ie_form_submit.html

这篇文章说不:http: //www.netlobo.com/ie_form_submit.html

This discussion says yes: http://bytes.com/topic/php/answers/538226-what-maximum-limit-using-post-method

这个讨论说是的:http: //bytes.com/topic/php/answers/538226-what-maximum-limit-using-post-method

And it all goes back and forth what I'm able to find online. So pleaselimit answers to personally tested/verified numbers.

这一切都在我能在网上找到的东西来回循环。因此,限制对个人测试/验证数字的回答。

I am wanting to post back an XML string that can be quite large (say up to 5mb).

我想回发一个可能很大的 XML 字符串(比如高达 5mb)。

If it makes any difference: browser will always be IE (our product requires it), post is coming from and httpService in flex, web server is php, DB is mySql.

如果有什么不同:浏览器将始终是 IE(我们的产品需要它),post 来自 flex 中的 httpService,Web 服务器是 php,DB 是 mySql。

采纳答案by inkedmn

It depends on a server configuration. If you're working with PHP under Linux or similar, you can control it using .htaccess configuration file, like so:

这取决于服务器配置。如果您在 Linux 或类似环境下使用 PHP,则可以使用 .htaccess 配置文件来控制它,如下所示:

#set max post size
php_value post_max_size 20M

And, yes, I can personally attest to the fact that this works :)

而且,是的,我可以亲自证明这是有效的:)

If you're using IIS, I don't have any idea how you'd set this particular value.

如果您使用的是 IIS,我不知道您将如何设置此特定值。

回答by David

The url portion of a request (GET and POST) can be limited by both the browser and the server - generally the safe size is 2KB as there are almost no browsers or servers that use a smaller limit.

请求的 url 部分(GET 和 POST)可以受到浏览器和服务器的限制——通常安全大小是 2KB,因为几乎没有浏览器或服务器使用更小的限制。

The body of a request (POST) is normally* limited by the server on a byte size basis in order to prevent a type of DoS attack (note that this means character escaping can increase the byte size of the body). The most common server setting is 10MB, though all popular servers allow this to be increased or decreased via a setting file or panel.

请求的主体 (POST) 通常*由服务器基于字节大小进行限制,以防止某种 DoS 攻击(请注意,这意味着字符转义会增加主体的字节大小)。最常见的服务器设置是 10MB,但所有流行的服务器都允许通过设置文件或面板增加或减少它。

*Some exceptions exist with older cell phone or other small device browsers - in those cases it is more a function of heap space reserved for this purpose on the device then anything else.

*旧手机或其他小型设备浏览器存在一些例外情况 - 在这些情况下,它更多地是设备上为此目的保留的堆空间功能,而不是其他任何功能。

回答by Nikolay Ivanov

Also, in PHP.INI file there is a setting:

此外,在 PHP.INI 文件中有一个设置:

max_input_vars

which in my version of PHP: 5.4.16 defaults to 1000.

在我的 PHP 版本中:5.4.16 默认为 1000。

From the manual: "How many input variables may be accepted (limit is applied to $_GET, $_POST and $_COOKIE superglobal separately)"

来自手册:“可以接受多少个输入变量(限制分别应用于 $_GET、$_POST 和 $_COOKIE 超全局变量)”

Ref.: http://www.php.net/manual/en/info.configuration.php#ini.max-input-vars

参考:http: //www.php.net/manual/en/info.configuration.php#ini.max-input-vars

回答by Nilesh Chourasia

You can post large amount of data by setting php.ini variable: max_input_varsDefault size of this variable is 1000 but if you want to sent large amount of data you have to increase the size accordingly. If you can't set the size from ini_set you have to do it through htaccessor by doing changes into php.ini file directly.

您可以通过设置 php.ini 变量来发布大量数据:max_input_vars此变量的默认大小为 1000,但如果您想发送大量数据,则必须相应地增加大小。如果您不能从 ini_set 设置大小,则必须通过htaccess或直接更改 php.ini 文件来完成。

max_input_vars  2500
memory_limit    256M

回答by ChrisDeDavidMindflowAU

As David pointed out, I would go with KB in most cases.

正如大卫所指出的,在大多数情况下我会选择 KB。

php_value post_max_size 2KB

Note: my form is simple, just a few text boxes, not long text.

注意:我的表格很简单,就是几个文本框,不是长文本。

回答by ChrisH

It is up to the http server to decide if there is a limit. The product I work on allows the admin to configure the limit.

由 http 服务器决定是否有限制。我工作的产品允许管理员配置限制。

回答by Muhammad Ashfaq

By default, the post request has maximum size of 8mb. But you can modify it according to your requirements. The modification can be done by opening php.ini file (php configuration setting).

默认情况下,post 请求的最大大小为 8mb。但是你可以根据你的要求修改它。修改可以通过打开 php.ini 文件(php 配置设置)来完成。

Find

post_max_size=8M  //for me, that was on line:771

replace 8 according to your requirements.

根据您的要求更换8个。

回答by harpej

One of the best solutions for this, you do not use multiple or more than 1,000 input fields. You can concatenate multiple inputs with any special character, for ex. @.

对此的最佳解决方案之一是,您不要使用多个或超过 1,000 个输入字段。您可以使用任何特殊字符连接多个输入,例如。@.

See this:

看到这个:

<input type='text' name='hs1' id='hs1'>
<input type='text' name='hs2' id='hs2'>
<input type='text' name='hs3' id='hs3'>
<input type='text' name='hs4' id='hs4'>
<input type='text' name='hs5' id='hs5'>

<input type='hidden' name='hd' id='hd'>

Using any script (JavaScript or JScript),

使用任何脚本(JavaScript 或 JScript),

document.getElementById("hd").value = document.getElementById("hs1").value+"@"+document.getElementById("hs2").value+"@"+document.getElementById("hs3").value+"@"+document.getElementById("hs4").value+"@"+document.getElementById("hs5").value

With this, you will bypass the max_input_varsissue. If you increase max_input_varsin the php.ini file, that is harmful to the server because it uses more server cache memory, and this can sometimes crash the server.

有了这个,你将绕过这个max_input_vars问题。如果你增加max_input_varsphp.ini 文件,那对服务器是有害的,因为它使用了更多的服务器缓存内存,这有时会导致服务器崩溃。

回答by Mira Nedved

For developers who cannot change php configuration because of the webhosting.(My settings 256MB max size, 1000 max variables)

对于由于虚拟主机而无法更改 php 配置的开发人员。(我的设置最大大小为 256MB,最大变量为 1000)

I got the same issue that just 2 out of 5 big data objects (associative arrays) with substructures were received on the server side.

我遇到了同样的问题,在服务器端收到了 5 个带有子结构的大数据对象(关联数组)中的 2 个。

I find out that the whole substructure is being "flattened" in the post request. So, one object becomes a hundreds of literal variables. At the end, instead of 5 Object variables it is in reality sending dozens of hundreds elementar variables.

我发现整个子结构在发布请求中被“扁平化”。因此,一个对象变成了数百个文字变量。最后,实际上发送了数十个数百个基本变量,而不是 5 个对象变量。

Solutionin this case is to serialize each of the substructuresinto String. Then it is received on the server as 5 String variables. Example: {variable1:JSON.stringify(myDataObject1),variable2:JSON.stringify(myDataObject2)...}

这种情况下的解决方案是将每个子结构序列化为字符串。然后它作为 5 个字符串变量在服务器上接收。例子: {variable1:JSON.stringify(myDataObject1),variable2:JSON.stringify(myDataObject2)...}