我有以下命令运行Symfony2进程:
class UpdateShopsCommand extends Command
{
protected function configure()
{
$this
->setName('backgroundtask:updateshop')
->setDescription('Update paying shops pictures and bio')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$container = $this->getApplication()->getKernel()->getContainer();
$shopsNeededToBeUpdated = $this->getShopsNeedToBeUpdated();
foreach ($shopsNeededToBeUpdated as $shop) {
//start a process here
var_dump('updating shop ' . $shop->getUsername());
$process = new Process('app/console backgroundtask:refreshuserinfo ' . $shop->getUserid() . ' false --env=' . $this->get('kernel')->getEnvironment());
$process->setTimeout(3600);
$process->start();
$process->wait(function ($type, $buffer) {
if (Process::ERR === $type) {
echo 'ERR > '.$buffer;
} else {
echo 'OUT > '.$buffer;
}
});
}
$output->writeln('Finished updating shops');
}
}
如果我有等待功能,代码就能完美运行。但是我不希望其中包含wait
,因为等待阻塞线程,现在它不是异步,只是想启动进程异步。但是,当我这样做时,就好像这个过程从未开始过。为什么是这样?我真的需要等待异步过程吗?我怎么知道它实际上正在运行?