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).");
11 // trim(mb_convert_case($split[0], MB_CASE_TITLE, 'UTF-8'))
13 function headers_render($header, $len)
17 if (isset($header['Cookies'])) {
18 $cookies = $header['Cookies']->render();
19 unset($header['Cookies']);
21 if (isset($header['Location'])) {
22 header(sprintf("HTTP/1.1 302 OK\r\n%sLocation: %s", $cookies, $header['Location']));
24 else if (isset($header['HTTP-Response'])) {
25 header(sprintf("HTTP/1.1 %s", $header['HTTP-Response']));
26 foreach($header as $key => $value) {
27 if (strtolower($key) == "http-response")
29 header(sprintf("%s: %s", $key, $value));
32 header(sprintf("Content-Length: %ld", $len));
36 header("HTTP/1.1 200 OK\r\n");
38 if (!isset($header['Date']))
39 header(sprintf("Date: %s", date(DATE_RFC822)));
40 if (!isset($header['Connection']))
41 header("Connection: close");
42 if (!isset($header['Content-Type']))
43 header("Content-Type: text/html");
44 foreach($header as $key => $value) {
45 header(sprintf("%s: %s", $key, $value));
48 header(sprintf("Content-Length: %d", $len));
51 header("Cache-Control: no-cache, must-revalidate");
52 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
53 if (!isset($header['Content-Encoding'])) {
54 header("Content-Encoding: chunked");
56 header("Transfer-Encoding: chunked");
64 $transs = array( "iframe", "websocket", "xhr", "htmlfile" );
66 $f_trans = $transs[0];
80 for ($i = 0; $i < ob_get_level(); $i++)
86 $escpush_from = array("\\", "\"");
87 $escpush_to = array("\\\\", "\\\"");
90 GLOBAL $escpush_from, $escpush_to;
92 return str_replace($escpush_from, $escpush_to, $s);
97 $from = array ( '\\', '@', '|' );
98 $to = array ( '\\\\', '@', '¦' );
100 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
103 if (isset($isstream) && $isstream == "true") {
105 require_once("Obj/transports.phh");
107 if (isset($transp) && $transp == "websocket") {
108 $trobj = new Transport_websocket();
110 else if (isset($transp) && $transp == "xhr") {
111 $trobj = new Transport_xhr();
113 else if (isset($transp) && $transp == "htmlfile") {
114 $trobj = new Transport_htmlfile();
117 $trobj = new Transport_iframe();
119 $headers_out = array();
122 for ($i = 0 ; $i < 4096 ; $i++) {
126 $init_string .= chr(mt_rand(65, 90));
128 $headers_in = getallheaders();
130 foreach ($headers_in as $header_in => $value) {
131 $headers[mb_convert_case($header_in, MB_CASE_TITLE, 'UTF-8')] = $value;
133 $fp = fopen("/tmp/xynt.log", "a+");
134 fprintf($fp, "here we are\n");
137 $body = $trobj->init("plain", $headers, $headers_out, $init_string, "", "0");
139 if ($body === FALSE) {
140 $fp = fopen("/tmp/xynt.log", "a+");
141 fprintf($fp, "init failed\n");
145 $fp = fopen("/tmp/xynt.log", "a+");
146 fprintf($fp, "after_init [%s] [%s]\n", $transp, print_r($headers_out, TRUE));
147 fprintf($fp, "body [%s][%d]\n", $body, mb_strlen($body, "ASCII"));
151 if (isset($transp) && $transp == "websocket") {
152 header_remove('Connection');
153 header_remove('Content-Encoding');
154 header_remove('Content-Type');
155 header_remove('Date');
156 header_remove('Keep-Alive');
157 header_remove('Server');
158 header_remove('Transfer-Encoding');
159 header_remove('Vary');
160 header_remove('X-Powered-By');
162 headers_render($headers_out, 100);
167 $lnz += mb_strlen($body, "ASCII");
172 // from 1 to 9 into the innerHTML and than close
173 for ($i = 1 ; $i < 10 ; $i++) {
174 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
182 // from 1 to 9 into the innerHTML and than close
183 for ($i = 1 ; $i < 10 ; $i++) {
184 $chunk = $trobj->chunk($i, sprintf("gst.st++; \$('container').innerHTML = gst.st;"));
186 $lnz += mb_strlen($chunk, "ASCII");
192 // from 1 to 9 with 60 secs after 8, the client js api must restart stream after 12 secs
193 for ($i = 1 ; $i < 10 ; $i++) {
194 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
203 // from 1 to 9 into the innerHTML and than close
204 for ($i = 1 ; $i < 10 ; $i++) {
206 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
209 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';|sleep(gst,3000);", $i));
217 // from 1 to 9 into the innerHTML and than close
218 $cont = array('@BEGIN@', '@END@', '@BEGIN@ sleep(1); @END@');
219 for ($i = 1 ; $i < 10 ; $i++) {
224 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%s';", xcape($cont[$i - 6])));
227 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
237 // from 1 to 9 into the innerHTML and than close
239 $chunk = $trobj->chunk(1, sprintf("gst.st++; \$('container').innerHTML = gst.st;"));
241 // without this usleep the delay is doubled in iframe stream because
242 // no transp.xynt_streaming back-set is performed
247 for ($i = 1 ; $i < 10 ; $i++) {
248 $chunk = $trobj->chunk($i, sprintf("gst.st++; \$('container').innerHTML = gst.st;"));
258 print($trobj->close());
266 <title>XYNT TEST01</title>
267 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
268 <script type="text/javascript" src="xynt-streaming.js"></script>
269 <script type="text/javascript" src="commons.js"></script>
270 <script type="text/javascript" src="heartbit.js"></script>
272 <!-- <script type="text/javascript" src="myconsole.js"></script> -->
274 <script type="text/javascript"><!--
275 var sess = "for_test";
278 var gst = new globst();
279 window.onload = function() {
281 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);});
282 xstm.hbit_set(heartbit);
295 for ($test = 1 ; $test <= count($desc) ; $test++) {
297 foreach ($transs as $trans) {
298 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);
302 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));
304 printf("<br>[%s]<br>Test: %d<br>", $f_trans, $f_test);
308 <b>Descrizione</b>: <?php echo $desc[$f_test - 1]; ?>
312 <b>Status</b>: <img id="stm_stat" class="nobo" style="vertical-align: bottom;" src="img/line-status_b.png"></div>
316 <b>Counter</b>: <span id="container">