Nginx   发布时间:2022-05-11  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了apache – Symfony2:由于已经发送了标头,因此无法启动会话大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

TL; DR
使用Nginx / php-FPM在Linux机器上获取错误,指出“由于已经发送了标头,因此无法启动会话.”. Apache本地计算机设置上未发生错误

所以在我的本地机器上我运行Symfony2应用程序.没有错误弹出.但是当我部署到我们的Linux服务器时,当我在Controller类中调用某个Action时,我遇到了这个错误

Failed to start the session because headers have already been sent. 

在我已经调用的索引操作中

$session = $this->getrequest()->getSession();

在同一控制器类中的另一个动作中,我再次调用它.我尝试时会弹出错误

$session->set('foo',$bar);

在我的Twig中,我通过一个表单和一个带有形成属性的按钮来调用动作

所以在我的本地机器上运行Apache一切运行正常. Linux服务器正在使用Nginx和php-fpm,由于某种原因它崩溃了.我检查了phpInfo(),会话自动启动设置为关闭.不确定这是否是Nginx / php-fpm问题,但我认为这可能是相关信息.

这是Controller声明,indexAction()和我的2ndAction()

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'));
}
}

如果您需要我可以提供的更多信息,我会:)

最佳答案
所以我明白了.在我打电话的第二个动作中

$session->getrequest()->getSession(); 

我不得不改变它

$session = new Session();
$session->start();

去搞清楚. :P

大佬总结

以上是大佬教程为你收集整理的apache – Symfony2:由于已经发送了标头,因此无法启动会话全部内容,希望文章能够帮你解决apache – Symfony2:由于已经发送了标头,因此无法启动会话所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: