我是Symfony2的新手,在尝试运行这样的异步命令时遇到了阻塞:
class MyCommand extends ContainerAwareCommand{
protected function configure()
{
$this
->setName('my:command')
->setDescription('My command')
->addArgument(
'country',InputArgument::required,'Which country?'
)
;
}
protected function execute(InputInterface $input,OutputInterface $output)
{
$country = $input->getArgument('country');
// Obtain the doctrine manager
$dm = $this->getContainer()->get('doctrine_mongodb.odm.document_manager');
$users = $dm->getRepository('MyBundle:User')
->findBy( array('country'=>$country));
}}
当我从命令行调用它时,它完美地工作:
PHP app/console my:command uk
但是,当我称之为Symfony2进程时,它不起作用:
$process = new Process("PHP ../app/console my:command $country");
$process->start();
我收到一个数据库错误:“[MongoWriteConcernException] 127.0.0.1:27017:not master”
我认为这意味着该过程没有得到我的数据库配置…
我只是想运行一个异步进程,还有其他方法吗?
也许一种方法来调用不需要答案的应用程序命令继续?
也许我需要使用注射?
PS:我目前的命令只是一个测试,最后它应该是一个“昂贵的”操作……