Try to search your question here, if you can't find : Ask Any Question Now ?

jQuery Ajax / Apache / PHP – Post size limit

HomeCategory: stackoverflowjQuery Ajax / Apache / PHP – Post size limit
Avatarjulie asked 5 months ago

I’m doing an ajax post through jquery (1.9.1) to an apache (2.2.25), php (5.3.28) server which is on a windows machine. HTML5/utf-8. My post has 3 variables. Two are very short text strings. The third is a very large text field. It contains base64 encoded image data. When the total post data hits a certain length (a bit over 22279860 chars) things break in a strange way. It appears that all the data is sent to the server because I’m using a progress meter that goes all the way up. When I log my ajax result it shows it completed successfully with a 200 status code. The strange part is that the response body is always blank. I’ve striped down the handling php file to just:

<? echo 'hi' ?>

But that never is sent in the response. So it seems like the request isn’t even getting to PHP land. So why is my server sending back a 200 status code?

Things I’ve tried

Setting in vhosts

LimitRequestFields 0
LimitRequestFieldSize 0
LimitRequestLine 0

Setting in .htaccess

php_value post_max_size 128M
php_value upload_max_size 128M
php_value memory_limit 128M
php_value upload_max_filesize 128M

LimitRequestBody 0
LimitXMLRequestBody 0
RLimitCPU max
RLimitMEM max
RLimitNPROC max 

When I lower these limits enough php does throw the expected errors which end up in the ajax response body.

I have also tried splitting the data in separate variables which does seem to work. I can easily double the amount of data I’m sending when breaking it apart. So it seems like there is some kind of line length limit or variable length limit in apache. I say apache because it seems to send find from ajax and never seems to get to php. I’m also wondering if jquery is formatting the post data strangely.

Needless to say, everything works fine with small amounts of data and I think I am changing all appropriate apache/php limits. I’m more concerned about figuring out what the limiting factor is rather than finding a different way to complete this task. Any ideas?

EDIT

I have put together a simple demo file which can be run on a PHP server. I’ve stripped it down so it doesn’t even use jquery. Reducing the ‘data_length’ variable for me causes it to work, as does changing the ‘string’ variable to false.

<?

if ($_POST[action] == 'upload') {
    echo 'hi' ;
    die ;
}

?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <style >
            #prog_cont {
                height: 10px; 
                font-size: 0px;
                line-height: 10px;
                width: 200px;
                border: solid 1px black;
            }

            #prog {
                height: 100%; 
                background-color: green; 
                width: 0%;
            }
        </style>

        <script >
            window.data_length = 22279981 ; //22279981 - is just too big
            window.string = true ; // false is chunked object
            window.url = '?' ;

            function startUpload() {
                var data = {
                    action : 'upload'
                } ;

                var test_arr = {} ;
                var test_str = '' ;

                var inc = 0 ;
                while (test_str.length < window.data_length) {
                    var cur = "000000011111112222222333333344444444555555556666666677777777" ;
                    test_str = test_str+cur ;
                    test_arr[inc++] = cur ;
                }

                if (window.string) {
                    data.data = test_str ;
                }
                else {
                    data.data = test_arr ;
                }

                var serialize = function(obj, prefix) {
                    var str = [];
                    for(var p in obj) {
                        if (obj.hasOwnProperty(p)) {
                            var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
                            str.push(typeof v == "object" ?
                                serialize(v, k) :
                                encodeURIComponent(k) + "=" + encodeURIComponent(v));
                        }
                    }
                    return str.join("&");
                }

                var ajax = new XMLHttpRequest() ;
                ajax.open("POST", window.url, true) ;

                ajax.upload.onprogress = function (ev) {
                    var pc = ev.loaded / ev.total * 100 ;
                    document.getElementById('prog').style.width = pc+'%' ;
                } ;

                ajax.onloadend = function (ev) {
                    var r = ev.originalTarget ;
                    console.log(r) ;
                    document.getElementById('results').innerHTML = '<b>Status:</b> '+r.status+' &nbsp; <b>Response:</b> '+r.responseText ;
                } ;

                var params = serialize(data) ;

                console.log(params.length) ;

                ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded") ;
                ajax.setRequestHeader("Content-length", params.length) ;
                ajax.setRequestHeader("Connection", "close") ;

                ajax.send(params) ;
            }
        </script>

    </head>

    <body>
        <p><a href="javascript:startUpload()">Start upload</a>
        <div id="prog_cont"><div id="prog"></div></div>
        <div id="results"></div>
    </body>
</html>
1 Answers
Best Answer
AvatarMannu answered 5 months ago
Your Answer

14 + 10 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com