some fixes for xhr and iframe transport came to light after hunged stream test was...
[brisk.git] / web / xynt_test01.php
1 <?php
2
3 $transs = array( "iframe", "xhr", "htmlfile" );
4 if (!isset($f_trans))
5     $f_trans = $transs[0];
6
7 if (!isset($f_test))
8     $f_test = 1;
9
10
11 function mop_flush()
12 {
13     for ($i = 0; $i < ob_get_level(); $i++)
14         ob_end_flush();
15     ob_implicit_flush(1);
16     flush();
17 }
18
19 $escpush_from = array("\\", "\"");
20 $escpush_to   = array("\\\\", "\\\"");
21 function escpush($s)
22 {
23     GLOBAL $escpush_from, $escpush_to;
24
25     return str_replace($escpush_from, $escpush_to, $s);
26 }
27
28 if ($isstream == "true") {
29
30     require_once("Obj/transports.phh");
31
32
33     if (isset($transp) && $transp == "xhr") {
34         $transp = new Transport_xhr();
35     }
36     else if (isset($transp) && $transp == "htmlfile") {
37         $transp = new Transport_htmlfile();
38     }
39     else {
40         $transp = new Transport_iframe();
41     }
42     $header_out = array();
43
44     $init_string = "";
45     for ($i = 0 ; $i < 4096 ; $i++) {
46         if (($i % 128) == 0)
47             $init_string .= " ";
48         else
49             $init_string .= chr(mt_rand(65, 90));
50     }
51
52     $body = $transp->init("plain", $header_out, $init_string, "", "0");
53
54     foreach ($header_out as $key => $value) {
55         header(sprintf("%s: %s", $key, $value));
56     }
57     print($body);
58     mop_flush();
59
60     switch ($f_test) {
61     case 1:
62         // from 1 to 9 into the innerHTML and than close
63         for ($i = 1 ; $i < 10 ; $i++) {
64             $chunk = $transp->chunk($i, sprintf("\$('container').innerHTML = 'xx%d';", $i));
65             print($chunk);
66             mop_flush();
67             sleep(1);
68         }
69         break;
70     case 2:
71         // from 1 to 9 with 60 secs after 8, the client js api must restart stream after 12 secs
72         for ($i = 1 ; $i < 10 ; $i++) {
73             $chunk = $transp->chunk($i, sprintf("\$('container').innerHTML = 'yy%d';", $i));
74             print($chunk);
75             mop_flush();
76             sleep(1);
77             if ($i == 8)
78                 sleep(60);
79         }
80         break;
81     }
82     exit;
83 }
84 ?>
85 <html>
86 <head>
87 <title>XYNT TEST01</title>
88 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
89 <script type="text/javascript" src="xynt-streaming.js"></script>
90 <script type="text/javascript" src="commons.js"></script>
91
92 <!-- <script type="text/javascript" src="myconsole.js"></script> -->
93
94 <script type="text/javascript"><!--
95      var sess = "for_test";
96      var stat = "";
97      var subst = "";
98      var gst = new globst();
99      window.onload = function() {
100
101      xstm = new xynt_streaming(window, "<?php echo "$f_trans";?>", null /* console */, gst, 'xynt_test01_php', 'sess', sess, null, 'xynt_test01.php?isstream=true&f_test=<?php echo "$f_test";?>', function(com){eval(com);});
102      /*     xstm.hbit_set(heartbit); */
103      xstm.start();
104  }
105  //-->
106 </script>
107 </head>
108 <body>
109 <div>
110 <?php
111
112 printf("<table>");
113 for ($test = 1 ; $test <= 2 ; $test++) {
114     printf("<tr>");
115     foreach ($transs as $trans) {
116         printf("<td style=\"padding: 8px; border: 1px solid black;\"><a href=\"?f_trans=%s&f_test=%d\">Test %s %02d</a></td>", $trans, $test, $trans, $test);
117     }
118     printf("</tr>\n");
119 }
120 printf("</table>");
121 printf("<br>[%s]<br>Test: %d<br>", $f_trans, $f_test);
122 ?>
123 </div>
124 <div id="container">
125 BEGIN
126 </div>
127 </body>
128 </html>