hitagi-entrada/includes/wrapper-noswoole.php

33 lines
835 B
PHP
Raw Permalink 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 = '';
2024-12-14 01:14:11 +00:00
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);
2024-12-12 19:27:10 +00:00
return $return;
2024-12-12 18:39:48 +00:00
};
}
2024-12-14 01:14:11 +00:00
function agiLogWrapper()
2024-12-12 18:39:48 +00:00
{
2024-12-14 01:14:11 +00:00
return function ($texto) {
$target = 'log' . DIRECTORY_SEPARATOR . 'log.txt';
$texto = trim($texto) . PHP_EOL;
file_put_contents($target, $texto, FILE_APPEND);
2024-12-12 18:39:48 +00:00
};
}