Problem with multiple Ajax requests

122 views
Skip to first unread message

Phenix

unread,
Nov 5, 2009, 2:53:08 PM11/5/09
to MooTools Users
Hello,

I'm using version 1.2.4 of Mootools on a php script which creates a
zip archive of several files. The process can takes time so i want to
check every 5 seconds what is doing the archiver.

First of all, i launch a first request which calls the zip archiver
and start adding all the files :

***
var mainReq =new Request({url: 'website/dlall.php?token='+token,
method: 'post',
onComplete:function(data){
ok = true;
timedReq.stopTimer();
$('etat-dlall').innerHTML = "4/4 Files
added, you can download it";
}
}).send(data);
***

This request can takes time so i launch timed requests to get each 5
seconds the state of the archive (which is updated by the first script
(dlall.php)) :

***
var timedReq = new Request({
method: 'post',
url: 'website/etatdlall.php',
initialDelay: 5000,
delay: 5000,
limit: 15000,
onComplete:testdlall
}).startTimer({
token: token
});

function testdlall(txt) {
if(!ok) {
var data = JSON.decode(txt);
if(data.etat == "1" || data.etat == "2" || data.etat ==
"3") {
$('etat-dlall').innerHTML = data.etat + "/4 : " +
data.texte + " loading...";
}
else if(data.etat == "4") {
$('etat-dlall').innerHTML =data.etat + "/4 : "
+data.texte;
timedReq.stopTimer();
}
else {
$('etat-dlall').innerHTML = txt;
timedReq.stopTimer();
}
}
}
***

I thought that it was possible to manage multiple requests in the same
time but it doesn't work in this case. The first request is fired,
then the second, but the second waits the first to finish to return
data... So i can't have an updated state of the archive.

Do you have any idea why the second script can't work in parallel with
the first?

Thanks a lot!

Jon Hancock

unread,
Nov 5, 2009, 5:09:39 PM11/5/09
to MooTools Users
I don't know how to make multiple requests work. I do know that I
would change your design. If the return of your second post,
'website/etatdlall.php', contains info on if its complete, you can
kick off the "finished, download now" function from here and keep
things serial. Keep it simple is the best approach.

Jon

Phenix

unread,
Nov 6, 2009, 3:39:39 AM11/6/09
to MooTools Users
Thanks for your answer.
If i keep it simple, all i need would be only the first script which
create the archive and when finished returns the "finished, download
now". The second script is here only to gather some info about the
process.
I'm going to make some other tests and will post here if i have
something new...

Phenix

unread,
Nov 6, 2009, 5:58:32 AM11/6/09
to MooTools Users
I've tried to use setInterval instead of timed requests, even to
launch the second request at first, but no changes.
Any idea about maybe an apache configuration or browser limitation?

Rolf -nl

unread,
Nov 8, 2009, 5:58:52 AM11/8/09
to MooTools Users
I'm sorry, didn't test the actual code, but why not create just one
periodical request? The first time it would check of there's no zip
file created yet, so it starts packing & returns that info
(Archiving... start) then the second time it sees there's already a
zip file in the making and would return the progress (Archiving...
24%), and finally the archive is created and you can return a download
link and stop the timer or whatever you want.

No?

Phenix

unread,
Nov 8, 2009, 7:19:31 AM11/8/09
to MooTools Users
It's an idea but the first script creates and add files to the archive
and takes a lot of time. If i follow your idea, i would need some kind
of background script which would always turn and check if there is an
archive to make and which wouldn't be call by the user.
I'm going to make a demo page to better explain my situation.

Phenix

unread,
Nov 8, 2009, 7:37:23 AM11/8/09
to MooTools Users
Here you can find a demo page of what i want to do :
http://www.mynox.fr/multiple-requests/ and ... it works fine :D It
must be something in my script which blocks something.
I will try to find what and i will come back here to post...

Rolf -nl

unread,
Nov 8, 2009, 7:45:53 AM11/8/09
to MooTools Users
Yup, I see it's running fine in your demo :) I think it should be a
bug somewhere else then, like you wrote.

What I meant with one periodical request is that you have one php
script that checks first if an archive is created, if not it starts
creating one and return the status. If there is already an archive in
the making (the 2nd and following requests) it would just return the
status. I'm not sure if this would work 100%, didn't think out the php
backend stuff for this, and if 2 requests work, it's fine too, not?


On Nov 8, 1:37 pm, Phenix <p...@no-log.org> wrote:
> Here you can find a demo page of what i want to do :http://www.mynox.fr/multiple-requests/and ... it works fine :D It

Phenix

unread,
Nov 8, 2009, 8:43:13 AM11/8/09
to MooTools Users
I found what was the problem! :)
As you said, it was not about ajax requests, it was in the php
backend.

The two scripts was working with sessions, when i execute session_start
() the script locks the session file until the end of the process, so
the second file wasn't able to access to the session until the end of
the first script!
Hopefully, the function session_write_close() is able to unlock the
session file before the end of the script...

Thanks a lot for your help and your ideas!

On Nov 8, 1:45 pm, Rolf -nl <plentyofr...@gmail.com> wrote:
> Yup, I see it's running fine in your demo :) I think it should be a
> bug somewhere else then, like you wrote.
>
> What I meant with one periodical request is that you have one php
> script that checks first if an archive is created, if not it starts
> creating one and return the status. If there is already an archive in
> the making (the 2nd and following requests) it would just return the
> status. I'm not sure if this would work 100%, didn't think out the php
> backend stuff for this, and if 2 requests work, it's fine too, not?
>
> On Nov 8, 1:37 pm, Phenix <p...@no-log.org> wrote:
>
> > Here you can find a demo page of what i want to do :http://www.mynox.fr/multiple-requests/and... it works fine :D It
Reply all
Reply to author
Forward
0 new messages