0

My AJAX request takes about 7 seconds to complete. For a page I have many such requests. The server responses almost sequentially for each request. For 10 requests I am getting the response of the last one after 1 minute. Is there a way to get the responses independently? I tried simply $http.get as well as jQuery AJAX to make the calls. I want to get the responses for all requests almost instantly after 7 seconds processing time.
For example, My $http.get code is below:

$q.all([
            $http.get('http://localhost/ajaxtest/index.php?route=test/sleepTest&seq=' + 0),
            $http.get('http://localhost/ajaxtest/index.php?route=test/sleepTest&seq=' + 1),
            $http.get('http://localhost/ajaxtest/index.php?route=test/sleepTest&seq=' + 2),
            $http.get('http://localhost/ajaxtest/index.php?route=test/sleepTest&seq=' + 3),
            $http.get('http://localhost/ajaxtest/index.php?route=test/sleepTest&seq=' + 4),
            $http.get('http://localhost/ajaxtest/index.php?route=test/sleepTest&seq=' + 5),
            $http.get('http://localhost/ajaxtest/index.php?route=test/sleepTest&seq=' + 6),
            $http.get('http://localhost/ajaxtest/index.php?route=test/sleepTest&seq=' + 7),
            $http.get('http://localhost/ajaxtest/index.php?route=test/sleepTest&seq=' + 8),
            $http.get('http://localhost/ajaxtest/index.php?route=test/sleepTest&seq=' + 9)
        ])
            .then(function(responses) {
                console.log( responses[0].data);
                console.log( responses[1].data);
                console.log( responses[2].data);
            });

At server side, I am running sleep() function for test purpose. Code is below:

public function sleepTest(){
    session_write_close();
    sleep(10);
    print $this->request->get["seq"];
}

The XHTTP request results are coming one after another (about 10 seconds after previous response comes). Please see the response times in the screenshot, The server is responding for each requests after 10 seconds of previous response. The last response comes after 100 seconds while I am expecting all responses to come after 10 seconds.

Update: Some mentors mentioned another question which have an accepted answer, but that answer is not clear. I followed the referred document but could not get what I expect. Adding session_write_close(); helps me partially, it makes 6 responses parallelly, means I am getting AJAX responses from server 6 at a time. Is there anything else I can do to get all (10+) responses parallelly?

Screenshot of requests and responses with time

Updated Screenshot: Updated Screenshot of requests and responses with time

Mainuddin
  • 416
  • 5
  • 15
  • Read [this question/answer](https://stackoverflow.com/questions/37431413/why-cannot-apache-handle-multiple-requests-at-the-same-time). Looks like your server configuration isn't quite correct. – Michel Jun 17 '18 at 06:31
  • Take the sleep() out! – Joseph_J Jun 17 '18 at 06:42
  • @Joseph_J, sleep() is just a placeholder, I have another tasks there which take approximately 8 seconds. – Mainuddin Jun 18 '18 at 03:57
  • Hi @georgeawg, The other similar question does not have a clear answer, the accepted answer did not work for me. Please remove duplicate mark from this question. – Mainuddin Jun 18 '18 at 06:17
  • That it is working for 6 connections the way you want now, but not more/all of them, is due to limitations on how many parallel requests browsers make to one domain - see f.e. https://docs.pushtechnology.com/cloud/latest/manual/html/designguide/solution/support/connection_limitations.html Setting up a couple of subdomains could help work around that. – CBroe Jun 18 '18 at 07:10
  • @CBroe, You are right. The server have MPM enabled but the only reason is the browser connection limit. I have to find another way to implement it. Thanks for the information. – Mainuddin Jun 25 '18 at 09:03

0 Answers0