SessionHandlerInterface::write
(PHP 5 >= 5.4.0)
SessionHandlerInterface::write — Write session data
Description
$session_id
, string $session_data
)Writes the session data to the session storage. Called by session_write_close(), when session_register_shutdown() fails, or during a normal shutdown. Note: SessionHandlerInterface::close() is called immediately after this function.
PHP will call this method when the session is ready to be saved and closed. It encodes the session data from the $_SESSION superglobal to a serialized string and passes this along with the session ID to this method for storage. The serialization method used is specified in the session.serialize_handler setting.
Note this method is normally called by PHP after the output buffers have been closed unless explicitly called by session_write_close()
Parameters
-
session_id
-
The session id.
-
session_data
-
The encoded session data. This data is the result of the PHP internally encoding the $_SESSION superglobal to a serialized string and passing it as this parameter. Please note sessions use an alternative serialization method.
Return Values
The return value (usually TRUE
on success, FALSE
on failure). Note this value is returned internally to PHP for processing.
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с сессиями
- Управление сессиями
- Функция SessionHandlerInterface::close() - Закрывает сессию
- Функция SessionHandlerInterface::destroy() - Уничтожает сессию
- Функция SessionHandlerInterface::gc() - Очищает старые сессии
- Функция SessionHandlerInterface::open() - Initialize session
- Функция SessionHandlerInterface::read() - Читает данные сессии
- Функция SessionHandlerInterface::write() - Записать данные сессии
Коментарии
Note: this function won't be called in case $session_data is unchanged. In order to call this function every time when session is about closing, add $_SESSION["timestamp"] = time();
It is important to note that if returning FALSE from this method, PHP will in turn output the following warning:
Warning: Unknown: Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0.
This could cause minor inconveniences, however if the session should not be written as per design, then returning TRUE after handling (and not writing) the session will avoid further issues.
All in all, better return TRUE at all times except in cases of hard errors.
Warning: session_write_close(): Session callback expects true/false return value in Unknown on line 0
I have returned TRUE in write() but the warning still persist. Then I also return TRUE in close() and the warning is gone.