#!/home/php/bin/php -q
<?php
function execute($command) {
GLOBAL $in, $out;
fputs($out, $command . " \n");
fflush($out);
$data = fgets($in, 4096);
if (preg_match("°^([0-9]{1,3}) (.*)°", $data, $matches)) {
if (preg_match('°^result=([0-9a-zA-Z]*)( ?\((.*)\))?$°', $matches[2], $match)) {
$arr['code'] = $matches[1];
$arr['result'] = $match[1];
if (isset($match[3]) && $match[3])
$arr['data'] = $match[3];
return $arr;
} else return 0;
} else return -1;
}
ob_implicit_flush(true);
set_time_limit(0);
$out = fopen("php://stdout", "w");
$in = fopen("php://stdin", "r");
//$log = fopen("/tmp/agi.log", "w");
while (!feof($in)) {
$temp = str_replace("\n","",fgets($in,4096));
$s = split(":",$temp);
if (!isset($s[1])) $s[1] = "";
$agi[str_replace("agi_","",$s[0])] = trim($s[1]);
if (($temp == "") || ($temp == "\n")) {
break;
}
}
execute("STREAM FILE whatever/whatever ''");
fclose($out);
fclose($in);
//fclose($log);
exit;
?>