php ci框架 里面使用 memcache 存 session

传送门

https://github.com/cnsaturn/codeigniter-my-session

http://blog.csdn.net/weilee2009/article/details/7658260

又一个使用PHP原生Session机制来代替CI默认Cookie机制Session的解决方案;同时,如果服务器支持memcached,那么本类也可以使用Memcached作为Session文件的存储容器(默认使用文本文件),从而极大提升程序性能。同时,它与CI默认Session使用方法完全一致。无需因为使用此库而修改任何目前的代码。

http://php.net/memcached


Memcached

add a note add a note

User Contributed Notes 4 notes

up
44
joelhy
4 years ago
For those confuse about the memcached extension and the memcache extension, the short story is that both of them are clients of memcached server, and the memcached extension offer more features than the memcache extension.
up
4
gabriel dot maybrun at demandmedia dot com
10 months ago
GOTCHA: Recently I was tasked with moving from PECL memcache to PECL memcached and ran into a major problem -- memcache and memcached serialize data differently, meaning that data written with one library can't necessarily be read with the other library.

For example, If you write an object or an array with memcache, it's interpreted as an integer by memcached.  If you write it with memcached, it's interpreted as a string by memcache.

tl;dr - You can't safely switch between memcache and memcached without a either a cache flush or isolated cache environments.

<?php
$memcache
= new Memcache;
$memcacheD = new Memcached;
$memcache->addServer($host);
$memcacheD->addServers($servers);

$checks = array(
   
123,
   
4542.32,
   
'a string',
   
true,
    array(
123, 'string'),
    (object)array(
'key1' => 'value1'),
);
foreach (
$checks as $i => $value) {
    print
"Checking WRITE with Memcache\n";
   
$key = 'cachetest' . $i;
   
$memcache->set($key, $value);
   
usleep(100);
   
$val = $memcache->get($key);
   
$valD = $memcacheD->get($key);
    if (
$val !== $valD) {
        print
"Not compatible!";
       
var_dump(compact('val', 'valD'));
    }

    print
"Checking WRITE with MemcacheD\n";
   
$key = 'cachetest' . $i;
   
$memcacheD->set($key, $value);
   
usleep(100);
   
$val = $memcache->get($key);
   
$valD = $memcacheD->get($key);
    if (
$val !== $valD) {
        print
"Not compatible!";
       
var_dump(compact('val', 'valD'));
    }
}
up
1
davidt
2 years ago
The module also supports SASL authentication, it just isn't documented sadly. You'll need to run the following code:

<?php
$m
= new Memcached();
$m->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
$m->setSaslAuthData("user-1", "pass");
?>

You need to enable the "memcached.use_sasl = 1" ini option for memcached in the php.ini file.
up
0
mike at eastghost dot com
3 years ago
It's Feb 2012, and I just spent half a day tracing a weird and sporadic problem back to Memcached extension (vers 1.0.2), which would randomly return SYSTEM ERROR and fail to either get or put data into unix memcached.  Made one single change from Memcached extension back to Memcache extension and problem instantly vanished.

A year or three ago, I had changed from Memcache to Memcached for some other reason.

Now I'm on a mission to transcend the Memcache/Memcached fiasco.  I'm going to try APC's variable cache, and if that doesn't work better than just revert to using a key:value stash collection in Mongo.

Basically, the Memcache / Memcache driver fiasco, which has been going on apparently for years now, has ruined serious use of unix memcached on PHP...unless you're huge and can afford to create your own MemcacheX driver...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值