1

I am loading summaries into my main page by making 5 AJAX calls using JQuery. The debugger shows that all calls start at the same time, but return results consecutively instead of simultaneously. i.e. First call returns after 5 secs, second returns after 10 secs, and so on.

I did not set async to false.

The server runs Centos7 with HTTPD and PHP7. YUM has applied all updates.

Evidently it's a matter of how many threads HTTPD is generating for each client call. I can't figure out how to make it create a separate thread for each.

// Get 4w records
$.ajax({
    dataType: "json",
    url: "getdata.php",
    async: "true",
    data: { 'db': '4w', 'function': 'registrations' },
    method: "POST"
})
    ...
// Get 8c records
$.ajax({
    dataType: "json",
    url: "getdata.php",
    async: "true",
    data: { 'db': '8c', 'function': 'registrations' },
    method: "POST"
})
    ...
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
Hussain Akbar
  • 646
  • 8
  • 25
  • 1
    It all depends on what `getdata.php` does. Is it possible that the file locks some database tables while it is performing a long query? – Jerodev Jul 09 '19 at 07:23
  • 1
    There can be restrictions on concurrent requests placed by a client on the server. This is part of the reason why making multiple async requests is a bad idea. I'd strongly suggest you refactor this logic so that you aggregate all the requests in to a single one. – Rory McCrossan Jul 09 '19 at 07:23
  • Related: https://stackoverflow.com/questions/1430883/simultaneous-requests-to-php-script – T.J. Crowder Jul 09 '19 at 07:26
  • getdata.php reads the total records for the criteria given in the parameters using "SELECT ... FOR READ ONLY" statements. This should not lock the tables. Originally, all of the results were aggregated into a single call, but then the UI wold show "Loading...." for 30 seconds. Which is why I passed the parameters and called it 5 times so that the UI would get faster updates. – Hussain Akbar Jul 10 '19 at 08:50
  • @T.J.Crowder, this seems more appropriate. I already have session_write_close (); at the top of the PHP. – Hussain Akbar Jul 10 '19 at 08:55

0 Answers0