1. 程式人生 > >CentOS環境PHP下安裝memcache擴充套件

CentOS環境PHP下安裝memcache擴充套件

注意:必須要memcache上下對包,memcached和memcache php擴充套件,先安裝memcached

1、安裝libmemcached庫

      yum install libmemcached

2、下載並解壓memcache檔案

     wget http://pecl.php.net/get/memcache-3.0.8.tgz  

     tar xzvf memcache-3.0.8.tgz  

     cd memcache-3.0.8

3、執行phpize擴充套件安裝程式,假設phpzie的路徑為/usr/local/php/bin/phpize,具體的路徑得根據自己的環境修改。

[[email protected] memcache-3.0.8]# /usr/local/php/bin/phpize

Configuring for:

PHP Api Version:         20100412

Zend Module Api No:      20100525

Zend Extension Api No:   220100525

4、開始安裝擴充套件memcache

 [[email protected] memcache-3.0.8]# ./configure --enable-memcache \

   --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir \ 

make && make install  

安裝完成後,提示

Build complete.

Don't forget to run 'make test'.

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/

5、最後修改php.ini檔案,在zend之前加入如下程式碼。

vim /usr/local/php/lib/php.ini

extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/memcache.so

6、重新啟動php-fpm

kill -QUIT pid

/usr/local/php/sbin/php-fpm

7、通過phpinfo()可以檢視memcached資訊

8、啟動memecached

 ./memcached -d -m 100 -l 192.168.1.120 -p 11211 -u root

9、測試

附php的memcache測試程式碼:

<?php

$mem = new Memcache;

$mem->connect("192.168.1.120", 11211)  or die("Could not connect");

$version = $mem->getVersion();

echo "Server's version: ".$version."<br/>\n";

$mem->set('hellokey', 'Hello World', 0, 600) or die("Failed to save data at the memcached server");

echo "Store data in the cache (data will expire in 600 seconds)<br/>\n";

$get_result = $mem->get('hellokey');

echo "$get_result is from memcached server.";        

?>

檢視命中結果

telnet 192.168.1.120 11211

輸入命令:status