hitagi-entrada/includes/wrapper-noswoole.php

40 lines
954 B
PHP
Raw Normal View History

2024-12-12 18:39:48 +00:00
<?php
function agiRunCmdWrapper($stdin, $stdout)
{
return function ($command) use ($stdin, $stdout) {
2024-12-12 19:27:10 +00:00
// $texto = "-----> EXECUTAR COMANDO $command";
// return $texto;
$return = '';
fwrite($stdout, $command . "\n");
fflush($stdout);
while ($line = fgets($stdin)) {
$return.= $line;
if (strpos($line, 'result=') !== false) {
if (substr($line,0,22) != '100 result=0 Trying...') {
break;
}
}
}
$return = trim($return);
return $return;
2024-12-12 18:39:48 +00:00
};
}
function agiLogWrapper($logEnabled)
{
return function ($texto, $options = array()) use ($logEnabled) {
if ($logEnabled) {
$target = 'log' . DIRECTORY_SEPARATOR . 'log.txt';
$texto .= PHP_EOL;
if (isset($options['new'])) {
file_put_contents($target, $texto);
} else {
file_put_contents($target, $texto, FILE_APPEND);
}
}
};
}