session_save_path
(PHP 4, PHP 5, PHP 7)
session_save_path — Get and/or set the current session save path
Описание
$path
] )session_save_path() returns the path of the current directory used to save session data.
Список параметров
-
path
-
Session data path. If specified, the path to which data is saved will be changed. session_save_path() needs to be called before session_start() for that purpose.
Замечание:
On some operating systems, you may want to specify a path on a filesystem that handles lots of small files efficiently. For example, on Linux, reiserfs may provide better performance than ext2fs.
Возвращаемые значения
Returns the path of the current directory used for data storage.
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с сессиями
- Управление сессиями
- session_abort
- session_cache_expire
- session_cache_limiter
- session_commit
- session_create_id
- session_decode
- session_destroy
- session_encode
- session_gc
- session_get_cookie_params
- session_id
- session_is_registered
- session_module_name
- session_name
- session_regenerate_id
- session_register_shutdown
- session_register
- session_reset
- session_save_path
- session_set_cookie_params
- session_set_save_handler
- session_start
- session_status
- session_unregister
- session_unset
- session_write_close
Коментарии
Session on clustered web servers !
We had problem in PHP session handling with 2 web server cluster. Problem was one servers session data was not available in other server.
So I made a simple configuration in both server php.ini file. Changed session.save_path default value to shared folder on both servers (/mnt/session/).
It works for me. :)
Debian does not use the default garbage collector for sessions. Instead, it sets session.gc_probability to zero and it runs a cron job to clean up old session data in the default directory.
As a result, if your site sets a custom location with session_save_path() you also need to set a value for session.gc_probability, e.g.:
<?php
session_save_path('/home/example.com/sessions');
ini_set('session.gc_probability', 1);
?>
Otherwise, old files in '/home/example.com/sessions' will never get removed!
I made a folder next to the public html folder and placed these lines at the very first point in index.php
Location of session folder:
/domains/account/session
location of index.php
/domains/account/public_html/index.php
What I placed in index.php at line 0:
<?php
ini_set('session.save_path',realpath(dirname($_SERVER['DOCUMENT_ROOT']) . '/../session'));
session_start();
This is the only solution that worked for me. Hope this helps someone.
If session.save_handler is set to files, on systems that have maximum path length limitations, when the session data file's path is too long, php may get you an error like "No such file or directory" and fails to start session, although the session-saving folder really exists on the disk.
You should:
1. Keep the session-saving folder's absolute path not too long
2. If you're with PHP 7.1+, don't set session.sid_length to a number too great, such as 255
I once got stuck with this problem on Windows and wasted hours to solve it.
This function seems to simply return the value of session.save_path from the [Session] section of php.ini. This has an important implication: the returned value can as well look like "0;0660;/var/lib/php/sessions", which is of course no valid path.
A way to extract the path despite the possible semicolons can be something like:
$ssp = explode(';', session_save_path());
echo end($ssp);
As end takes the array by reference, it's not possible to make a real one-liner without relying on an intermediate variable.