Ловлю deadlock..., почему - видимо что-то не так понимаю
// threads.php
// dummy файл, чтобы загрузить процесс чем-нибудь, пока выполняется функция
require_once 'functions.php';
// EOF
// functions.php
// файл-библиотека функций
defined($var = '__APPDIR__') or define($var, dirname(__FILE__));
// _doAsync
// выполняет "асинхронную" команду
if (!function_exists("_doAsync")):
function _doAsync(Callable $async_func) {
$path = realpath('threads.php');
$spec = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'r')
);
$pipes = array();
$h = proc_open(sprintf('php %s', $path), $spec, $pipes, $cwd = __APPDIR__, $env = null);
// start async
$async_func();
// end async
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($h);
return $stdout;
}
endif;
// EOF
// action.php
// файл команды для приложения
require_once 'functions.php';
$res = _doAsync(function () {
echo 123;
});
// EOF