I am attempting to call a console command from a controller using the Process component in Symfony2 to have it run in the background, however all it does is hang and end up at a white screen. This is an example of what fails:
我试图使用Symfony2中的Process组件从控制器调用一个控制台命令让它在后台运行,但它只是挂起并最终在白色屏幕上运行。这是失败的一个例子:
$process = new Process('php app/console list');
$process->setWorkingDirectory($this->get('kernel')->getRootDir().'/../');
$process->run();
print $process->getOutput();
I have tried interchanging $process->run() with $process->start() and it still doesn't work.
我尝试用$ process-> start()交换$ process-> run(),但它仍然不起作用。
1 个解决方案
#1
Checkout AsyncServiceCallBundle, it allows you to execute your application service's methods in background without having to wait until they are finished. Just use it like this:
Checkout AsyncServiceCallBundle,它允许您在后台执行应用程序服务的方法,而不必等到它们完成。只需使用它:
$this->get('krlove.async')->call('service_id', 'method', [$arg1, $arg2, $arg3]);
It uses this approach to make such calls asynchronous.
它使用这种方法使这种调用异步。
#1
Checkout AsyncServiceCallBundle, it allows you to execute your application service's methods in background without having to wait until they are finished. Just use it like this:
Checkout AsyncServiceCallBundle,它允许您在后台执行应用程序服务的方法,而不必等到它们完成。只需使用它:
$this->get('krlove.async')->call('service_id', 'method', [$arg1, $arg2, $arg3]);
It uses this approach to make such calls asynchronous.
它使用这种方法使这种调用异步。