首页 > 后端开发 > php教程 > use memcached and php-memcache(d)

use memcached and php-memcache(d)

WBOY
发布: 2016-06-23 14:31:45
原创
1145 人浏览过

For memcached 1.2 to 1.3, protocol changed for delete(). For memcached 1.4, the wrong format will cause fatal error:
failed with: CLIENT_ERROR bad command line format.
So php pecl-memcache will get failed with the new version.

for php pecl-memcached, because it’s using libmemcache, so no this issue.
We write a function to choose which memcache extension we will use in our code:

$mem_flag = 0;$mem_conn = null;function mcached_conn(){	global $config, $mem_flag, $mem_conn;	if($mem_flag != 1)	{		if ($config['mcache']['version']==0){		$mem_conn = memcache_pconnect($config['mcache']['host'], 11211);		} else {			$mem_conn = new Memcached();			$mem_conn->addServer($config['mcache']['host'], 11211);		}		$mem_flag = 1;	}	return $mem_conn;}function memcache_version_set($memcache_obj, $key,$value,$flag,$ttl){	global $config;	if ($config['mcache']['version']==0){		return memcache_set($memcache_obj, $key,$value,$flag,$ttl);	} else {		return $memcache_obj->set($key,$value,$ttl);	}}	function memcache_version_get($memcache_obj, $key){	global $config;	if ($config['mcache']['version']==0){		return memcache_get($memcache_obj, $key);	} else {		return $memcache_obj->get($key);	}}function memcache_version_del($memcache_obj, $key){	global $config;	if ($config['mcache']['version']==0){		return memcache_delete($memcache_obj, $key);	} else {		return $memcache_obj->delete($key);	}}
登录后复制

?
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板