Symfony2 and “ContextErrorException: Warning: SessionHandler::read()” Exception
I just upgraded to Symfony 2.4, and started randomly getting this error:
ContextErrorException: Warning: SessionHandler::read(): open(/var/lib/php/session/sess_3cq63tff1lhbghus3o9jsh26j4, O_RDWR) failed: No such file or directory (2) in /var/www/codeconsortium.com/public/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php line 69
Which was pretty odd, as there is a discussion about this, which you can find here on symfony/symfony github, However the issue seems to be in part with PHP, but it was for me already patched. As the issue is introduced in 5.4 somewhere and fixed in 5.4.11.
It seems that everything was fixed, and i was many versions ahead. So why was this cropping up randomly now? I had not changed my PHP version or my OS version, just symfony.
It seems some config changed, which i show below. If you do not have this set, then i believe it falls back on the default php.ini setting of session.cookie_path, which if blank causes this. Add this config below will fix the issue.
framework: session: handler_id: session.handler.native_file save_path: "%kernel.root_dir%/sessions"
I hope this helps.
9 thoughts on “Symfony2 and “ContextErrorException: Warning: SessionHandler::read()” Exception”
This is exactly what I needed to make it happen on my Mac OS build. Funny thing is that this error started appearing after I changed the user that PHP runs under from _www to staff user. Thanks again
Also I read your notes on the Symfony github site and I have php 5.5 also so it could be related to that.
Thank you for that bit of information. It worked for me.
you saved my day.. thanks man!!!
sorry, i’m newbie here. Where i can find php.ini in server?
Right solution. Thanks mate!
thank you so much
thanks, that fixed my new installation.