1、找到php.ini配置文件,找到session.save_path,修改如下: 其中2表示session存储的目录深度,也就是分目录,避免一个目录下文件太多,造成IO负担。 session.save_path = "2;D:\xxx\php54\session" 2、如上设置后,重启apache后,在php文件session_start()后会报错。 Warning: session_start(): open(D:\xxx\php54\session\b\9\sess_b9h5uo3bra9j28f4p4rim8mg02, O_RDWR) failed: No such file or directory (2) in D:\wwwroot\test\index.php on line 2 Warning: Unknown: open(D:\xxx\php54\session\b\9\sess_b9h5uo3bra9j28f4p4rim8mg02, O_RDWR) failed: No such file or directory (2) in Unknown on line 0 Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (2;D:\xxx\php54\session) in Unknown on line 0 3、原来是session下的\b\9目录需要手动创建,所以写了一个函数。 <?php function createSessionDir($sessionPath = '') { if(empty($sessionPath)) { return false; } $dirNameArr = array_merge(range(0, 9), range('a', 'z')); $sessionPath = rtrim($sessionPath, '\/') . DIRECTORY_SEPARATOR; foreach ($dirNameArr as $dirName) { $dirPath = $sessionPath . $dirName . DIRECTORY_SEPARATOR; foreach ($dirNameArr as $subDirName) { @mkdir($dirPath . $subDirName, 0777, true); } } } createSessionDir('D:\xxx\php54\session');
版权声明:博主文章,可以不经博主允许随意转载,随意修改,知识是用来传播的。