Programming, Security, Server Administration, Technology, Uncategorized

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.