php操作memcache的代码如下:
[iyunv@robin mc]# cat memcache.php
<?php
$conf = array(
array("host" => '192.168.8.57', "port" => '7522'),
//array("host" => '192.168.90.130', "port" => '7510'),
//array("host" => '192.168.30.22', "port" => '7011')
//array("host" => '192.168.30.23', "port" => '7030')
//array("host" => '192.168.1.61' , "port" => '11211'),
);
$memcache = new Memcache();
memcache_debug(true);
foreach ($conf as $memCachedConfig) {
@$memcache->addServer($memCachedConfig['host'], $memCachedConfig['port']);
}
$str = "test";
@$memcache->set('testkey', $str);
echo $memcache->get('testkey');
echo "\n";
try{
$rs = $memcache->delete('testkey', 0);
}catch( Exception $e ){
print_r($e->getMessage());
}
var_dump($rs);
echo "\n";
echo $memcache->get('testkey');
#备注:192.168.8.57为haproxy的虚ip,后端指向的是192.168.30.21和192.168.30.22这两个twemproxy,然后twemproxy的后端又是192.168.30.21、192.168.30.22、192.168.30.23、192.168.30.24这4个memcache
执行但无法删除的显示结果如下:
[iyunv@robin mc]# php memcache.php
test
bool(false)##如果删除成功显示的应该是true
问题的原因定位是因为php的memcache扩展版本过低造成的,应该是php的低版本memcache的一个bug,升级就可以解决了
升级前:
升级后:
升级步骤:
wget "https://pecl.php.net/get/memcache-3.0.8.tgz"
tar xf memcache-3.0.8.tgz
cd memcache-3.0.8
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
/kuxun/php-cgid restart
php -m | grep mem
查看phpinfo的方法
nginx配置如下:
[iyunv@robin sites-enabled]# vim op.conf
log_format op_log "$remote_addr" - "$remote_user" [$time_local] "$request"
"$status" "$body_bytes_sent" "$http_referer"
"$http_user_agent" "$http_x_forwarded_for";
server {
listen 80;
server_name 192.168.90.99;
set $ROOT_PATH /home/himalayas/op;
location / {
#auth_basic "Password please";
#auth_basic_user_file /usr/local/webserver/nginx/conf/htpasswd;
root $ROOT_PATH;
index index.php;
}
location ~ .php$ {
root $ROOT_PATH;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_param SCRIPT_FILENAME $ROOT_PATH$fastcgi_script_name;
send_timeout 300;
fastcgi_buffers 8 256k;
include /usr/local/webserver/nginx/conf/fastcgi_params;
}
access_log /home/nginxlog/accesslog/access.log op_log;
error_log /home/nginxlog/errorlog/error.log;
}
代码如下:
[iyunv@robin ~]# cat /home/himalayas/op/test.php
<?php
phpinfo();
?>
访问方式:http://192.168.90.99/test.php
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com