您好,登錄后才能下訂單哦!
php的memcache模塊:
下載地址:http://pecl.php.net/package/memcache
下載并配置生成php的memcache模塊
wget http://pecl.php.net/get/memcache-3.0.8.tgz
yum install -y m4 autoconf
tar -zxvf memcache-3.0.8.tgz
cd memcache-3.0.8
/usr/local/php/bin/phpize //生成.config文件
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
mkdir /usr/local/php/ext 創(chuàng)建一個(gè)統(tǒng)一的存放擴(kuò)展目錄
打開php.ini
如果沒有php.ini {cp /usr/local/src/php-5.3.27/php.ini-production /usr/local/php/etc/php.ini}
添加:extension_dir = "/usr/local/php/ext"定義一個(gè)統(tǒng)一的存放目錄。
cp /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/memcache.so /usr/local/php/ext 復(fù)制模塊進(jìn)目錄里
然后再編輯php.ini在最后添加一行extension = memcache.so
檢測(cè)一下/usr/local/php/bin/php -m |grep memcache 查看模塊是否已經(jīng)加載上。
用一個(gè)php腳本:
<?php
//連接Memcache Memcache ip地址可以改
$mem = new Memcache;
$mem->connect("192.168.47.26", 11211);
//保存數(shù)據(jù)
$mem->set('key1', 'This is first value', 0, 60);
$val = $mem->get('key1');
echo "Get key1 value: " . $val ."<br>";
//替換數(shù)據(jù)
$mem->replace('key1', 'This is replace value', 0, 60);
$val = $mem->get('key1');
echo "Get key1 value: " . $val . "<br>";
//保存數(shù)組數(shù)據(jù)
$arr = array('aaa', 'bbb', 'ccc', 'ddd');
$mem->set('key2', $arr, 0, 60);
$val2 = $mem->get('key2');
echo "Get key2 value: ";
print_r($val2);
echo "<br>";
//刪除數(shù)據(jù)
$mem->delete('key1');
$val = $mem->get('key1');
echo "Get key1 value: " . $val . "<br>";
//清除所有數(shù)據(jù)
$mem->flush();
$val2 = $mem->get('key2');
echo "Get key2 value: ";
print_r($val2);
echo "<br>";
//關(guān)閉連接
$mem->close();
?>
實(shí)現(xiàn)session共享:
在php.ini里配置連接:
添加:
session.save_handler = "memcache"
session.save_path = "tcp://192.168.47.26:11211"
在httpd.conf【LAMP】里配置連接:apache
虛擬主機(jī)配置添加:
php_value session.save_handler "memcache"
php_value session.save_path "tcp://192.168.47.26:11211"
在php-fpm.conf【LNMP】里配置連接:nginx
對(duì)應(yīng)的pool里面添加:
php_value[session.save_handler] = memcache
php_value[session.save_path] = "tcp://192.168.47.26:11211"
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。