PHP/Apache/AJAX - POST 限制?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9691057/
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
PHP/Apache/AJAX - POST limit?
提问by James Nine
I'm trying to send POST data that is 2 million characters big (non-binary string) via ajax (jQuery) and it always comes up as blank on the PHP side. Here is my code:
我正在尝试通过 ajax (jQuery) 发送 200 万个字符大(非二进制字符串)的 POST 数据,它在 PHP 端总是显示为空白。这是我的代码:
var string = "<data string that is 2M chars long>";
$.ajax({
cache: false,
type: 'POST',
url: 'data.php',
data: {'data_string': string}
});
On the PHP side, I get the following error message (when trying to retrieve data from $_POST['data_string']
):
在 PHP 端,我收到以下错误消息(尝试从 检索数据时$_POST['data_string']
):
Notice: Undefined index: data_string in data.php on line ...
I've checked the post_max_size
in php.ini, and it's set at 256M which should be more than enough? I'm stumped and not sure what I'm doing wrong...
我查过post_max_size
php.ini,设置为256M,应该够用了吧?我很难过,不知道我做错了什么......
EDIT: If I make "string"
a small amount of data (e.g. var string = 'test'
) then $_POST["data_string"]
returns test
, as expected. So I'm wondering if there's some sort of data limit I'm reaching in Apache2, PHP or the browser itself? I'm using Google Chrome 17.0.963.79
编辑:如果我制作"string"
少量数据(例如var string = 'test'
),则按预期$_POST["data_string"]
返回test
。所以我想知道我是否在 Apache2、PHP 或浏览器本身中达到了某种数据限制?我使用的是谷歌浏览器 17.0.963.79
EDIT2: memory_limit = 256M
in php.ini
EDIT2:memory_limit = 256M
在 php.ini
EDIT3: max_input_time = -1
in php.ini
EDIT3:max_input_time = -1
在 php.ini
EDIT4: var_dump($_POST) returns Array(0)
EDIT4: var_dump($_POST) 返回 Array(0)
EDIT5: running the latest stable version of PHP5 on debian squeeze: PHP 5.3.3-7+squeeze8 with Suhosin-Patch (cli) (built: Feb 10 2012 14:12:26)
EDIT5:在 debian Squeeze 上运行最新稳定版本的 PHP5:PHP 5.3.3-7+squeeze8 with Suhosin-Patch (cli)(构建时间:2012 年 2 月 10 日 14:12:26)
回答by regilero
You'll have to check the limits parameters on all items between you and the server. Quite hard for proxy servers if any, but at least you can check:
您必须检查您和服务器之间所有项目的限制参数。如果有的话,对于代理服务器来说相当困难,但至少您可以检查:
Apache:
阿帕奇:
- LimitRequestBody, around 2Gb by default, maybe greater for 64bits, check error logs for details.
- LimitRequestBody,默认情况下约为 2Gb,对于 64 位可能更大,请查看错误日志以获取详细信息。
PHP:
PHP:
- post_max_sizewhich is directly related to the POST size
- upload_max_filesizewhich may be unrelated, not sure
- max_input_time, if the POSt takes too long
- max_input_nesting_levelif your data is an array with a lot of sublevels
- max_execution_time, but quite sure it's not that
- memory_limit, as you may reach a size exceding the subprocess allowed memory
- max_input_vars, if your data array has many elements
- post_max_size与 POST 大小直接相关
- upload_max_filesize可能不相关,不确定
- max_input_time,如果 POST 花费的时间太长
- max_input_nesting_level如果你的数据是一个有很多子级别的数组
- max_execution_time,但很确定不是那个
- memory_limit,因为您可能会达到超出子进程允许内存的大小
- max_input_vars,如果你的数据数组有很多元素
If you have reached the compiled in limit for Apache your only solution is to avoid direct POSt of such a big chunk of data, you'll have to break it into pieces.
如果您已达到 Apache 的编译限制,您唯一的解决方案是避免直接 POST 如此大的数据块,您必须将其分成几部分。
回答by schmunk
You may also check the suhosin.ini settings, eg.:
您还可以检查 suhosin.ini 设置,例如:
suhosin.post.max_value_length = 65000
回答by Fostah
You may also want to set set_time_limit(0)and your memory limit.
您可能还想设置set_time_limit(0)和您的内存限制。
EDIT: You may also want to console.log(string)
; or console.log(string.length);
before your request to verify it's being set properly, and also check your request in firebug or chromes developer tools to verify your data is being sent.
编辑:您可能还想console.log(string)
;或者console.log(string.length);
在您请求验证是否正确设置之前,并在 firebug 或 chromes 开发人员工具中检查您的请求以验证您的数据是否正在发送。
回答by user4651625
//Adding Respond Box After Selected Field
$( '[maxlength]' ).bind('click keyup', function(){
var RespondBox = '<div class="StPgRp" id="UpdateRespond"></div>';
$('#UpdateRespond').remove();
$(this).after(RespondBox);
});
//Counting Maximum Characters Allowed In Selected Field
$( '[maxlength]' ).bind('click keyup', function(){
var MaxLength = $(this).attr('maxlength');
var CurrentLength = $(this).val().length;
var Remainder = MaxLength - CurrentLength;
$('#UpdateRespond').html('You have ' + Remainder + ' characters remaining.');
});
//Checking the PHP Function if YES then send message to user
$( '.Check' ).bind('click keyup', function(){
var Check = $(this).parent().children('.Check').val();
});
Add this to your .js file linked to your page and your sorted!
将此添加到链接到您的页面的 .js 文件中并进行排序!