您好,登錄后才能下訂單哦!
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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。