Short-polling vs Long-polling for real time web applications?

Just for the sake of argument. Both are http request (xhr), and its at least partially untrue it uses more server resources (depends totally on technology, will explain later). Short polling. Lot of request that are processed as they come on server. Creates a lot of traffic (uses resources, but frees them as soon as … Read more

jQuery read AJAX stream incrementally?

This is quite straightforward when outputting text or HTML. Below is an example. (You’ll run into issues if trying to output JSON however, which I’ll tackle further down.) PHP FILE header(‘Content-type: text/html; charset=utf-8’); function output($val) { echo $val; flush(); ob_flush(); usleep(500000); } output(‘Begin… (counting to 10)’); for( $i = 0 ; $i < 10 ; … Read more

What are Long-Polling, Websockets, Server-Sent Events (SSE) and Comet?

In the examples below the client is the browser and the server is the webserver hosting the website. Before you can understand these technologies, you have to understand classic HTTP web traffic first. Regular HTTP: A client requests a webpage from a server. The server calculates the response The server sends the response to the … Read more