X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2Fxynt_test01.php;h=4c1c43bab19cfbb44071ae5bb3b2afee4a30f431;hb=a06e072cbc877921263a20150915ad09fc79d260;hp=f9efb7b35376421b61a93d3b332dda9e99ad0ae6;hpb=93f201e82b6497b86245817a170904151b6b06ac;p=brisk.git
diff --git a/web/xynt_test01.php b/web/xynt_test01.php
index f9efb7b..4c1c43b 100644
--- a/web/xynt_test01.php
+++ b/web/xynt_test01.php
@@ -1,20 +1,87 @@
il client aspetta 3 secondi, e poi da 10 a N ogni secondo, (status sempre verde).");
+ "Reload limiter: da 1 a 8 ogni secondo e chiude, 9 setta e chiude subito,
il client aspetta 3 secondi, e poi da 10 a N ogni secondo, (status sempre verde).",
+ "Esegue un comando, manda loc_new a un valore irraggiungibile, stoppa il processore di comandi e poi dà un comando teoricamente irraggiungibile.");
+
+
+// trim(mb_convert_case($split[0], MB_CASE_TITLE, 'UTF-8'))
+
+function headers_render($header, $len)
+{
+ $cookies = "";
+
+ if (isset($header['Cookies'])) {
+ $cookies = $header['Cookies']->render();
+ unset($header['Cookies']);
+ }
+ if (isset($header['Location'])) {
+ header(sprintf("HTTP/1.1 302 OK\r\n%sLocation: %s", $cookies, $header['Location']));
+ }
+ else if (isset($header['HTTP-Response'])) {
+ header(sprintf("HTTP/1.1 %s", $header['HTTP-Response']));
+ foreach($header as $key => $value) {
+ if (strtolower($key) == "http-response")
+ continue;
+ header(sprintf("%s: %s", $key, $value));
+ }
+ if ($len >= 0) {
+ header(sprintf("Content-Length: %ld", $len));
+ }
+ }
+ else {
+ header("HTTP/1.1 200 OK\r\n");
+ if (!isset($header['Date']))
+ header(sprintf("Date: %s", date(DATE_RFC822)));
+ if (!isset($header['Connection']))
+ header("Connection: close");
+ if (!isset($header['Content-Type']))
+ header("Content-Type: text/html");
+ foreach($header as $key => $value) {
+ header(sprintf("%s: %s", $key, $value));
+ }
+ if ($len >= 0) {
+ header(sprintf("Content-Length: %d", $len));
+ }
+ else {
+ header("Cache-Control: no-cache, must-revalidate");
+ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+ if (!isset($header['Content-Encoding'])) {
+ header("Content-Encoding: chunked");
+ }
+ header("Transfer-Encoding: chunked");
+ }
+ header($cookies);
+ }
-$transs = array( "iframe", "xhr", "htmlfile" );
+ return (TRUE);
+}
+
+$transs = array( "iframe", "websocket", "websocketsec", "xhr", "htmlfile" );
+$trans_ports = array( "iframe"=>80, "websocket"=>80, "websocketsec"=>443, "xhr"=>80, "htmlfile"=>80 );
if (!isset($f_trans))
$f_trans = $transs[0];
if (!isset($f_test))
$f_test = 1;
+if (!isset($f_port))
+ $f_port = NULL;
+
+if (!isset($f_fback))
+ $f_fback = 0;
+
function mop_flush()
{
@@ -41,21 +108,25 @@ function xcape($s)
return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
}
-if ($isstream == "true") {
-
+if (isset($isstream) && $isstream == "true") {
require_once("Obj/transports.phh");
-
- if (isset($transp) && $transp == "xhr") {
- $transp = new Transport_xhr();
+ if (isset($transp) && $transp == "websocket") {
+ $trobj = new Transport_websocket();
+ }
+ else if (isset($transp) && $transp == "websocketsec") {
+ $trobj = new Transport_websocket(TRUE);
+ }
+ else if (isset($transp) && $transp == "xhr") {
+ $trobj = new Transport_xhr();
}
else if (isset($transp) && $transp == "htmlfile") {
- $transp = new Transport_htmlfile();
+ $trobj = new Transport_htmlfile();
}
else {
- $transp = new Transport_iframe();
+ $trobj = new Transport_iframe();
}
- $header_out = array();
+ $headers_out = array();
$init_string = "";
for ($i = 0 ; $i < 4096 ; $i++) {
@@ -64,30 +135,66 @@ if ($isstream == "true") {
else
$init_string .= chr(mt_rand(65, 90));
}
+ $headers_in = getallheaders();
+ // error_log(print_r($headers_in, TRUE));
+ $headers = array();
+ foreach ($headers_in as $header_in => $value) {
+ $headers[mb_convert_case($header_in, MB_CASE_TITLE, 'UTF-8')] = $value;
+ }
+ $fp = fopen("/tmp/xynt.log", "a+");
+ fprintf($fp, "here we are\n");
+ fclose($fp);
+
+ $body = $trobj->init("plain", $headers, $headers_out, $init_string, "", "0");
+
+ if ($body === FALSE) {
+ $fp = fopen("/tmp/xynt.log", "a+");
+ fprintf($fp, "init failed\n");
+ fclose($fp);
+ }
+ else {
+ $fp = fopen("/tmp/xynt.log", "a+");
+ fprintf($fp, "after_init [%s] [%s]\n", $transp, print_r($headers_out, TRUE));
+ fprintf($fp, "body [%s][%d]\n", $body, mb_strlen($body, "ASCII"));
+ fclose($fp);
+ }
- $body = $transp->init("plain", $header_out, $init_string, "", "0");
+ if (isset($transp) && ($transp == "websocket" || $transp == "websocketsec")) {
+ header_remove('Connection');
+ header_remove('Content-Encoding');
+ header_remove('Content-Type');
+ header_remove('Date');
+ header_remove('Keep-Alive');
+ header_remove('Server');
+ header_remove('Transfer-Encoding');
+ header_remove('Vary');
+ header_remove('X-Powered-By');
- foreach ($header_out as $key => $value) {
- header(sprintf("%s: %s", $key, $value));
+ headers_render($headers_out, 100);
}
+ $lnz = 0;
+
print($body);
+ $lnz += mb_strlen($body, "ASCII");
mop_flush();
switch ($f_test) {
case 1:
// from 1 to 9 into the innerHTML and than close
for ($i = 1 ; $i < 10 ; $i++) {
- $chunk = $transp->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
+ $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
print($chunk);
mop_flush();
sleep(1);
}
+
break;
case 2:
// from 1 to 9 into the innerHTML and than close
for ($i = 1 ; $i < 10 ; $i++) {
- $chunk = $transp->chunk($i, sprintf("gst.st++; \$('container').innerHTML = gst.st;"));
+ $chunk = $trobj->chunk($i, sprintf("gst.st++; \$('container').innerHTML = gst.st;"));
print($chunk);
+ $lnz += mb_strlen($chunk, "ASCII");
mop_flush();
sleep(1);
}
@@ -95,7 +202,7 @@ if ($isstream == "true") {
case 3:
// from 1 to 9 with 60 secs after 8, the client js api must restart stream after 12 secs
for ($i = 1 ; $i < 10 ; $i++) {
- $chunk = $transp->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
+ $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
print($chunk);
mop_flush();
sleep(1);
@@ -107,10 +214,10 @@ if ($isstream == "true") {
// from 1 to 9 into the innerHTML and than close
for ($i = 1 ; $i < 10 ; $i++) {
if ($i != 5) {
- $chunk = $transp->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
+ $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
}
else {
- $chunk = $transp->chunk($i, sprintf("\$('container').innerHTML = '%d';|sleep(gst,3000);", $i));
+ $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';|sleep(gst,3000);", $i));
}
print($chunk);
mop_flush();
@@ -125,10 +232,10 @@ if ($isstream == "true") {
case 6:
case 7:
case 8:
- $chunk = $transp->chunk($i, sprintf("\$('container').innerHTML = '%s';", xcape($cont[$i - 6])));
+ $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%s';", xcape($cont[$i - 6])));
break;
default:
- $chunk = $transp->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
+ $chunk = $trobj->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
break;
}
print($chunk);
@@ -140,7 +247,7 @@ if ($isstream == "true") {
case 6:
// from 1 to 9 into the innerHTML and than close
if ($step == 8) {
- $chunk = $transp->chunk(1, sprintf("gst.st++; \$('container').innerHTML = gst.st;"));
+ $chunk = $trobj->chunk(1, sprintf("gst.st++; \$('container').innerHTML = gst.st;"));
print($chunk);
// without this usleep the delay is doubled in iframe stream because
// no transp.xynt_streaming back-set is performed
@@ -149,15 +256,30 @@ if ($isstream == "true") {
}
else {
for ($i = 1 ; $i < 10 ; $i++) {
- $chunk = $transp->chunk($i, sprintf("gst.st++; \$('container').innerHTML = gst.st;"));
+ $chunk = $trobj->chunk($i, sprintf("gst.st++; \$('container').innerHTML = gst.st;"));
print($chunk);
mop_flush();
if ($i < 9)
sleep(1);
}
}
+ break;
+ case 7:
+ $chunk = $trobj->chunk(1, sprintf("gst.st++; \$('container').innerHTML = 'prima';"));
+ print($chunk);
+
+ $chunk = $trobj->chunk(2, sprintf("gst.st++; gst.st_loc_new++; xstm.stop();"));
+ print($chunk);
+
+ $chunk = $trobj->chunk(3, sprintf("gst.st++; \$('container').innerHTML = 'dopo';"));
+ print($chunk);
+
break;
}
+
+ print($trobj->close());
+ mop_flush();
+
exit;
}
?>
@@ -178,7 +300,8 @@ if ($isstream == "true") {
var gst = new globst();
window.onload = function() {
- xstm = new xynt_streaming(window, "", null /* console */, gst, 'xynt_test01_php', 'sess', sess, null, 'xynt_test01.php?isstream=true&f_test=', function(com){eval(com);});
+ xstm = new xynt_streaming(window, "", , , console, gst, 'xynt_test01_php', 'sess', sess, null, 'xynt_test01.php?isstream=true&f_test=', function(com){eval(com);});
xstm.hbit_set(heartbit);
xstm.start();
}
@@ -189,16 +312,17 @@ if ($isstream == "true") {