PHP Atom Server

While out hunting for someone who’s implemented some kind of timeout mechanism when using XMLHttpReqeust, ran into isolani’s PHP Atom Server (serves ATOM XML), which I guess is part of the isoTope framework he’s working on, as well as a Javascript ATOM client (which uses XMLHttpRequest).

Interested to see he’s using the php://input stream. In fact there is another way to access the raw POST data in PHP, which will work on older PHP versions, using the global variable $HTTP_RAW_POST_DATA. Unless you have always_populate_raw_post_data switched on in php.ini, this global only exists if an HTTP POST was made without a Content-Type of “application/x-www-form-urlencoded” (which is the default content type for a normal form). Believe you also need to declare it or access it via the $GLOBALS array, unlike other variables such as $_GET and $_SERVER e.g.;


function getRawPost() {
global $HTTP_RAW_POST_DATA;
return $HTTP_RAW_POST_DATA;

// or
# return $GLOBALS['HTTP_RAW_POST_DATA'];
}

Doesn’t bring me any closer to implementing timeouts with XmlHttpRequest though ;) Got some wierd stuff happening now – IE calls the XmlHttpRequest.onreadystatechange callback both for sync and async requests but if you call the abort() method, prepare to kill -9 (the Windows way). Meanwhile Mozilla seems to ignore onreadystatechange completely, when making sync requests, which doesn’t leave much room for a timeout.

Some other interesting links along the way;

Cross-Browser XMLHttpRequest – provides a partial XMLHttpRequest implementation for Opera

libXmlRequest – very interesting implementation, using a pool of XMLHttpRequest objects. But still doesn’t seem to answer the timeout mystery.

Also from the libXmlRequest author: engine for web applications – something in the same ball park as ScriptServer. Personally turned me off with “too many” layers of abstration and excessive XML but perhaps that’s me – transparency is relative.

[Update]
Looking in all the wrong places! Christian has the answer with Livesearch – use Window.setTimeout()

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • http://www.mission36teen.com M36Teen

    Wow, you’re really getting into this aren’t you?!!

  • http://www.phppatterns.com HarryF

    It’s that obsessive / compulsive disorder ;)

    Actually there seems to be little info about XMLHttpRequest out there right now that really goes into depth so figure discoveries need noting.

  • http://www.sample.com Widow Maker

    Maybe little documentation and information though your sure on your way to making a lot more documentation and information, and for that you need to be praised :)

    I’m now kinda hoping to find some time soon to look over your blogs and links to get some idea on this, though are you planning to put together a sitepoint article(s) on this whole subject in the near future ?

    Please say ‘Yes’ :)

  • http://www.mission36teen.com M36Teen

    It’s that obsessive / compulsive disorder ;)

    Hmm, you should really do something about that. 8)

    Actually there seems to be little info about XMLHttpRequest out there right now that really goes into depth so figure discoveries need noting.

    You’re sure on your way to making a lot more documentation and information, and for that you need to be praised :)

    I agree! And I also hope that you will put this into one (or more), really good, article(s)!

    Maybe that “obsessive / compulsive disorder” is a good thing! =) WAIT!!! Much better! lol

  • http://www.phppatterns.com HarryF

    are you planning to put together a sitepoint article(s) on this whole subject in the near future ?

    Not at the moment but there is a lengthy essay in my head which ties all this together. Guess we’ll see.

  • http://www.rideontwo.com z0s0

    I’m sure it will wind up in Kev’s tech times next week!

  • Nelson Menezes

    Harry, I’ve been looking around the limitations of XmlHttpRequest and XMLHTTP; it seems that there’s no way to specify a timeout at all, although this might be of interest: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=XbPjttzfBHA.1536%40cpmsftngxa08

    It might be that the solution is to *always* do requests asynchronously and implement your own timeout mechanism. (Including, maybe, a pseudo-synchronous call, if you want to have that functionality.)

  • http://www.phppatterns.com HarryF

    Hi Nelson,

    Many thanks for that link! Seems to confirm what I’m finding, which is nice to know. I’ve managed to implement a timeout for async requests now (using a similar but slightly simpler approach that that suggested).

    But sync requests really are synchronous it seems (both in IE and Mozilla) – the Window object doesn’t get a chance to process any timeouts it’s been given.

    Really like your idea of of a pseudo-synchronous request – that may well be the answer to allow the response to be returned directly to the caller. Will see where that leads…

  • rickwright

    This type of site could be the future; I have been trying it out, and can see tremendous possibilities, and advantages.
    Rick

  • Ren

    Don’t know if your aware of this but here is a link to microsoft’s own method of calling SOAP services from IE, completely in JS (with some odd dynamically created VBS) using XmlHttpRequest

    http://msdn.microsoft.com/library/default.asp?url=/workshop/author/webservice/overview.asp

  • http://www.phppatterns.com HarryF

    Re: pseudo-synchronous calls

    Sadly looks like that’s not going to work. Sending an async request then looping until the request is completed (so I can capture the result and return to the caller) seems to prevent the request from actually taking place – like the loop occupies the browser 100% (resulting in popup warnings to cancel excution).

    On the MS web services page;

    Note: Synchronous calls to remote services lock the user interface while the call is pending and, therefore, aren’t practical for browser-based applications

    Perhaps it’s time to give up hacking at it ;)