TL; DR
使用Nginx / PHP-FPM在Linux机器上获取错误,指出“由于已经发送了标头,因此无法启动会话.”. Apache本地计算机设置上未发生错误
所以在我的本地机器上我运行Symfony2应用程序.没有错误弹出.但是当我部署到我们的Linux服务器时,当我在Controller类中调用某个Action时,我遇到了这个错误
在我已经调用的索引操作中
- @H_502_9@$session = $this->getRequest()->getSession();
在同一控制器类中的另一个动作中,我再次调用它.我尝试时会弹出错误
- @H_502_9@$session->set('foo',$bar);
在我的Twig中,我通过一个表单和一个带有形成属性的按钮来调用动作
- @H_502_9@
所以在我的本地机器上运行Apache一切运行正常. Linux服务器正在使用Nginx和PHP-fpm,由于某种原因它崩溃了.我检查了PHPInfo(),会话自动启动设置为关闭.不确定这是否是Nginx / PHP-fpm问题,但我认为这可能是相关信息.
这是Controller声明,indexAction()和我的2ndAction()
- @H_502_9@use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\HttpFoundation\Session\Session;
- use CBSi\Utils\HTTPUtils\CURLUtil;
- class StartController extends Controller
- {
- /**
- * @var CurlUtil $curlUtil
- */
- private $curlUtil;
- /**
- * @var AccessControl $accessControl
- */
- private $accessControl;
- /*placeholder for request object*/
- private $requestHolder;
- /**
- * @Route("/path/for/action/one",name="start")
- * @Template()
- */
- public function indexAction()
- {
- $session = $this->getRequest()->getSession();
- $this->curlUtil = $this->get('curlUtil');
- $this->requestHolder= Request::createFromGlobals();
- // Some logic is done here
- return $this->render('ListEngagementBundle:Start:start.html.twig');
- }
- /**
- * @Route("/path/to/second/action",name="2ndAction")
- * @Template
- */
- public function 2ndAction(){
- $session = $this->getRequest()->getSession();
- $this-> curlUtil = $this->get('curlUtil');
- $this->requestHolder= Request::createFromGlobals();
- //Some logic is done here to get the data for the session variable
- $bar= logic output
- $session->set('foo',$bar);
- return $this->redirect($this->generateUrl('start'));
- }
- }
如果您需要我可以提供的更多信息,我会:)
最佳答案