1

I'm making 3 subsequent AJAX requests to a PHP file.

$.post("page/1");
$.post("page/2");
$.post("page/3");

They all seem to wait for one another to finish before firing. I can watch the activity in Network Console, and see that they really do wait for each other. I can't figure out how to get them to fire all at once.

I am using PHP sessions, which I saw on here that might be the issue. But I added session_close() as suggested and that doesn't help. I don't think PHP is the issue because at least the browser would have made the 3 ajax calls and then they would wrongfully queue up. But that's not the case, they all wait for each other. 1 after another.

I've check jQuery Ajax.settings and async is set to true. I'm using 1.7.2 from the CDN.

Any ideas on where to look on how to get these to fire all at once?

Thanks!

Sean Clark
  • 1,436
  • 1
  • 17
  • 31
  • I'd check PHP side again. Maybe some setting allows only one request to be processed simultaneously. – Dmitry Osinovskiy Jul 12 '12 at 20:07
  • 1
    That's definitely something on the PHP side that's blocking parallel requests. – Darin Dimitrov Jul 12 '12 at 20:07
  • 2
    If you have to request `"page/1","page/2","page/3"` pages at once,then your site is designed wrongly. Combine those 3 in one (e.g. `"page/range1_3"`),and make just one call to server, instead of `3`. – Engineer Jul 12 '12 at 20:10
  • Try setting cache to false in the jQuery ajax settings, see if that helps. – Mahn Jul 12 '12 at 20:13
  • the goal of having 3 ajax requests is to have some data load in while more is gathered. It would take 3 times as long to call this api i'm using 3 times in PHP then return. so calling the api 3 times in 3 separate ajax requests is 3 times as fast. Its a better user experience to load some data in as its available. Ill check PHP settings for multiple requests. Thanks! – Sean Clark Jul 12 '12 at 20:25
  • Wouldn't it be more of an apache problem than a PHP problem? I mean, the browser is told to make 3 requests to the server, PHP can't stop that from happening. Actually nothing can stop the browser from making the requests right? It's just supposed to do them? – Sean Clark Jul 12 '12 at 20:29
  • @SeanClark: You're assumption is right. See my answer. – Robin Maben Jul 12 '12 at 20:32
  • old question, still topical. With KeepAlive PHP waits until the end of the script to write the session. This is how long it pauses a new request in the same session. Use session_write_close(); to free the session for writing by other scripts. See: https://stackoverflow.com/a/38334673/2320007 – Sarah Trees Oct 05 '19 at 19:59

1 Answers1

0

By default, you can have 4 concurrent HTTP requests.

As for XMLHttpRequests, its sometimes 6 (FF). But varies.

It would seem they are determined by the domain in question.

See this related question.

Community
  • 1
  • 1
Robin Maben
  • 22,194
  • 16
  • 64
  • 99