【发布时间】:2014-07-16 06:50:48
【问题描述】:
我是 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:我当前的命令只是一个测试,最后它应该是一个“昂贵”的操作......
【问题讨论】:
-
好吧,我自己找到了解决方案。实际上这是一个愚蠢的问题......我已将环境参数(--env=)添加到进程中,一切都像一个魅力:
$process = new Process("php ../app/console my:command $country --env=test");
标签: php mongodb symfony asynchronous process