keemor.com - Surfin' JavaScript Wave

Simple HTTP Streaming design pattern

If you want to stream server data in the response of a long-lived HTTP connection you can use HTTP Streaming design pattern.

Check out simple DEMO »


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head id="my-head">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>keemor.com - Simple HTTP Streaming design pattern</title>
	</head>
<body>
	Counter: <span id="counter"></span>	
</body>
</html>


<?php
for ( $counter = 0; $counter <= 10; $counter++) {
	?>
	<script type="text/javascript">
		document.getElementById('counter').innerHTML = "<?= $counter ?>";
	</script>		
	<?
	flush();
	sleep(3);
}
?>