Marc
Marc

Reputation: 6771

Multiple simultaneous running ajax requests in ExtJS 4

Problem

I have a long running import job which I start with an ajax request, it could take some minutes until the request is finished. While this first ajax request is running, I want to have a look at the server to know how far the import is gone, this second request will be done every 2 seconds or so.

When I use the Ext.Ajax method the requests seems to be chained - the first ajax request (import) runs until it is finished, just then the second (import update) is fired.

I saw that Ext.Ajax is singleton, so maybe thats the reason. So I tried to create my own Connection objects with Ext.create('Ext.data.Connection') but it doesn't work.

My current request chain is:

But it should be:

Question

The browser should be able to handle multiple request, there must be a limitation inside ExtJS but I didn't find it?


Update 2011-10-16

Answer

The problem wasn't ExtJS - sorry! It was PHP, my first script works with the session and the second script tried to access the session as well. And because PHP sessions are file based, the session file was locked from the first request script and the second request script had to wait until the first release the session lock.

I solved this with this little piece of code I added to my import process (the first script) after every x row:

 $id = session_id();
 session_write_close();
 sleep(1);
 session_start($id);

So it stops and reloads the session and the other script was able to hook in and get the session information.

Upvotes: 6

Views: 2909

Answers (1)

Lionel Chan
Lionel Chan

Reputation: 8069

Singleton or non-singleton doesn't even change the way Ext.Ajax works. I think this could be due to the coding (did you wait for the calls to finish?)

Afaik, I never have this problem before when I do multiple calls. The only thing that is hogging the calls is the server (PHP), which doesn't support parallel processing and causes delays, and generate a pattern like this

  • Call 1 - start
  • Call 2 - start
  • Call 1 get processed in the server and Call 2 get queued up
  • Call 1 - finished
  • Call 2 get processed in server
  • Call 2 - finished

It could be disastrous if Call 1 requires more time to process than Call 2.

EDIT:

I have written this little demo just for you to feel how does it works. Check it out :) Spent me half an hour lol!

Upvotes: 5

Related Questions