2 foreach (array('isstream', 'f_test', 'f_trans', 'f_port', 'f_fback', 'sess', 'stat',
3 'subst', 'step', 'from', 'transp') as $i) {
4 if (isset($_REQUEST[$i])) {
9 $desc = array( "Semplice: da 1 a 9 ogni secondo, poi ricomincia (status sempre verde).",
10 "Continuo: da 1 a N ogni secondo, ricomincia ogni 9 (status sempre verde).",
11 "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).",
12 "Pausa: da 1 a 5 ogni secondo, pausa 3 secondi, e poi 8 e 9 ogni secondo, e poi ricomincia (status sempre verde).",
13 "Keyword: da 1 a 5 ogni secondo, @BEGIN@, @END@, @BEGIN@ xxx yyy @END@, 9, (status sempre verde).",
14 "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).",
15 "Esegue un comando, manda loc_new a un valore irraggiungibile, stoppa il processore di comandi e poi dà un comando teoricamente irraggiungibile.");
18 // trim(mb_convert_case($split[0], MB_CASE_TITLE, 'UTF-8'))
20 function headers_render($header, $len)
24 if (isset($header['Cookies'])) {
25 $cookies = $header['Cookies']->render();
26 unset($header['Cookies']);
28 if (isset($header['Location'])) {
29 header(sprintf("HTTP/1.1 302 OK\r\n%sLocation: %s", $cookies, $header['Location']));
31 else if (isset($header['HTTP-Response'])) {
32 header(sprintf("HTTP/1.1 %s", $header['HTTP-Response']));
33 foreach($header as $key => $value) {
34 if (strtolower($key) == "http-response")
36 header(sprintf("%s: %s", $key, $value));
39 header(sprintf("Content-Length: %ld", $len));
43 header("HTTP/1.1 200 OK\r\n");
45 if (!isset($header['Date']))
46 header(sprintf("Date: %s", date(DATE_RFC822)));
47 if (!isset($header['Connection']))
48 header("Connection: close");
49 if (!isset($header['Content-Type']))
50 header("Content-Type: text/html");
51 foreach($header as $key => $value) {
52 header(sprintf("%s: %s", $key, $value));
55 header(sprintf("Content-Length: %d", $len));
58 header("Cache-Control: no-cache, must-revalidate");
59 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
60 if (!isset($header['Content-Encoding'])) {
61 header("Content-Encoding: chunked");
63 header("Transfer-Encoding: chunked");
71 $transs = array( "iframe", "websocket", "websocketsec", "xhr", "htmlfile" );
72 $trans_ports = array( "iframe"=>80, "websocket"=>80, "websocketsec"=>443, "xhr"=>80, "htmlfile"=>80 );
74 $f_trans = $transs[0];
88 for ($i = 0; $i < ob_get_level(); $i++)
94 $escpush_from = array("\\", "\"");
95 $escpush_to = array("\\\\", "\\\"");
98 GLOBAL $escpush_from, $escpush_to;
100 return str_replace($escpush_from, $escpush_to, $s);
105 $from = array ( '\\', '@', '|' );
106 $to = array ( '\\\\', '@', '¦' );
108 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
111 if (isset($isstream) && $isstream == "true") {
112 require_once("Obj/transports.phh");
114 if (isset($transp) && $transp == "websocket") {
115 $trobj = new Transport_websocket();
117 else if (isset($transp) && $transp == "websocketsec") {
118 $trobj = new Transport_websocket(TRUE);
120 else if (isset($transp) && $transp == "xhr") {
121 $trobj = new Transport_xhr();
123 else if (isset($transp) && $transp == "htmlfile") {
124 $trobj = new Transport_htmlfile();
127 $trobj = new Transport_iframe();
129 $headers_out = array();
132 for ($i = 0 ; $i < 4096 ; $i++) {
136 $init_string .= chr(mt_rand(65, 90));
138 $headers_in = getallheaders();
139 // error_log(print_r($headers_in, TRUE));
141 foreach ($headers_in as $header_in => $value) {
142 $headers[mb_convert_case($header_in, MB_CASE_TITLE, 'UTF-8')] = $value;
144 $fp = fopen("/tmp/xynt.log", "a+");
145 fprintf($fp, "here we are\n");
148 $body = $trobj->init("plain", $headers, $headers_out, $init_string, "", "0");
150 if ($body === FALSE) {
151 $fp = fopen("/tmp/xynt.log", "a+");
152 fprintf($fp, "init failed\n");
156 $fp = fopen("/tmp/xynt.log", "a+");
157 fprintf($fp, "after_init [%s] [%s]\n", $transp, print_r($headers_out, TRUE));
158 fprintf($fp, "body [%s][%d]\n", $body, mb_strlen($body, "ASCII"));
162 if (isset($transp) && ($transp == "websocket" || $transp == "websocketsec")) {
163 header_remove('Connection');
164 header_remove('Content-Encoding');
165 header_remove('Content-Type');
166 header_remove('Date');
167 header_remove('Keep-Alive');
168 header_remove('Server');
169 header_remove('Transfer-Encoding');
170 header_remove('Vary');
171 header_remove('X-Powered-By');
173 headers_render($headers_out, 100);
178 $lnz += mb_strlen($body, "ASCII");
183 // from 1 to 9 into the innerHTML and than close
184 for ($i = 1 ; $i < 10 ; $i++) {
185 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
193 // from 1 to 9 into the innerHTML and than close
194 for ($i = 1 ; $i < 10 ; $i++) {
195 $chunk = $trobj->chunk($i, sprintf("gst.st++; \$('container').innerHTML = gst.st;"));
197 $lnz += mb_strlen($chunk, "ASCII");
203 // from 1 to 9 with 60 secs after 8, the client js api must restart stream after 12 secs
204 for ($i = 1 ; $i < 10 ; $i++) {
205 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
214 // from 1 to 9 into the innerHTML and than close
215 for ($i = 1 ; $i < 10 ; $i++) {
217 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
220 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';|sleep(gst,3000);", $i));
228 // from 1 to 9 into the innerHTML and than close
229 $cont = array('@BEGIN@', '@END@', '@BEGIN@ sleep(1); @END@');
230 for ($i = 1 ; $i < 10 ; $i++) {
235 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%s';", xcape($cont[$i - 6])));
238 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
248 // from 1 to 9 into the innerHTML and than close
250 $chunk = $trobj->chunk(1, sprintf("gst.st++; \$('container').innerHTML = gst.st;"));
252 // without this usleep the delay is doubled in iframe stream because
253 // no transp.xynt_streaming back-set is performed
258 for ($i = 1 ; $i < 10 ; $i++) {
259 $chunk = $trobj->chunk($i, sprintf("gst.st++; \$('container').innerHTML = gst.st;"));
268 $chunk = $trobj->chunk(1, sprintf("gst.st++; \$('container').innerHTML = 'prima';"));
271 $chunk = $trobj->chunk(2, sprintf("gst.st++; gst.st_loc_new++; xstm.stop();"));
274 $chunk = $trobj->chunk(3, sprintf("gst.st++; \$('container').innerHTML = 'dopo';"));
280 print($trobj->close());
288 <title>XYNT TEST01</title>
289 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
290 <script type="text/javascript" src="xynt-streaming.js"></script>
291 <script type="text/javascript" src="commons.js"></script>
292 <script type="text/javascript" src="heartbit.js"></script>
294 <!-- <script type="text/javascript" src="myconsole.js"></script> -->
296 <script type="text/javascript"><!--
297 var sess = "for_test";
300 var gst = new globst();
301 window.onload = function() {
303 xstm = new xynt_streaming(window, "<?php echo "$f_trans";?>", <?php
304 echo ($f_port == NULL ? "${trans_ports[$f_trans]}" : "$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);});
305 xstm.hbit_set(heartbit);
316 for ($test = 1 ; $test <= count($desc) ; $test++) {
318 foreach ($transs as $trans) {
319 printf("<td style=\"padding: 8px; border: 1px solid black;\"><a href=\"?f_trans=%s&f_test=%d%s&f_fback=%d\">Test %s %02d (port %d (fb %d))</a></td>", $trans, $test,
320 ($f_port == NULL ? "" : sprintf("&f_port=%d", $f_port)), $f_fback, $trans, $test,
321 ($f_port == NULL ? $trans_ports[$trans] : $f_port ), $f_fback);
325 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));
327 printf("<br>[%s]<br>Test: %d<br>", $f_trans, $f_test);
331 <b>Descrizione</b>: <?php echo $desc[$f_test - 1]; ?>
335 <b>Status</b>: <img id="stm_stat" class="nobo" style="vertical-align: bottom;" src="img/line-status_b.png"></div>
339 <b>Counter</b>: <span id="container">