You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.6 KiB
72 lines
1.6 KiB
<?php
|
|
|
|
session_start();
|
|
|
|
//
|
|
// work around for globals registers.
|
|
// we will not use them at all
|
|
//
|
|
|
|
|
|
if (ini_get('register_globals'))
|
|
{
|
|
foreach ($_SESSION as $key=>$value)
|
|
{
|
|
if (isset($GLOBALS[$key]))
|
|
unset($GLOBALS[$key]);
|
|
}
|
|
}
|
|
|
|
|
|
function debug($text) {
|
|
$f = fopen("/tmp/modelbahn-php.log",'a+');
|
|
fwrite($f, $text.PHP_EOL);
|
|
fclose($f);
|
|
};
|
|
|
|
|
|
function readsend_data() {
|
|
$data = "";
|
|
$input = "";
|
|
debug ("opening connection");
|
|
$fp = stream_socket_client("unix:///tmp/modelbahn.socket", $errno, $errstr, 30);
|
|
if (stream_set_blocking ($fp, FALSE) == FALSE) debug ("stream_set_blocking error");
|
|
else debug ("stream_set_blocking ok");
|
|
|
|
if (!$fp) {
|
|
debug ($errstr . " " . $errno);
|
|
} else {
|
|
$json = file_get_contents("php://input");
|
|
debug("Send to Server :".$json);
|
|
fwrite($fp, $json);
|
|
$timestart = gettimeofday();
|
|
$deltatime = 0;
|
|
while (!feof($fp) && $deltatime < 1000) {
|
|
$input = fgets($fp, 1024);
|
|
$data = $data.$input;
|
|
$timeend = gettimeofday();
|
|
|
|
if ($timeend["usec"] < $timestart["usec"]) $deltatime = 1000 + ($timeend["usec"] - $timestart["usec"])/1000;
|
|
else $deltatime = ($timeend["usec"] - $timestart["usec"])/1000;
|
|
|
|
$deltatime = $deltatime + ($timeend["sec"] - $timestart["sec"]) * 1000;
|
|
}
|
|
fclose($fp);
|
|
debug ("got: $data");
|
|
debug ("connection closed");
|
|
return $data;
|
|
}
|
|
return $data;
|
|
};
|
|
|
|
$timerstart = microtime(true);
|
|
debug("*** php script called");
|
|
|
|
$request = 0;
|
|
$resultdata = array();
|
|
|
|
echo readsend_data();
|
|
$timeused = microtime(true) - $timerstart;
|
|
debug ("*** php script finished ********************************* ".$timeused."ms");
|
|
|