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?