Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP/Apache/AJAX - POST limit?

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:

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']):

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...

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

EDIT2: memory_limit = 256M in php.ini

EDIT3: max_input_time = -1 in php.ini

EDIT4: var_dump($_POST) returns 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)

like image 806
James Nine Avatar asked Mar 13 '12 19:03

James Nine


2 Answers

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.

PHP:

  • post_max_size which is directly related to the POST size
  • upload_max_filesize which may be unrelated, not sure
  • max_input_time, if the POSt takes too long
  • max_input_nesting_level if 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

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.

like image 145
regilero Avatar answered Sep 20 '22 02:09

regilero


You may also check the suhosin.ini settings, eg.:

suhosin.post.max_value_length = 65000
like image 21
schmunk Avatar answered Sep 20 '22 02:09

schmunk