19

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)

James Nine
  • 2,548
  • 10
  • 36
  • 53
  • 1
    Does the same error persist with significantly smaller strings, such as `test`? Undefined index makes it seem as though it isn't being posted. – MetalFrog Mar 13 '12 at 19:53
  • 1
    no, error does not persist with small text data. – James Nine Mar 13 '12 at 19:56
  • Try `var_dump($_GET); var_dump($_POST);` if there's nothing, check apache config files for possible limits – Robus Mar 13 '12 at 20:16
  • what php version are you using? php underwent some invasive changes to post data handling recently due to a hash collision DOS attack. – Basti Mar 13 '12 at 20:17
  • Each HTTP server implementation (Apache, IIS, etc) has its own setting for data limit on POST operations. If you're able to configure the server, you can change the limit in an .htaccess file. – Brian Driscoll Mar 13 '12 at 20:17
  • could be running into browser string size / memory limit.. test string length before sending – charlietfl Mar 13 '12 at 20:18
  • I would also check the request header if your browser actually did include your 2M string. Maybe you went into some of Chrome's or even jQuery's limitations. – Basti Mar 13 '12 at 20:22
  • Basti: the request header actually does show the entire 2M string on Chrome. – James Nine Mar 13 '12 at 20:24

4 Answers4

33

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:

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.

Tarek Adam
  • 3,387
  • 3
  • 27
  • 52
regilero
  • 29,806
  • 6
  • 60
  • 99
3

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

suhosin.post.max_value_length = 65000
schmunk
  • 4,708
  • 1
  • 27
  • 50
0

You may also want to set set_time_limit(0) and your memory limit.

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.

Fostah
  • 2,947
  • 4
  • 56
  • 78
-2
//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!