温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-07-26 14:44:01 来源:网络 阅读:498 作者:Tenderrain 栏目:web开发

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,升级就可以解决了

升级前:

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

升级后:

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

升级步骤:

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

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI