【问题标题】:Failed to start the session because headers have already been sent by "" at line 0. at n/a无法启动会话,因为标头已由第 0 行的“”发送。在 n/a
【发布时间】:2014-09-06 23:19:26
【问题描述】:

我正在尝试在现有项目中的新 (Windows 8) 笔记本电脑上开始工作,该项目在我以前的 (Mac OS X) 机器和它部署到的所有 (Linux) 服务器上运行良好。

我已经从 git 克隆,运行 composer,app/console 工作正常,我已经正确设置了配置文件,创建了数据库并检查了数据库架构是否正常,清除了缓存等等以前做过一千次。

但是现在我遇到了一个我以前从未遇到过的错误,我不知道它是否与更新的依赖项有关,这些依赖项可能不一定使用与以前完全相同的版本,或者只是我一种在 Windows 环境下的新工作:

[1] RuntimeException: Failed to start the session because headers have already been sent by "" at line 0.
at n/a
    in C:\Users\David\Sites\my-project\app\cache\dev\classes.php line 103

at Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->start()
    in C:\Users\David\Sites\my-project\app\cache\dev\classes.php line 183

at Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->getBag('attributes')
    in C:\Users\David\Sites\my-project\app\cache\dev\classes.php line 475

at Symfony\Component\HttpFoundation\Session\Session->has('_security.last_error')
    in C:\Users\David\Sites\my-project\vendor\friendsofsymfony\user-bundle\FOS\UserBundle\Controller\SecurityController.php line 28

at FOS\UserBundle\Controller\SecurityController->loginAction(object(Request))
    in  line 

at call_user_func_array(array(object(SecurityController), 'loginAction'), array(object(Request)))
    in C:\Users\David\Sites\my-project\app\bootstrap.php.cache line 2841

at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
    in C:\Users\David\Sites\my-project\app\bootstrap.php.cache line 2815

at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
    in C:\Users\David\Sites\my-project\app\bootstrap.php.cache line 2944

at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
    in C:\Users\David\Sites\my-project\app\bootstrap.php.cache line 2245

at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
    in C:\Users\David\Sites\my-project\web\app_dev.php line 29

【问题讨论】:

  • 这可能是由文件编码引起的。当你将它克隆到windows并用文本编辑器打开它时,文件编码可能会改变。
  • 您的其他服务器可能启用了输出缓冲。出现此问题的原因是您在尝试设置标头之前输出了 html(有意或启用了 display_errors)。您可以使用app\bootstrap.php 顶部的ob_start() 来解决此问题。

标签: php symfony-2.3


【解决方案1】:

检查任何覆盖来自 HttpKernel 的类的自定义类,例如 Bundle 类没有从 boot() 等方法之一发送标头或响应

【讨论】:

  • 啊,谢谢我有一个应用程序范围的开关,但我忘记了它:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-19
  • 2021-02-27
  • 2017-08-29
  • 1970-01-01
  • 2013-05-15
  • 2013-04-25
相关资源
最近更新 更多