Failed to start the session because headers have already been sent by "/htdocs/backbone.mouv-ml.com/vendor/symfony/http-foundation/Response.php" at line 1285. (500 Internal Server Error)

Symfony Exception

RuntimeException

HTTP 500 Internal Server Error

Failed to start the session because headers have already been sent by "/htdocs/backbone.mouv-ml.com/vendor/symfony/http-foundation/Response.php" at line 1285.

Exception

RuntimeException

  1. if (\PHP_SESSION_ACTIVE === session_status()) {
  2. throw new \RuntimeException('Failed to start the session: already started by PHP.');
  3. }
  4. if (filter_var(\ini_get('session.use_cookies'), \FILTER_VALIDATE_BOOL) && headers_sent($file, $line)) {
  5. throw new \RuntimeException(\sprintf('Failed to start the session because headers have already been sent by "%s" at line %d.', $file, $line));
  6. }
  7. $sessionId = $_COOKIE[session_name()] ?? null;
  8. /*
  9. * Explanation of the session ID regular expression: `/^[a-zA-Z0-9,-]{22,250}$/`.
  1. }
  2. if (!$this->started && $this->saveHandler->isActive()) {
  3. $this->loadSession();
  4. } elseif (!$this->started) {
  5. $this->start();
  6. }
  7. return $this->bags[$name];
  8. }
  1. $this->storage->registerBag(new SessionBagProxy($bag, $this->data, $this->usageIndex, $this->usageReporter));
  2. }
  3. public function getBag(string $name): SessionBagInterface
  4. {
  5. $bag = $this->storage->getBag($name);
  6. return method_exists($bag, 'getBag') ? $bag->getBag() : $bag;
  7. }
  8. /**
  1. *
  2. * Note that this method was added to help with IDE autocompletion.
  3. */
  4. private function getAttributeBag(): AttributeBagInterface
  5. {
  6. return $this->getBag($this->attributeName);
  7. }
  8. }
  1. return $this->getAttributeBag()->has($name);
  2. }
  3. public function get(string $name, mixed $default = null): mixed
  4. {
  5. return $this->getAttributeBag()->get($name, $default);
  6. }
  7. public function set(string $name, mixed $value): void
  8. {
  9. $this->getAttributeBag()->set($name, $value);
  1. if (null !== $session) {
  2. $usageIndexValue = $session instanceof Session ? $usageIndexReference = &$session->getUsageIndex() : 0;
  3. $usageIndexReference = \PHP_INT_MIN;
  4. $sessionId = $request->cookies->all()[$session->getName()] ?? null;
  5. $token = $session->get($this->sessionKey);
  6. // sessionId = true is used in the tests
  7. if ($this->sessionTrackerEnabler && \in_array($sessionId, [true, $session->getId()], true)) {
  8. $usageIndexReference = $usageIndexValue;
  9. } else {
  1. public function authenticate(RequestEvent $event): void
  2. {
  3. $startTime = microtime(true);
  4. try {
  5. $this->listener->authenticate($event);
  6. } catch (LazyResponseException $e) {
  7. $this->response = $e->getResponse();
  8. throw $e;
  9. } finally {
  1. }
  2. $this->tokenStorage->setInitializer(static function () use ($event, $listeners) {
  3. $event = new LazyResponseEvent($event);
  4. foreach ($listeners as $listener) {
  5. $listener($event);
  6. }
  7. });
  8. }
  9. public static function getPriority(): int
in vendor/symfony/security-core/Authentication/Token/Storage/TokenStorage.php :: Symfony\Bundle\SecurityBundle\Security\{closure} (line 34)
  1. public function getToken(): ?TokenInterface
  2. {
  3. if ($initializer = $this->initializer) {
  4. $this->initializer = null;
  5. $initializer();
  6. }
  7. return $this->token;
  8. }
  1. if ($this->shouldTrackUsage()) {
  2. // increments the internal session usage index
  3. $this->getSession()->getMetadataBag();
  4. }
  5. return $this->storage->getToken();
  6. }
  7. public function setToken(?TokenInterface $token = null): void
  8. {
  9. $this->storage->setToken($token);
UsageTrackingTokenStorage->getToken() in src/EventListener/TaskSchedulerSubscriber.php (line 48)
  1. $path = $event->getRequest()->getPathInfo();
  2. if (str_starts_with($path, '/_') || str_starts_with($path, '/build/')) {
  3. return;
  4. }
  5. $user = $this->tokenStorage->getToken()?->getUser();
  6. if (!$user instanceof User) {
  7. return;
  8. }
  9. // La réponse est déjà partie : une exception ici ne doit pas transformer
  1. $this->priority ??= $dispatcher->getListenerPriority($eventName, $this->listener);
  2. $e = $this->stopwatch->start($this->name, 'event_listener');
  3. try {
  4. ($this->optimizedListener ?? $this->listener)($event, $eventName, $dispatcher);
  5. } finally {
  6. if ($e->isStarted()) {
  7. $e->stop();
  8. }
  9. }
  1. foreach ($listeners as $listener) {
  2. if ($stoppable && $event->isPropagationStopped()) {
  3. break;
  4. }
  5. $listener($event, $eventName, $this);
  6. }
  7. }
  8. /**
  9. * Sorts the internal list of listeners for the given event by priority.
  1. } else {
  2. $listeners = $this->getListeners($eventName);
  3. }
  4. if ($listeners) {
  5. $this->callListeners($listeners, $eventName, $event);
  6. }
  7. return $event;
  8. }
  1. try {
  2. $this->beforeDispatch($eventName, $event);
  3. try {
  4. $e = $this->stopwatch->start($eventName, 'section');
  5. try {
  6. $this->dispatcher->dispatch($event, $eventName);
  7. } finally {
  8. if ($e->isStarted()) {
  9. $e->stop();
  10. }
  11. }
  1. public function terminate(Request $request, Response $response): void
  2. {
  3. try {
  4. $this->terminating = true;
  5. $this->dispatcher->dispatch(new TerminateEvent($this, $request, $response), KernelEvents::TERMINATE);
  6. } finally {
  7. $this->terminating = false;
  8. }
  9. }
in vendor/symfony/http-kernel/Kernel.php -> terminate (line 147)
  1. if (!$this->booted) {
  2. return;
  3. }
  4. if ($this->getHttpKernel() instanceof TerminableInterface) {
  5. $this->getHttpKernel()->terminate($request, $response);
  6. }
  7. }
  8. public function shutdown(): void
  9. {
  1. Response::closeOutputBuffers(0, true);
  2. flush();
  3. }
  4. if ($this->kernel instanceof TerminableInterface) {
  5. $this->kernel->terminate($this->request, $response);
  6. }
  7. return 0;
  8. }
  9. }
in vendor/autoload_runtime.php -> run (line 32)
  1. $app = $app(...$args);
  2. exit(
  3. $runtime
  4. ->getRunner($app)
  5. ->run()
  6. );
require_once('/htdocs/backbone.mouv-ml.com/vendor/autoload_runtime.php') in public/index.php (line 14)
  1. // ini_set('display_startup_errors', 1);
  2. // error_reporting(E_ALL);
  3. use App\Kernel;
  4. require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
  5. return function (array $context) {
  6. return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
  7. };

Stack Trace

RuntimeException
RuntimeException:
Failed to start the session because headers have already been sent by "/htdocs/backbone.mouv-ml.com/vendor/symfony/http-foundation/Response.php" at line 1285.

  at vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php:116
  at Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->start()
     (vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php:282)
  at Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->getBag('attributes')
     (vendor/symfony/http-foundation/Session/Session.php:201)
  at Symfony\Component\HttpFoundation\Session\Session->getBag('attributes')
     (vendor/symfony/http-foundation/Session/Session.php:221)
  at Symfony\Component\HttpFoundation\Session\Session->getAttributeBag()
     (vendor/symfony/http-foundation/Session/Session.php:69)
  at Symfony\Component\HttpFoundation\Session\Session->get('_security_main')
     (vendor/symfony/security-http/Firewall/ContextListener.php:99)
  at Symfony\Component\Security\Http\Firewall\ContextListener->authenticate(object(LazyResponseEvent))
     (vendor/symfony/security-bundle/Debug/WrappedLazyListener.php:46)
  at Symfony\Bundle\SecurityBundle\Debug\WrappedLazyListener->authenticate(object(LazyResponseEvent))
     (vendor/symfony/security-bundle/Security/LazyFirewallContext.php:83)
  at Symfony\Bundle\SecurityBundle\Security\LazyFirewallContext::Symfony\Bundle\SecurityBundle\Security\{closure}()
     (vendor/symfony/security-core/Authentication/Token/Storage/TokenStorage.php:34)
  at Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage->getToken()
     (vendor/symfony/security-core/Authentication/Token/Storage/UsageTrackingTokenStorage.php:42)
  at Symfony\Component\Security\Core\Authentication\Token\Storage\UsageTrackingTokenStorage->getToken()
     (src/EventListener/TaskSchedulerSubscriber.php:48)
  at App\EventListener\TaskSchedulerSubscriber->onKernelTerminate(object(TerminateEvent), 'kernel.terminate', object(TraceableEventDispatcher))
     (vendor/symfony/event-dispatcher/Debug/WrappedListener.php:115)
  at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(object(TerminateEvent), 'kernel.terminate', object(TraceableEventDispatcher))
     (vendor/symfony/event-dispatcher/EventDispatcher.php:206)
  at Symfony\Component\EventDispatcher\EventDispatcher->callListeners(array(object(WrappedListener)), 'kernel.terminate', object(TerminateEvent))
     (vendor/symfony/event-dispatcher/EventDispatcher.php:56)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch(object(TerminateEvent), 'kernel.terminate')
     (vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:129)
  at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch(object(TerminateEvent), 'kernel.terminate')
     (vendor/symfony/http-kernel/HttpKernel.php:114)
  at Symfony\Component\HttpKernel\HttpKernel->terminate(object(Request), object(Response))
     (vendor/symfony/http-kernel/Kernel.php:147)
  at Symfony\Component\HttpKernel\Kernel->terminate(object(Request), object(Response))
     (vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php:48)
  at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run()
     (vendor/autoload_runtime.php:32)
  at require_once('/htdocs/backbone.mouv-ml.com/vendor/autoload_runtime.php')
     (public/index.php:14)