目前我的做法是
try {
$process = new \Symfony\Component\Process\Process(['php', 'react-php-test.php']);
$process->setOptions(['create_new_console' => true]);
$process->start();
echo $process->getPid();
} catch (Throwable $throwable) {
echo $throwable->getMessage();
}
$loop = React\EventLoop\Loop::get();
// 創(chuàng)建一個定時器,每3秒執(zhí)行一次,寫入文件
$loop->addPeriodicTimer(3, function () {
file_put_contents('debug.txt', 'test' . PHP_EOL, FILE_APPEND);
});
$loop->run();
php process.php
,執(zhí)行后,可關(guān)閉當前終端,會看到文件中,每3秒會寫入'test'字符串