ctx_new moved and $st added to manage status value
[xynt.git] / web / test-hs-rd.php
1 <html>
2 <head>
3 <script type="text/javascript" src="xynt/xynt-console.js"></script>
4 <script type="text/javascript" src="xynt/xynt-http-streaming-ifra.js"></script>
5 <script type="text/javascript">
6 var http_streaming = "ready";
7
8 window.onload = function () { if (http_streaming != "ready") http_streaming.reload(); };
9 </script> 
10 </head>
11 <body onabort = "console.log('rd abort');" onunload = "console.log('rd unload');" onerror = "console.log('rd error');" onkeypress = "console.log('rd keypress');">
12 </body>
13 <?php
14 function mop_flush()
15 {
16     ob_flush();
17     flush();
18 }
19
20 function main()
21 {
22     $st = 0;
23     $fp = fopen("/tmp/test-hs-rd.log", "a");
24     fwrite($fp, "START\n");
25     fclose($fp);
26
27     $s = "";
28     for ($i = 0 ; $i < 4096 ; $i++) {
29         $s .= rand(65,90);
30     }
31
32     $to = rand(10,20);
33     for ($first = true, $i = $st+1 ; $i < $st+$to ; $i++, $first = false) {
34         // if ($i == 0)
35         //    sleep(1);
36      
37         if ($i == $st+8) {
38             // exit();
39             sleep(30);
40         }
41         printf("<script id='hs%d' type='text/javascript'>
42 push(\"$('cont').innerHTML += '%s %d';\");
43 </script>", $i, ($first ? "<br/>" : ""), $i);
44
45         if ($first)
46             printf("<!-- %s -->", $s);
47         mop_flush();
48         usleep(1000000);
49     }
50 }
51 main();
52 ?>
53 </html>