PHP 7 Session Options

PHP 7 新特性PHP 7 New Features

In PHP 7, the session_start() function can accept an array as a parameter, which can override the session configuration items in php.ini.

This feature also introduced a new php.ini setting (session.lazy_write), which is set to true by default, meaning session data is only written when changes occur.

In addition to the regular session configuration directives, you can also include the read_and_close option in this array. If this option is set to TRUE, the session file will be closed immediately after reading is complete. Therefore, when session data has not changed, unnecessary file locking can be avoided.

Examples

Set cache_limiter to private, and close the session immediately after reading it.

Examples

<?php session_start([ 'cache_limiter' => 'private', 'read_and_close' => true, ]); ?>

PHP 7 新特性PHP 7 New Features

Other Extensions