This talk was given at the Dutch PHP Conference 2011 and details the use of Comet (aka reverse ajax or ajax push) technologies and the importance of websockets and server-sent events. More information is available at http://joind.in/3237.
32. We need to get the status before oncomplete/onsuccess Note: there is also multipart/x-mixed-replace as part of XHR
33. XHR “ The XMLHttpRequest object can be in several states. The readyState attribute must return the current state, which must be one of the following values” * http://www.w3.org/TR/XMLHttpRequest/#states UNSENT (0) The object has been constructed. OPENED (1) The open() method has been successfully invoked. During this state request headers can be set using setRequestHeader() and the request can be made using the send() method. HEADERS_RECEIVED (2) All redirects (if any) have been followed and all HTTP headers of the final response have been received. Several response members of the object are now available. LOADING (3) The response entity body is being received. DONE (4) The data transfer has been completed or something went wrong during the transfer (e.g. infinite redirects).
43. Server: checks for updates for a few cycles and keeps a counter. If counter limit reached, 'false' or 'error' message goes back. If an update is available before that, exit the loop and return an 'ok' message with payload.
49. Objects (other then the ones being pulled/pushed) on server side can be changed, need to have these changes fed to the client. Piggybacking to the rescue again?
50. One or more long polling requests open and then an AJAX call: might give you browser problems with simultaneous requests
51. Server performance: we need event driven solutions (message queues and/or something like node.js) to fix this
52.
53. Thoughts & Notes Performance is the biggest problem A Comet server should be able to handle as much connections as fast as possible, with a high troughput and low latency. Long polling requests stay idle for a while, so claiming a thread is not ok.
72. Cometd/Bayeux Download distribution from: http://downloads.dojotoolkit.org/cometd/ $ tar zxvf cometd-1.1.4.tgz $ cd cometd-1.1.4/ $ cd cometd-1.1.4/ $ cd cometd-demo $ mvn jetty:deploy-war http://localhost:8080/ And a demo..
145. Conclusions Push! Go for a solution that bridges the gap while waiting for websockets and SSE Do keep an eye on the real-time web evolution. It will be here very (very) soon and will impact your job.