本篇内容主要讲解“php中session写入失败怎么解决”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“php中session写入失败怎么解决”吧!
php session写入失败是因为把session误存在memcache里面了,其解决办法就是把session存在redis里面,然后修改php的配置文件即可。
本文操作环境:windows10系统、PHP7.1版,DELL G3电脑
具体问题:
php session 写入失败怎么办?
php 一直报session写入失败
Warning:session_write_close():Failedtowritesessiondatausinguserdefinedsavehandler.(session.save_path:tcp://127.0.0.1:6379)in/var/www/html/php/pbs/util/Session.phponpne43
问题描述
我的代码写入session 的时候一直报这个问题, 环境是windows10 ubuntu 子系统,session 写入的位置是 memcache 6379 端口,扩展都开启了,有大神能解答一下这是什么问题吗?
问题出现的环境背景及自己尝试过哪些方法
相关代码
classSession{ //singleton privatestatic$session_handler_; pubpcstaticfunctionInit(){ if(!isset(self::$session_handler_)) self::$session_handler_=newSession(); } //阻止用户复制对象实例 pubpcfunction__clone(){ trigger_error('CloneSessionisnotallowed.',E_USER_ERROR); } privatefunction__construct(){ session_set_save_handler(array($this,"Open"), array($this,"Close"), array($this,"Read"), array($this,"Write"), array($this,"Destroy"), array($this,"Gc")); //forwebuser $session_id=Cookie::Get(SESSIONID); /*lengthofsessionid 128-bitdigest(MD5) 4bits/char:32charSID 5bits/char:26charSID 6bits/char:22charSID 160-bitdigest(SHA-1) 4bits/char:40charSID 5bits/char:32charSID 6bits/char:27charSID */ if(!empty($session_id)&&26==strlen($session_id)) session_id($session_id); session_start(); } pubpcfunction__destruct(){ session_write_close(); } pubpcfunctionOpen($save_path,$session_name){ returntrue; } pubpcfunctionClose(){ returntrue; } pubpcfunctionRead($session_id){ $key=SESSION_PREFIX.$session_id; $memcached_cpent_=SessionMemCachedCpent::GetInstance(); return(string)$memcached_cpent_->get($key); } pubpcfunctionWrite($session_id,$data){ $key=SESSION_PREFIX.$session_id; $memcached_cpent_=SessionMemCachedCpent::GetInstance(); if($data) return$memcached_cpent_->set($key,$data,SESSION_EXPIRE_TIME); returntrue; } pubpcfunctionDestroy($session_id){ $key=SESSION_PREFIX.$session_id; $memcached_cpent_=SessionMemCachedCpent::GetInstance(); return$memcached_cpent_->delete($key); } pubpcfunctionGc($maxpfetime){ returntrue; } } Session::Init();
你期待的结果是什么?实际看到的错误信息又是什么?
解决办法:
已经找到问题所在了,我们现在是把session 存在memcache里面,memcache用的是6379端口, 但是之前我是把session存在redis里面,改了php的配置文件,我忘了这一点,所以一直以为代码有问题。
到此,相信大家对“php中session写入失败怎么解决”有了更深的了解,不妨来实际操作一番吧!这里是编程网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
关于php中session写入失败怎么解决的内容到此结束,希望对大家有所帮助。屹东网往后会继续推荐php中session写入失败怎么解决相关内容。