AJAX and multiple loads...

J

jodleren

I use ajax to load data, which can be slow. Normally it takes 2-14
seconds, but the record is 84 seconds. I have found, that after 40
seconds, most browsers consider the connection lost, e.g. the 84
example - got data, but the connection was cancelled, so I never got
to know.
In my code, I can take it apart, and run it several times, or more in
parallel.... - n PHP.
Still, I need a bright way, so
1) return a code and load again in AJAX
2) open multiple pages at once
3) _________ ?

Any ideas?

WBR
Sonnich

My code as of now:

var xmlHttp = window.XMLHttpRequest ? new XMLHttpRequest() : new
ActiveXObject("MSXML2.XMLHTTP.3.0");
xmlHttp.onreadystatechange = function()
{
ShowETime(); // starts timer and shows the loading time

if(xmlHttp.readyState==1)
statusID.innerHTML="Please wait, loading...";
else if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
// if(xmlHttp.responseText=="Done.")
// something to load again, if there is more
{
statusID.innerHTML=xmlHttp.responseText;
StartUp2(); // something else...
}
}
else
statusID.innerHTML="<span class=\"message_fail\">Connection
error</span>";

clearInterval(timer1);
}
}
xmlHttp.open("get","mypage.php?loadid=<?php echo rand(); ?>");
xmlHttp.send(null);
 
G

GArlington

I use ajax to load data, which can be slow. Normally it takes 2-14
seconds, but the record is 84 seconds. I have found, that after 40
seconds, most browsers consider the connection lost, e.g. the 84
example - got data, but the connection was cancelled, so I never got
to know.
In my code, I can take it apart, and run it several times, or more in
parallel.... - n PHP.
Still, I need a bright way, so
1) return a code and load again in AJAX
2) open multiple pages at once
3) _________ ?

Any ideas?

WBR
Sonnich

My code as of now:

var xmlHttp = window.XMLHttpRequest ? new XMLHttpRequest() : new
ActiveXObject("MSXML2.XMLHTTP.3.0");
xmlHttp.onreadystatechange = function()
{
ShowETime(); // starts timer and shows the loading time

if(xmlHttp.readyState==1)
statusID.innerHTML="Please wait, loading...";
else if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
// if(xmlHttp.responseText=="Done.")
// something to load again, if there is more
{
statusID.innerHTML=xmlHttp.responseText;
StartUp2(); // something else...
}
}
else
statusID.innerHTML="<span class=\"message_fail\">Connection
error</span>";

clearInterval(timer1);
}
}
xmlHttp.open("get","mypage.php?loadid=<?php echo rand(); ?>");
xmlHttp.send(null);

What in hell is your page (the one you are calling) doing for 84
seconds?
The point of having AJAX was to make things better/faster. So you
should use FAST processing pages, cache the results on the server if
necessary, send as little information as possible (i.e. DO NOT send
ALL results if your page can only show one page).

Another thing: I am not familiar with php, but (from my experience
with other scripting languages) I suspect that your request to
"mypage.php?loadid=<?php echo rand(); ?>" might NOT work the way you
expect it to work...
 
J

jodleren

On Feb 6, 8:54 am, jodleren <[email protected]> wrote:
What in hell is your page (the one you are calling) doing for 84
seconds?

It is a search function. Some searches can be very wide and I really
have a lot of data to look into. I admin that it is rare that a used
might search for and in a way, that it will take that long. (mostly me
testing worst case)
I am also looking for ways to speed that up.
The point of having AJAX was to make things better/faster. So you
should use FAST processing pages, cache the results on the server if
necessary, send as little information as possible (i.e. DO NOT send
ALL results if your page can only show one page).

I do that. Data is cached on the server, then I load a new page once
the search is done.
Another thing: I am not familiar with php, but (from my experience
with other scripting languages) I suspect that your request to
"mypage.php?loadid=<?php echo rand(); ?>" might NOT work the way you
expect it to work...-

It ( <?php echo rand(); ?> ) simply generates a number, so IE will not
use cached data. By having a new number every time thet s..... IE
thinks it is a new page (which, in fact, it is).

/S
 
E

Erwin Moller

jodleren wrote:

It ( <?php echo rand(); ?> ) simply generates a number, so IE will not
use cached data. By having a new number every time thet s..... IE
thinks it is a new page (which, in fact, it is).

/S

Hi Sonich,

Using PHP to generate a random string for Ajax is a bit strange.
If you reuse the same code in the same page, you are stuck with the old
url, and thus get possible cachingproblems.

Why not let Javascript generate the number?
I always use something like this:
url=url+"&myrand="+Math.random();

Regards,
Erwin Moller
 
J

jodleren

What in hell is your page (the one you are calling) doing for 84
seconds?
The point of having AJAX was to make things better/faster. So you
should use FAST processing pages, cache the results on the server if
necessary, send as little information as possible (i.e. DO NOT send
ALL results if your page can only show one page).

I reply to this in hope, that anyone might have any ideas?
I cannot imagine, that I am the only with something this slow. It is
not my choice, I have tried to speed it up, but still... it takes
time.
I have an option of caching data (usually not much), and opening a
page, if the answer is "go", and I can stop it when "done" arrives.
That is the best I can think of.

I would prefer to open a new page, once the first one is done, as
opening multiple pages might get complicated when figuring out what
they have to do.

Still, I need to make this search work, I have optimised it, but there
are limits to that too. Result: it still takes 45 seconds. That is 5
too much for some connections (timeout @ 40 sec) - and in the future
there will not be less data :)

TIA
Sonnich
 
J

Joost Diepenmaat

jodleren said:
I reply to this in hope, that anyone might have any ideas?
I cannot imagine, that I am the only with something this slow. It is
not my choice, I have tried to speed it up, but still... it takes
time.

I'm using the following strategy in a production system where some jobs
can take a couple of minutes (this is the simplified overview):

1. (client) Send Ajax request for job.
2. (server) Push the job into the job queue, return "wait" response that
includes the job ID.
3. (client) Retrieve the job ID, wait for a bit and request job status
4. (server) If the job is finished, send the results back.
If not, send a "wait" response.
5. (client) If "wait" response is recieved, go to 3.
Otherwise, use the data that you've now recieved.

The jobs are actually scheduled & cached in a database, and another
process is monitoring the job queue, runs the jobs and updates the entry
in the database when the jobs are done.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,157
Latest member
MercedesE4
Top