title: AJAX, PHP Sessions and simultaneous requests
body: <p>I'll get straight to the point!</p>
  
  <p>My javascript sends about 20 AJAX requests to my PHP file to respond to (via an external web API) when the user submits their search. The results are stored in an array in the session array.</p>
  
  <p>I've read that browsers will only allow 2 simultaneous requests to a server.</p>
  
  <p>My first problem is that while there are still more than one requests still waiting for a response the AJAX "add to basket" request won't work since it's still waiting for the other requests to complete.</p>
  
  <p>My second (and more annoying) problem is that the 2 requests that are being handled simultaneously seem to be over writing each other so that when all the responses are complete only half are in the session array. Either all the odd ones or even ones depending on whether the final request is odd or even.</p>
  
  <p>I'd prefer not to have to send requests individually (ie only send the next when the last has finished) as that would slow things down for the user a fair bit.</p>
  
  <p>Is there a solution to this session overwriting or should I be using a completely different approach altogether?</p>
  
  <p>Thanks all!
  <hr />
  Edit:<br/>
  It's for checking domain availability. The user searches for "mydomain" and results for com, net, org, etc are eventually presented.</p>
  
  <p>Sending a single request and having the script search for all tlds in one go means that a response isn't returned until all results are in. The result for some tlds seem to take upto and over 30 seconds during which the user is getting no feedback save for a swirly icon and "Please Wait" (this is what happens when javascript isn't enabled).</p>
  
  <p>Seperate requests allow me to display the domains availability as they come in.</p>
  
  <p>I'm currently thinking along the lines of sending a single request and then using javascript's setinterval to repeatedly check the session until all results are in.</p>