3 $desc = array( "Semplice: da 1 a 9 ogni secondo, poi ricomincia (status sempre verde).",
4 "Continuo: da 1 a N ogni secondo, ricomincia ogni 9 (status sempre verde).",
5 "Restart: da 1 a 8 ogni secondo, pausa 16 secondi (status passa ad arancione e poi a rosso), poi ricomincia (e status torna a verde).",
6 "Pausa: da 1 a 5 ogni secondo, pausa 3 secondi, e poi 8 e 9 ogni secondo, e poi ricomincia (status sempre verde).",
7 "Keyword: da 1 a 5 ogni secondo, @BEGIN@, @END@, @BEGIN@ xxx yyy @END@, 9, (status sempre verde).",
8 "Reload limiter: da 1 a 8 ogni secondo e chiude, 9 setta e chiude subito,<br>il client aspetta 3 secondi, e poi da 10 a N ogni secondo, (status sempre verde).",
9 "Esegue un comando, manda loc_new a un valore irraggiungibile, stoppa il processore di comandi e poi dà un comando teoricamente irraggiungibile.");
12 // trim(mb_convert_case($split[0], MB_CASE_TITLE, 'UTF-8'))
14 function headers_render($header, $len)
18 if (isset($header['Cookies'])) {
19 $cookies = $header['Cookies']->render();
20 unset($header['Cookies']);
22 if (isset($header['Location'])) {
23 header(sprintf("HTTP/1.1 302 OK\r\n%sLocation: %s", $cookies, $header['Location']));
25 else if (isset($header['HTTP-Response'])) {
26 header(sprintf("HTTP/1.1 %s", $header['HTTP-Response']));
27 foreach($header as $key => $value) {
28 if (strtolower($key) == "http-response")
30 header(sprintf("%s: %s", $key, $value));
33 header(sprintf("Content-Length: %ld", $len));
37 header("HTTP/1.1 200 OK\r\n");
39 if (!isset($header['Date']))
40 header(sprintf("Date: %s", date(DATE_RFC822)));
41 if (!isset($header['Connection']))
42 header("Connection: close");
43 if (!isset($header['Content-Type']))
44 header("Content-Type: text/html");
45 foreach($header as $key => $value) {
46 header(sprintf("%s: %s", $key, $value));
49 header(sprintf("Content-Length: %d", $len));
52 header("Cache-Control: no-cache, must-revalidate");
53 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
54 if (!isset($header['Content-Encoding'])) {
55 header("Content-Encoding: chunked");
57 header("Transfer-Encoding: chunked");
65 $transs = array( "iframe", "websocket", "xhr", "htmlfile" );
67 $f_trans = $transs[0];
81 for ($i = 0; $i < ob_get_level(); $i++)
87 $escpush_from = array("\\", "\"");
88 $escpush_to = array("\\\\", "\\\"");
91 GLOBAL $escpush_from, $escpush_to;
93 return str_replace($escpush_from, $escpush_to, $s);
98 $from = array ( '\\', '@', '|' );
99 $to = array ( '\\\\', '@', '¦' );
101 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
104 if (isset($isstream) && $isstream == "true") {
106 require_once("Obj/transports.phh");
108 if (isset($transp) && $transp == "websocket") {
109 $trobj = new Transport_websocket();
111 else if (isset($transp) && $transp == "xhr") {
112 $trobj = new Transport_xhr();
114 else if (isset($transp) && $transp == "htmlfile") {
115 $trobj = new Transport_htmlfile();
118 $trobj = new Transport_iframe();
120 $headers_out = array();
123 for ($i = 0 ; $i < 4096 ; $i++) {
127 $init_string .= chr(mt_rand(65, 90));
129 $headers_in = getallheaders();
131 foreach ($headers_in as $header_in => $value) {
132 $headers[mb_convert_case($header_in, MB_CASE_TITLE, 'UTF-8')] = $value;
134 $fp = fopen("/tmp/xynt.log", "a+");
135 fprintf($fp, "here we are\n");
138 $body = $trobj->init("plain", $headers, $headers_out, $init_string, "", "0");
140 if ($body === FALSE) {
141 $fp = fopen("/tmp/xynt.log", "a+");
142 fprintf($fp, "init failed\n");
146 $fp = fopen("/tmp/xynt.log", "a+");
147 fprintf($fp, "after_init [%s] [%s]\n", $transp, print_r($headers_out, TRUE));
148 fprintf($fp, "body [%s][%d]\n", $body, mb_strlen($body, "ASCII"));
152 if (isset($transp) && $transp == "websocket") {
153 header_remove('Connection');
154 header_remove('Content-Encoding');
155 header_remove('Content-Type');
156 header_remove('Date');
157 header_remove('Keep-Alive');
158 header_remove('Server');
159 header_remove('Transfer-Encoding');
160 header_remove('Vary');
161 header_remove('X-Powered-By');
163 headers_render($headers_out, 100);
168 $lnz += mb_strlen($body, "ASCII");
173 // from 1 to 9 into the innerHTML and than close
174 for ($i = 1 ; $i < 10 ; $i++) {
175 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
183 // from 1 to 9 into the innerHTML and than close
184 for ($i = 1 ; $i < 10 ; $i++) {
185 $chunk = $trobj->chunk($i, sprintf("gst.st++; \$('container').innerHTML = gst.st;"));
187 $lnz += mb_strlen($chunk, "ASCII");
193 // from 1 to 9 with 60 secs after 8, the client js api must restart stream after 12 secs
194 for ($i = 1 ; $i < 10 ; $i++) {
195 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
204 // from 1 to 9 into the innerHTML and than close
205 for ($i = 1 ; $i < 10 ; $i++) {
207 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
210 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';|sleep(gst,3000);", $i));
218 // from 1 to 9 into the innerHTML and than close
219 $cont = array('@BEGIN@', '@END@', '@BEGIN@ sleep(1); @END@');
220 for ($i = 1 ; $i < 10 ; $i++) {
225 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%s';", xcape($cont[$i - 6])));
228 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
238 // from 1 to 9 into the innerHTML and than close
240 $chunk = $trobj->chunk(1, sprintf("gst.st++; \$('container').innerHTML = gst.st;"));
242 // without this usleep the delay is doubled in iframe stream because
243 // no transp.xynt_streaming back-set is performed
248 for ($i = 1 ; $i < 10 ; $i++) {
249 $chunk = $trobj->chunk($i, sprintf("gst.st++; \$('container').innerHTML = gst.st;"));
258 $chunk = $trobj->chunk(1, sprintf("gst.st++; \$('container').innerHTML = 'prima';"));
261 $chunk = $trobj->chunk(2, sprintf("gst.st++; gst.st_loc_new++; xstm.stop();"));
264 $chunk = $trobj->chunk(3, sprintf("gst.st++; \$('container').innerHTML = 'dopo';"));
270 print($trobj->close());
278 <title>XYNT TEST01</title>
279 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
280 <script type="text/javascript" src="xynt-streaming.js"></script>
281 <script type="text/javascript" src="commons.js"></script>
282 <script type="text/javascript" src="heartbit.js"></script>
284 <!-- <script type="text/javascript" src="myconsole.js"></script> -->
286 <script type="text/javascript"><!--
287 var sess = "for_test";
290 var gst = new globst();
291 window.onload = function() {
293 xstm = new xynt_streaming(window, "<?php echo "$f_trans";?>", <?php echo "$f_port";?>, <?php echo "$f_fback";?>, console, gst, 'xynt_test01_php', 'sess', sess, null, 'xynt_test01.php?isstream=true&f_test=<?php echo "$f_test";?>', function(com){eval(com);});
294 xstm.hbit_set(heartbit);
307 for ($test = 1 ; $test <= count($desc) ; $test++) {
309 foreach ($transs as $trans) {
310 printf("<td style=\"padding: 8px; border: 1px solid black;\"><a href=\"?f_trans=%s&f_test=%d&f_port=%d&f_fback=%d\">Test %s %02d (port %d (fb %d))</a></td>", $trans, $test, $f_port, $f_fback, $trans, $test, $f_port, $f_fback);
314 printf("<tr><td style=\"padding: 8px; border: 1px solid black; text-align: center;\" colspan='%d'><a href='#' onclick=\"xstm.abort(); \">STOP</a></td></tr>", count($transs));
316 printf("<br>[%s]<br>Test: %d<br>", $f_trans, $f_test);
320 <b>Descrizione</b>: <?php echo $desc[$f_test - 1]; ?>
324 <b>Status</b>: <img id="stm_stat" class="nobo" style="vertical-align: bottom;" src="img/line-status_b.png"></div>
328 <b>Counter</b>: <span id="container">