码迷,mamicode.com
首页 > Web开发 > 详细

php经过twemproxy无法delete后端memcache值的解决方法

时间:2015-04-01 20:18:05      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:php twemproxu

php操作memcache的代码如下:


[root@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


执行但无法删除的显示结果如下:

[root@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配置如下:

[root@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;
}

代码如下:

[root@robin ~]# cat /home/himalayas/op/test.php
<?php
phpinfo();
?>

访问方式:http://192.168.90.99/test.php

php经过twemproxy无法delete后端memcache值的解决方法

标签:php twemproxu

原文地址:http://tenderrain.blog.51cto.com/9202912/1627342

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!