1<!doctype html> 2<html> 3<head> 4<title>EventSource Loader Buffering</title> 5<script> 6window.onload = function () { 7 setTimeout(test_es, 500); 8}; 9 10function test_es() { 11 var len = 0; 12 var count = 0; 13 var step = 1000; 14 var es = new EventSource("eventsource-loader-buffering.php"); 15 es.onopen = function () { 16 log("got 'open' event"); 17 log("waiting for the first " + step + " 'message' events"); 18 }; 19 es.onmessage = function (evt) { 20 len += evt.data.length; 21 if (++count % step) 22 return; 23 log("got " + count + " 'message' events (" + len + " characters)", 1); 24 if (len >= 1e9) 25 end(); 26 }; 27 es.onerror = function () { 28 log("got 'error' event"); 29 end(); 30 }; 31 function end() { 32 if (es.readyState != es.CLOSED) 33 es.close(); 34 log("ENDED"); 35 }; 36} 37 38function log(message, updateLast) { 39 if (!log.list) 40 log.list = document.getElementById("log"); 41 var text = document.createTextNode(message); 42 if (updateLast) 43 log.list.lastChild.replaceChild(text, log.list.lastChild.firstChild); 44 else 45 log.list.appendChild(document.createElement("li")).appendChild(text); 46} 47</script> 48</head> 49<body> 50<p>Manual test to verify that the EventSource loader does not buffer data (may result in memory growth with long lived connections). Monitor memory usage; it should be stable. This file has to be served from the same web server as the php script with the same name.</p> 51<ul id="log" style="list-style-type: none"></ul> 52</body> 53</html> 54 55