3

I'm using ajax to upload a group of ~50 files, all <= 5MB. If the connection is on the slower side, the upload will "timeout" without even finishing the first upload (approx ~45 seconds into upload).

In Firefox, ajax will fail with an 'error' response but no further info. In Chrome, I get an net::ERR_CONNECTION_RESET error.

I've checked my Apache and php.ini settings, and I believe they are all sufficient.

post_max_size = 1000M
upload_max_filesize = 15M
max_input_time = -1
max_execution_time = 0
max_file_uploads = 50
memory_limit = 128M

I've also tried setting ajax's timeout parameter to 0. My ajax request looks sort of like this:

return $.ajax({ 
    url: ajaxpath,
    type: 'post',
    data: formData,
    dataType: 'json',
    timeout: 0,
    xhr: function(){

        var myXhr = $.ajaxSettings.xhr();

        if(myXhr.upload) myXhr.upload.addEventListener('progress',function(e){

            uploadProgress(e,item);

        },false);

        return myXhr;

    },
    processData: false,
    contentType: false

}).fail(function(jqXHR,textStatus,errorThrown){

            console.log(textStatus,errorThrown);

        });

    }

With quicker connections, I don't seem to get this problem. If I use my browser's developer tools to throttle the speed, it'll happen, which is what I'm doing to replicate my users' situation.

Am I missing a setting somewhere? How can I keep the upload alive?

HWD
  • 1,547
  • 7
  • 36
  • 72

3 Answers3

3

Using the mod_reqtimeout Apache module ended up solving my problem:

RequestReadTimeout header = 20-40, MinRate = 500 body = 20, MinRate = 500

I found this suggestion at the bottom of a similar question.

For reference, I tried upping various ini settings, the Apache TimeOut directive, as well as the set_time_limit php function with no success.

HWD
  • 1,547
  • 7
  • 36
  • 72
0

At First your web server can have other timeout configurations that may also interrupt PHP execution.

Apache has a Timeout directive and IIS has a CGI timeout function.

Both default to 300 seconds.

See your web server documentation for specific details.

this message

ERR_CONNECTION_RESET

does not come from php script, it is a server issue because the server is disconnecting sending nothing to client !

here things you can try :

1- change setting max_execution_time = 1000 and see if you get more time , i had some issues with old xammp and appserv versions when using max_execution_time = 0 !

2- in php.ini set :

upload_max_filesize = 300M

post_max_size = 300M

3- put this in your script :

set_time_limit(3600); // 1 hour

since uploading is working fine on fast connections i guess the problem is a timeout somewhere

Alaa Morad
  • 445
  • 4
  • 13
0

Your configuration seems correct. only one thing is missing which is set_time_limit

set_time_limit(0); //If set to zero, no time limit is imposed. 

Mitesh Vasava
  • 707
  • 6
  • 13