2
我需要异步运行一个命令。为此,我试图使用Process Component。Symfony过程组件 - 设置命令的输入参数
我试着开始的命令是调用一个需要一些参数的函数。这些参数由启动Process的Controller给出。
问题是我不知道如何使用Process Component将参数传递给我的命令。
命令:
protected function configure()
{
$this
->setName('generationpdf:classement')
->setDescription('Génère le PDF d\'un classement.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
ini_set('memory_limit','4000M');
$pdf = $this->imprimerAction();
$this->sendClassement($pdf);
$output->writeln('PDF envoyé.');
}
控制器:
$command = new PDFClassementCommand();
$input = new ArrayInput(array('id' => $id, 'errata' => $errata, 'precision' => $precision, 'group' => $group, 'logoAnnee' => $logoAnnee));
$output = new NullOutput();
$process = new Process($command);
$process->disableOutput();
$process->start();
参数我需要使用在ArrayInput,但过程并不需要数组参数。
我确实通过parameters正常,就像运行命令你说的话,并如预期在终端我的命令运行。 我尝试使用Process,但它不起作用。 '$ rootDir = $ this-> get('kernel') - > getRootDir();' '$ process = new Process('php'。$ rootDir。'/ bin/console generationpdf:classement'。$ $'$。$。'$。''。$'precision。'');' '$ process-> start();' 过程已启动,但是不成功。 –
'$ process-> run()'正在工作,但它不会在后台执行命令。 –
您可以使用'start()'等待进程完成,然后检查输出和错误输出。应该有失败进程的错误输出,对吧?有关实施,请参阅[文档](http://symfony.com/doc/current/components/process.html#running-processes-asynchronously)。 –