phpsymfonyphp-7

PHP7 + Symfony 2.8, Failed to write session data


i compiled php7 on my own (974f6c2a705). if i run php7 + php-fpm + nginx using symfony i get this error:

(using the snc redis bundle for sessions:)

 Warning: session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/tmp)

(using the native session support:)

 Warning: session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/[...]/app/cache/dev/sessions)

the problem seems to be symfony related, because php has read / write access to the folder.

if i run nothing but this code, it works:

session_start();
$_SESSION['x'] = 4234;
session_write_close();

any suggestions or ideas why symfony fails to write the sessions?


Solution

  • PHP7 is more strict with session handling for custom session handlers. Symfony's custom session handler for its write method is, for whatever reason, returning false. Previously this did not trigger an error but now it does.

    Since we do not have a lot of information on which custom session handler you are using, I would suggest setting a different custom session handler if possible since most of them appear to return true.

    Here are the different session handlers Symfony, most of them appear to explicitly return true except for the Memcache ones and WriteCheckSessionHandler:

    https://github.com/symfony/symfony/tree/582f4753a343f230fbe18b4e9a0747d48351ddfb/src/Symfony/Component/HttpFoundation/Session/Storage/Handler

    EDIT:

    Since you mention the Snc Redis Bundle session handler, are you sure you are using the most up-to-date version? A year ago it was modified to always return true on write:

    https://github.com/snc/SncRedisBundle/blob/master/Session/Storage/Handler/RedisSessionHandler.php

    UPDATE

    Submitted a bug to PHP to see if we can figure out a more useful error message for future versions (please vote or leave a comment on the bug report):

    https://bugs.php.net/bug.php?id=71070