在一个新的symfony2项目(这里描述的安装)中,我想作为请求的一部分启动一个控制台进程.该应用程序在nginx + php-fpm的"标准"ubuntu 14.04框上运行.
考虑一下这个控制器代码:
<?php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Process\Process;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class CommandController extends Controller
{
/**
* @Route("/command")
* @return JsonResponse
*/
public function commandAction ()
{
$rootDir = $this->get('kernel')->getRootDir();
$env = $this->get('kernel')->getEnvironment();
$commandline = $rootDir . '/console --env=' . $env . ' acme:hello --who jojo'
$process = new Process($commandline);
$process->start();
return new JsonResponse(array('command' => $commandline));
}
}
Run Code Online (Sandbox Code Playgroud)
当我向/ command发出请求时,我得到了我期望的结果并且该过程开始,例如我用htop等看到它.当我再次发出此请求时,我得到了我的预期结果,但是要启动的过程不会出现在任何地方.没有错误,没有任何错误.
重新启动php5-fpm服务使我能够再次通过请求启动一个进程,所以基本上我需要在每次请求后重新启动整个php服务.所以这可能不是编程问题.但老实说,我还不知道.问题是在stackoverflow之前描述的,Symfony2 - 进程启动一个symfony2命令,但exec的解决方法对我不起作用.
有人有线索吗?
谢谢,问候,jojo