Symfony2 PHP 5.4.4 Cannot change the ID of an active session

Currently, we install our web application in Symfony2 and we find a blocking problem.

  • linux Debian Wheezy
  • PHP 5.4.4
  • Symfony version 2.1.10-DEV - app/dev/debug
  • The fatal error to the exception :

    vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/AbstractProxy.php throw new LogicException('Cannot change the ID of an active session');

    Stack Trace :

    in kernel.root_dir/cache/dev/classes.php at line 484 -+ public function setId($id) { if ($this->isActive()) { throw new LogicException('Cannot change the ID of an active session'); } session_id($id); at AbstractProxy ->setId ('09g5hbsvg1apk8d32k52l19rr5') in kernel.root_dir/cache/dev/classes.php at line 208 -+ at NativeSessionStorage ->setId ('09g5hbsvg1apk8d32k52l19rr5') in kernel.root_dir/cache/dev/classes.php at line 780 -+ at Session ->setId ('09g5hbsvg1apk8d32k52l19rr5') in /home/wwwmain/www_v5/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/EventListener/TestSessionListener.php at line 54 -+ at TestSessionListener ->onKernelRequest (object(GetResponseEvent)) at call_user_func (array(object(TestSessionListener), 'onKernelRequest'), object(GetResponseEvent)) in /home/wwwmain/www_v5/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/ContainerAwareTraceableEventDispatcher.php at line 139 -+ at ContainerAwareTraceableEventDispatcher ->doDispatch (array(array(object(ProfilerListener), 'onKernelRequest'), array(object(TestSessionListener), 'onKernelRequest'), array(object(SessionListener), 'onKernelRequest'), array(object(RouterListener), 'onKernelRequest'), arr ay(object(LocaleListener), 'onKernelRequest'), array(object(Firewall), 'onKernelRequest'), array(object(RequestListener), 'onKernelRequest'), array(object(TwigExtension2), 'onKernelRequest'), array(object(RequestListener), 'onKernelRequest')), 'kernel.request', object(GetResponseEvent)) in kernel.root_dir/cache/dev/classes.php at line 4781 -+ at EventDispatcher ->dispatch ('kernel.request', object(GetResponseEvent)) in kernel.root_dir/cache/dev/classes.php at line 4999 -+ at ContainerAwareEventDispatcher ->dispatch ('kernel.request', object(GetResponseEvent)) in /home/wwwmain/www_v5/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/ContainerAwareTraceableEventDispatcher.php at line 78 -+ at ContainerAwareTraceableEventDispatcher ->dispatch ('kernel.request', object(GetResponseEvent)) in kernel.root_dir/bootstrap.php.cache at line 1412 -+ at HttpKernel ->handleRaw (object(Request), '1') in kernel.root_dir/bootstrap.php.cache at line 1392 -+ at HttpKernel ->handle (object(Req uest), '1', true) in kernel.root_dir/bootstrap.php.cache at line 1568 -+ at HttpKernel ->handle (object(Request), '1', true) in kernel.root_dir/bootstrap.php.cache at line 619 -+ at Kernel ->handle (object(Request)) in /home/wwwmain/www_v5/web/app_dev.php at line 25 -+

    Logs :

    DEBUG - Notified event "kernel.request" to listener "SymfonyComponentHttpKernelEventListenerProfilerListener::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "SymfonyBundleFrameworkBundleEventListenerTestSessionListener::onKernelRequest". DEBUG - Notified event "kernel.exception" to listener "SymfonyComponentHttpKernelEventListenerProfilerListener::onKernelException". DEBUG - Notified event "kernel.exception" to listener "SymfonyComponentHttpKernelEventListenerExceptionListener::onKernelException". CRITICAL - LogicException: Cannot change the ID of an active session (uncaught exception) at /home/wwwmain/www_v5/app/cache/dev/classes.php line 484 DEBUG - Notified event "kernel.request" to listener "SymfonyComponentHttpKernelEventListenerProfilerListener::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "SymfonyBundleFrameworkBundleEventListenerTestSessionListener::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "SymfonyBundleFrameworkBundleEventListenerSessionListener::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "SymfonyComponentHttpKernelEventListenerRouterListener::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "SymfonyComponentHttpKernelEventListenerLocaleListener::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "SymfonyComponentSecurityHttpFirewall::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "EyrollesCompteBundleServiceRequestListener::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "EyrollesEcommerceBundleTwigExtensionTwigExtension2::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "SymfonyBundleAsseticBundleEventListenerRequestListener::onKernelRequest". DEBUG - Notified event "kernel.controller" to listener "SymfonyBundleFrameworkBundleDataCollectorRouterDataCollector::onKernelController". DEBUG - Notified event "kernel.controller" to listener "SensioBundleFrameworkExtraBundleEventListenerControllerListener::onKernelController". DEBUG - Notified event "kernel.controller" to listener "SensioBundleFrameworkExtraBundleEventListenerParamConverterListener::onKernelController". DEBUG - Notified event "kernel.controller" to listener "SensioBundleFrameworkExtraBundleEventListenerTemplateListener::onKernelController". DEBUG - Notified event "kernel.controller" to listener "SymfonyComponentHttpKernelDataCollectorRequestDataCollector::onKernelController".

    Any ideas, thoughts?


    Looks like you are running phpunit tests? If so, then calss TestSessionListener calls Session::setId() if it finds Cookie with session name.

    I'm, also encounter this problem. Looks like the only way is to extends this class and override "test.session.listener.class" parameter.

    链接地址: http://www.djcxy.com/p/53994.html

    上一篇: 如何正确包含包?

    下一篇: Symfony2 PHP 5.4.4无法更改活动会话的ID