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];
74 for ($i = 0; $i < ob_get_level(); $i++)
80 $escpush_from = array("\\", "\"");
81 $escpush_to = array("\\\\", "\\\"");
84 GLOBAL $escpush_from, $escpush_to;
86 return str_replace($escpush_from, $escpush_to, $s);
91 $from = array ( '\\', '@', '|' );
92 $to = array ( '\\\\', '@', '¦' );
94 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
97 if (isset($isstream) && $isstream == "true") {
99 require_once("Obj/transports.phh");
101 if (isset($transp) && $transp == "websocket") {
102 $trobj = new Transport_websocket();
104 else if (isset($transp) && $transp == "xhr") {
105 $trobj = new Transport_xhr();
107 else if (isset($transp) && $transp == "htmlfile") {
108 $trobj = new Transport_htmlfile();
111 $trobj = new Transport_iframe();
113 $headers_out = array();
116 for ($i = 0 ; $i < 4096 ; $i++) {
120 $init_string .= chr(mt_rand(65, 90));
122 $headers_in = getallheaders();
124 foreach ($headers_in as $header_in => $value) {
125 $headers[mb_convert_case($header_in, MB_CASE_TITLE, 'UTF-8')] = $value;
127 $fp = fopen("/tmp/xynt.log", "a+");
128 fprintf($fp, "here we are\n");
131 $body = $trobj->init("plain", $headers, $headers_out, $init_string, "", "0");
133 if ($body === FALSE) {
134 $fp = fopen("/tmp/xynt.log", "a+");
135 fprintf($fp, "init failed\n");
139 $fp = fopen("/tmp/xynt.log", "a+");
140 fprintf($fp, "after_init [%s] [%s]\n", $transp, print_r($headers_out, TRUE));
141 fprintf($fp, "body [%s][%d]\n", $body, mb_strlen($body, "ASCII"));
145 if (isset($transp) && $transp == "websocket") {
146 header_remove('Connection');
147 header_remove('Content-Encoding');
148 header_remove('Content-Type');
149 header_remove('Date');
150 header_remove('Keep-Alive');
151 header_remove('Server');
152 header_remove('Transfer-Encoding');
153 header_remove('Vary');
154 header_remove('X-Powered-By');
156 headers_render($headers_out, 100);
161 $lnz += mb_strlen($body, "ASCII");
166 // from 1 to 9 into the innerHTML and than close
167 for ($i = 1 ; $i < 10 ; $i++) {
168 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
176 // from 1 to 9 into the innerHTML and than close
177 for ($i = 1 ; $i < 10 ; $i++) {
178 $chunk = $trobj->chunk($i, sprintf("gst.st++; \$('container').innerHTML = gst.st;"));
180 $lnz += mb_strlen($chunk, "ASCII");
186 // from 1 to 9 with 60 secs after 8, the client js api must restart stream after 12 secs
187 for ($i = 1 ; $i < 10 ; $i++) {
188 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
197 // from 1 to 9 into the innerHTML and than close
198 for ($i = 1 ; $i < 10 ; $i++) {
200 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
203 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';|sleep(gst,3000);", $i));
211 // from 1 to 9 into the innerHTML and than close
212 $cont = array('@BEGIN@', '@END@', '@BEGIN@ sleep(1); @END@');
213 for ($i = 1 ; $i < 10 ; $i++) {
218 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%s';", xcape($cont[$i - 6])));
221 $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
231 // from 1 to 9 into the innerHTML and than close
233 $chunk = $trobj->chunk(1, sprintf("gst.st++; \$('container').innerHTML = gst.st;"));
235 // without this usleep the delay is doubled in iframe stream because
236 // no transp.xynt_streaming back-set is performed
241 for ($i = 1 ; $i < 10 ; $i++) {
242 $chunk = $trobj->chunk($i, sprintf("gst.st++; \$('container').innerHTML = gst.st;"));
252 print($trobj->close());
260 <title>XYNT TEST01</title>
261 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
262 <script type="text/javascript" src="xynt-streaming.js"></script>
263 <script type="text/javascript" src="commons.js"></script>
264 <script type="text/javascript" src="heartbit.js"></script>
266 <!-- <script type="text/javascript" src="myconsole.js"></script> -->
268 <script type="text/javascript"><!--
269 var sess = "for_test";
272 var gst = new globst();
273 window.onload = function() {
275 xstm = new xynt_streaming(window, "<?php echo "$f_trans";?>", 80, 0, null /* console */, gst, 'xynt_test01_php', 'sess', sess, null, 'xynt_test01.php?isstream=true&f_test=<?php echo "$f_test";?>', function(com){eval(com);});
276 xstm.hbit_set(heartbit);
289 for ($test = 1 ; $test <= count($desc) ; $test++) {
291 foreach ($transs as $trans) {
292 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);
297 printf("<br>[%s]<br>Test: %d<br>", $f_trans, $f_test);
301 <b>Descrizione</b>: <?php echo $desc[$f_test - 1]; ?>
305 <b>Status</b>: <img id="stm_stat" class="nobo" style="vertical-align: bottom;" src="img/line-status_b.png"></div>
309 <b>Counter</b>: <span id="container">