session_save_path

(PHP 4, PHP 5, PHP 7, PHP 8)

session_save_path读取/设置当前会话的保存路径

说明

session_save_path ( string $path = ? ) : string

session_save_path() 返回当前会话的保存路径。

参数

path

指定会话数据保存的路径。 必须在调用 session_start() 函数之前调用 session_save_path() 函数。

Note:

在某些操作系统上,建议使用可以高效处理 大量小尺寸文件的文件系统上的路径来保存会话数据。 例如,在 Linux 平台上,对于会话数据保存的工作而言,reiserfs 文件系统会比 ext2fs 文件系统能够提供更好的性能。

返回值

返回保存会话数据的路径。

参见

User Contributed Notes

hrushiemail at gmail dot com 09-Feb-2019 03:29
<?php
ini_set
('session.save_path',realpath(dirname($_SERVER['DOCUMENT_ROOT']) . '/tmp'));
ini_set('session.gc_probability', 1);
session_start();

?>

(for using above code create a tmp folder/directory in your directory)
ohcc at 163 dot com 15-Dec-2017 07:42
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.
mdibbets at outlook dot nospam 03-Oct-2013 07:45
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.
alvaro at demogracia dot com 26-May-2010 03:42
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!
sampathperera at hotmail dot com - Sri Lanka 05-Feb-2008 11:25
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. :)
PHP8中文手册 站长在线 整理 版权归PHP文档组所有