473,805 Members | 1,939 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AJAX request hangs for 5 minutes

My site uses lots of AJAX requests to PHP files which then retrieves
data from MySQL. About 95% of the time the requests complete without
issues. Every once in a while a request will hang for exactly 5
minutes then fail. It seems to be occuring on the client side. I
can't re-create the issue. It just happens randomly. I think it
eventally reaches the server (Apache) because I can see errors in the
server log that certain POST/GET variables are undefined. The
variables are clearly defined. One thing it could be is that it's
only tied to POST requests since I read somewhere that POST makes two
requests to the server. I have this issue with IE6 and IE7 and could
be tied to the wininet.dll I briefly read about as well. I'm not
sure. Below is the typical structure I use for my requests. Any help
will be appreciated. Thanks...

function loginReq(frm){
var req=false;
var msg=document.ge tElementById("m sg");
msg.innerHTML=" ";
msg.className=" error";
if(window.XMLHt tpRequest){
req=new XMLHttpRequest( );
}else if(window.Activ eXObject){
try{req=new ActiveXObject(" Msxml2.XMLHTTP" );}catch(e){
try{req=new ActiveXObject(" Microsoft.XMLHT TP");}catch(e){ }}
}
if(!req){
msg.innerHTML=" There was a problem with the request!";
return false;
}
req.onreadystat echange=functio n(){
if(req.readySta te==4){
if(req.status== 200){
if(req.response Text.substr(0,1 )=='<'){
document.getEle mentById("main" ).innerHTML=req .responseText;
}else{
msg.innerHTML=r eq.responseText ;
}
}else{
msg.innerHTML=" There was a problem with the request!";
}
}
}
var prm='user='+frm .user.value+'&p asswd='+frm.pas swd.value;
req.open('POST' ,'login.php',tr ue);
req.setRequestH eader("Content-type","applicat ion/x-www-form-
urlencoded");
req.setRequestH eader("Content-length",prm.len gth);
req.setRequestH eader("Connecti on","close");
req.send(prm);
}
Sep 12 '08 #1
10 2801
mo*****@yahoo.c om wrote:
My site uses lots of AJAX requests to PHP files which then retrieves
data from MySQL. About 95% of the time the requests complete without
issues. Every once in a while a request will hang for exactly 5
minutes then fail. It seems to be occuring on the client side. I
can't re-create the issue. It just happens randomly.
Reads like a race condition.
I think it eventally reaches the server (Apache) because I can see errors
in the server log that certain POST/GET variables are undefined. The
variables are clearly defined. One thing it could be is that it's
only tied to POST requests since I read somewhere that POST makes two
requests to the server.
Either you have read utter nonsense or misunderstood completely what you had
read. One (POST) request is still *one* (POST) request.
I have this issue with IE6 and IE7 and could be tied to the wininet.dll
I briefly read about as well. I'm not sure.
Wouldn't other UAs running on Windows have to use wininet.dll as well?

<http://msdn.microsoft. com/en-us/library/aa385483.aspx>
Below is the typical structure I use for my requests. Any help will
be appreciated. Thanks...

function loginReq(frm){
[...]
if(window.XMLHt tpRequest){
^^^^^^^^^^^^^^^ ^^^^^^
req=new XMLHttpRequest( );
}else if(window.Activ eXObject){
^^^^^^^^^^^^^^^ ^^^^^
Those are hardly sufficient feature tests. For example, not every property
can be called. And you should not rely on the `window' property to refer to
the Global Object. Read the FAQ and search the archives on both.
try{req=new ActiveXObject(" Msxml2.XMLHTTP" );}catch(e){
try{req=new ActiveXObject(" Microsoft.XMLHT TP");}catch(e){ }}
}
Testing for `Microsoft.XMLH TTP' usually suffices.
if(!req){
msg.innerHTML=" There was a problem with the request!";
return false;
}
req.onreadystat echange=functio n(){
[...]
}
var prm='user='+frm .user.value+'&p asswd='+frm.pas swd.value;
If you declare `Content-type: application/x-www-form-urlencoded', you MUST
escape the values that you use as an URI component or in the message body,
using the percent encoding defined in RFC3986. Implementations of
ECMAScript Ed. 3 provide the encodeURICompon ent() method for that purpose;
for older implementations you need escape() and maybe even a dummy method as
fallbacks.
req.open('POST' ,'login.php',tr ue);
That call must come *before* you assign to the `onreadystatech ange' property.
req.setRequestH eader("Content-type","applicat ion/x-www-form-
urlencoded");
This call is not universally supported, you need to feature-test it and
catch the exceptions it may throw. It is likely to be superfluous anyway.
req.setRequestH eader("Content-length",prm.len gth);
req.setRequestH eader("Connecti on","close");
These calls are pointless, the implementation will likely ignore them.
req.send(prm);
}

HTH

PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Sep 13 '08 #2
function loginReq(frm){
[...]
* if(window.XMLHt tpRequest){

* * * *^^^^^^^^^^^^^^ ^^^^^^^* * req=new XMLHttpRequest( );
* }else if(window.Activ eXObject){

* * * * * * *^^^^^^^^^^^^^^ ^^^^^^
Those are hardly sufficient feature tests. *For example, not every property
can be called. *And you should not rely on the `window' property to refer to
the Global Object. *Read the FAQ and search the archives on both.
If you are referring to < http://www.jibbering.com/faq/ >, I couldn't
find anything which tells us not to rely on the 'window' property to
refer to Global Object. Correct me if I am wrong but if the test for
the Global XMLHttpRequest property is successful, we can be almost
always sure that it will be a function.
* req.open('POST' ,'login.php',tr ue);

That call must come *before* you assign to the `onreadystatech ange' property.
The working draft of XMLHttpRequest says it comes after you assign the
onreadystatecha nge property.
< http://www.w3.org/TR/XMLHttpRequest/ >
* req.setRequestH eader("Content-type","applicat ion/x-www-form-
urlencoded");

This call is not universally supported, you need to feature-test it and
catch the exceptions it may throw. *It is likely to be superfluous anyway.
Though XMLHttpRequest is still not standardized, doesn't each and
every implementation out there provide a setRequestHeade r function?
>
* req.setRequestH eader("Content-length",prm.len gth);
* req.setRequestH eader("Connecti on","close");

These calls are pointless, the implementation will likely ignore them.
The default 'Connection' request header used by the browser when
issuing HTTP Requests is 'Keep-Alive' so if the XHR implementation /
HTTP Client chooses to ignore the one which overrides the default,
wouldn't it be kind of wrong?
Sep 14 '08 #3
On Sep 14, 2:15*pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
sasuke wrote:
The default 'Connection' request header used by the browser when
issuing HTTP Requests is 'Keep-Alive'

Nonsense. *Obviously you have no idea what you are talking about. *Read
RFCs 1945 and 2616, and please don't continue here before you did.
I guess not on each and every browser out there but at least FF works
this way. Trapping the Request headers with a sniffing tool says so at
least. But you are right, it's not a mandate.
so if the XHR implementation / HTTP Client chooses to ignore the
one which overrides the default, wouldn't it be kind of wrong?

Non sequitur. *Why don't you simply test my advice? *BTDT.

One wonders why you asked here if you think you know everything better.
Kindly point me a passage from my previous post which indicates my
claiming to know everything. I know you know better than me hence
those questions were not 'question tags' but genuine 'queries'.
Apologies to everyone for hijacking the thread; was curious. Still,
anyways, thanks for the clarifications.

Regards,
/sasuke.
Sep 14 '08 #4
sasuke wrote:
Thomas 'PointedEars' Lahn wrote:
>sasuke wrote:
>>The default 'Connection' request header used by the browser when
issuing HTTP Requests is 'Keep-Alive'
Nonsense. Obviously you have no idea what you are talking about. Read
RFCs 1945 and 2616, and please don't continue here before you did.
I guess not on each and every browser out there but at least FF works
this way. Trapping the Request headers with a sniffing tool says so at
least. [...]
That depends on the HTTP version negotiated with a proxy or server, and the
capabilities of the proxy or server. Did I or did I not suggest you read
the Specifications, where this is explained, before you posted here again?
>>so if the XHR implementation / HTTP Client chooses to ignore the
one which overrides the default, wouldn't it be kind of wrong?
Non sequitur. Why don't you simply test my advice? BTDT.

One wonders why you asked here if you think you know everything better.
Kindly point me a passage from my previous post which indicates my
claiming to know everything.
I can point you to your whole posting where you question every statement
that I made. Granted, it appears as if one of your statements eventually
improved (my) knowledge about XHR slightly.
I know you know better than me hence those questions were not 'question tags'
but genuine 'queries'.
Bluntly questioning things that had already been explained ad nauseam
before, and immediately after they have been explained again, without making
any appearance of having done any double-checking, can be easily perceived
as a wannabe's know-everything-better attitude. That does not mean at all
that questions should not be asked, though. But please ask smart questions.

<http://catb.org/~esr/faqs/smart-questions.html>
Apologies to everyone for hijacking the thread; was curious.
Don't be sorry for *this*. (There is no "hijacking" in this discussion
medium. An OP does not own a thread; threads can drift and should as long
they are on-topic.)
Still, anyways, thanks for the clarifications.
You are welcome, I think.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Sep 14 '08 #5
Thomas 'PointedEars' Lahn <Po*********@we b.dewrites:
<http://catb.org/~esr/faqs/smart-questions.html>
I can somehow understand that you would identify with the abandoned Red
Hat Primadonna ESR.

(for some of your problems,
<http://www.catb.org/jargon/html/W/wannabee.htmlmi ght help :)

Sep 14 '08 #6
I think it eventally reaches the server (Apache) because I can see
errors
in the server log that certain POST/GET variables are undefined. *The
variables are clearly defined. *One thing it could be is that it's
only tied to POST requests since I read somewhere that POST makes two
requests to the server.

Either you have read utter nonsense or misunderstood completely what you had
read. *One (POST) request is still *one* (POST) request.
Sorry, I shouldn't have said'two requests'. Here's what I was
refering to:
"The Yahoo! Mail team found that when using XMLHttpRequest, POST is
implemented in the browsers as a two-step process: sending the headers
first, then sending data. So it's best to use GET, which only takes
one TCP packet to send (unless you have a lot of cookies)."

You guys are way over my head. Thanks for your help.
Sep 15 '08 #7
mo*****@yahoo.c om wrote:
>>I think it eventally reaches the server (Apache) because I can see
errors in the server log that certain POST/GET variables are undefined.
The variables are clearly defined. One thing it could be is that it's
only tied to POST requests since I read somewhere that POST makes two
requests to the server.
Either you have read utter nonsense or misunderstood completely what you had
read. One (POST) request is still *one* (POST) request.

Sorry, I shouldn't have said'two requests'. Here's what I was
refering to:
"The Yahoo! Mail team found that when using XMLHttpRequest, POST is
implemented in the browsers as a two-step process: sending the headers
first, then sending data. So it's best to use GET, which only takes
one TCP packet to send (unless you have a lot of cookies)."
It would appear that my former statement applies. The Yahoo! Mail team
obviously does not know how either HTTP or TCP works:

<http://en.wikipedia.or g/wiki/Hypertext_Trans fer_Protocol>
<http://en.wikipedia.or g/wiki/Transmission_Co ntrol_Protocol>

The TCP *three-way* handshake is one of the first things you learn when
studying computer science. So the question is, given their apparent utter
incompetence, do you really want to trust these people with your data?

When trimming quotes, please do not remove the attribution lines for the
text that you leave there.
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Sep 15 '08 #8
Thomas 'PointedEars' Lahn wrote:
mo*****@yahoo.c om wrote:
>"The Yahoo! Mail team found that when using XMLHttpRequest, POST is
implemented in the browsers as a two-step process: sending the headers
first, then sending data. So it's best to use GET, which only takes
one TCP packet to send (unless you have a lot of cookies)."

It would appear that my former statement applies. The Yahoo! Mail team
obviously does not know how either HTTP or TCP works:
While that quotation is clearly a load of crap - there's no guarantee
that a GET request will be sent in a single TCP segment, for example -
the problem is not how many segments actually get sent (and so the
TCP three-way handshake is beside the point).

Applications present data to the stack. The stack determines how that
data is assembled into TCP segments. It's certainly possible that some
implementations of XHR present POST requests to the stack in pieces
(maybe specifically the request-line and headers in one piece, and the
content-body in another); and that will likely cause most TCP
implementations to usually send the request as two or more segments.

This is indeed undesirable; all associated outbound data should be
presented to the stack at once, whenever possible, to take advantage
of path MTU, reduce overhead, and avoid Nagle / Delayed ACK interaction.

But selecting an HTTP request type based on this possibility is
idiotic. It's a micro-optimization that is likely to have no
observable effect in most cases; Nagle will come into effect if both
segments are smaller than the MSS, but that's only a 200ms delay. And
GET and POST are not equivalent; they are used for different purposes,
so selecting one over the other based on performance is simply wrong.

If a POST request is not idempotent, then replacing it with a GET
request is a violation of the spec.
The TCP *three-way* handshake is one of the first things you learn when
studying computer science.
Nonsense. The three-way handshake, and TCP in general, have nothing to
do with computer science; and it's unlikely that most people studying
computing learn the details of TCP as "one of the first things".

And the three-way handshake is irrelevant here. The HTTP request
itself is not sent as part of the handshake, so a GET request smaller
than the MSS can indeed be sent "with a single TCP packet" (though it
may not be), as the Yahoos claimed, once the conversation is
established. Whether the conversation already exists is extraneous to
the question of how many segments ("packets") are involved in sending
a GET request.

The important point is that GET should be used for idempotent
(loosely, "read-only") requests, and POST for non-idempotent (loosely,
"read-write") requests. The OP should see RFC 2616 - not vapid advice
from random development blogs - for more information.

--
Michael Wojcik
Micro Focus
Rhetoric & Writing, Michigan State University
Sep 16 '08 #9
On 2008-09-16 16:38, Michael Wojcik wrote:
Thomas 'PointedEars' Lahn wrote:
>It would appear that my former statement applies. The Yahoo! Mail team
obviously does not know how either HTTP or TCP works:
...
It's a micro-optimization that is likely to have no
observable effect in most cases; Nagle will come into effect if both
segments are smaller than the MSS, but that's only a 200ms delay.
The Yahoo! Mail team could speed that up that by using:

navigator.setSo ckOpt(IPPROTO_T CP, TCP_NODELAY, 1);

I should send them a note.
- Conrad
Sep 16 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
2105
by: Elizabeth | last post by:
Can you all give me your best recommendation(s) for books on AJAX ? Thanks ... - E -
5
20092
by: dougwig | last post by:
I'm trying to handle the scenario where a user's session times out and and their ajax request triggers a redirection by the webserver (302 error?). I'm using Prototype 1.4 and the my works great with Firefox,but with IE6 the onFailure never gets called and the request never completes. My code: var ajaxReq = new Ajax.Request( url, {method: 'post', parameters:
25
2806
by: meltedown | last post by:
This is supposed ot be an example: http://www.ajaxtutorial.net/index.php/2006/11/30/simple-ajax-using-prototype-part-2/ It says : This example is probably the simplest example you will ever find. We are going to use the prototype feature ‘ajax.Updater’ (see part one for more details on prototype).
5
2728
by: Steve Wright | last post by:
I have an AJAX routine on a webpage that is working in IE6, but not IE7 or Firefox v2.0.0.2 The webpage is http://www.a-drop-in-the-ocean.co.uk/CWS/monitor10bins.php?quarry=401 The AJAX routine is encapsulated in the module http://www.a-drop-in-the-ocean.co.uk/CWS/js/timer.js
6
5177
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick application working. However, when attempting to implement the solution, the AJAX calls weren't updating the screen like the examples were and seemed not to fire until after the long running process had completed. I found the only real...
10
3162
by: Piotr Nowak | last post by:
Hi, Say i have a server process which listens for some changes in database. When a change occurs i want to refresh my page in browser by notyfinig it. I do not want to refresh my page i.e. every 5 seconds, i just want to refresh it ONLY on server change just like desktop applications do. The problem is that refreshing evry n seconds has to much impact on my web server. The refresh action should be taken only when something
1
2026
by: Joey | last post by:
Hey guys, here's what I have... To help manage browser windows with session state on the server, I have some javascript code in one of my master pages that gets planted into most (content) pages on my site... <script type='text/javascript'> var sessionTimer; function StartSessionTimer() {
1
1188
by: urbn | last post by:
Hi everyone. I am finally starting to focus more time on learning AJAX for the last few days, and I ran into a problem I couldn't find a solution too, or find much info on how to do this. What I am looking to do is have a page that is displaying content (varies between docs to videos) which are all pulled up from within a web browser (always IE). What currently happens is every few minutes the data is refreshed (iframe refresh though...
11
3056
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have run into a situation that if a page/tab that uses the Ajax toolkit (using .net version 3.5) is closed before the Ajax enable controls complete loading, then IE locks up. Does it in both IE7 and IE8. There is no issue when the controls are allowed to complete loading. Can you please tell me the best practice that handles this? Thanks.
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10360
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10105
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9185
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5542
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3845
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.