IT貓撲網(wǎng):您身邊最放心的安全下載站! 最新更新|軟件分類|軟件專題|手機版|論壇轉(zhuǎn)貼|軟件發(fā)布

您當(dāng)前所在位置: 首頁網(wǎng)絡(luò)編程PHP編程 → linux下為PHP擴展安裝memcache模塊

linux下為PHP擴展安裝memcache模塊

時間:2015-06-28 00:00:00 來源:IT貓撲網(wǎng) 作者:網(wǎng)管聯(lián)盟 我要評論(1)

安裝環(huán)境
RHEL 4
Php 5.2.6


所需軟件
libevent-1.4.6-stable.tar.gz (http://monkey.org/~provos/libevent/)
memcache-2.2.3.tgz (http://pecl.php.net/package/memcache)
memcached-1.2.6.tar.gz (http://www.danga.com/memcached/)


安裝配置

1. 安裝libevent
# tar zxf libevent-1.4.6-stable.tar.gz
# cd libevent-1.4.6-stable
# ./configure --prefix=/usr/local/servers/libevent
# make && make install

2. 安裝memcached
# tar zxvf memcached-1.2.6.tar.gz
# cd memcached-1.2.6
# ./configure --prefix=/usr/local/servers/memcached --with-libevent=/usr/local/servers/libevent
# make && make install

3. 運行memcached
# /usr/local/servers/memcached -d -m 128 -l localhost -p 11211 -u root

-d 以守護(hù)程序(daemon)方式運行 memcached;
-m 設(shè)置 memcached 可以使用的內(nèi)存大小,單位為 M;
-l 設(shè)置監(jiān)聽的 IP 地址,如果是本機的話,通??梢圆辉O(shè)置此參數(shù);
-p 設(shè)置監(jiān)聽的端口,默認(rèn)為 11211,所以也可以不設(shè)置此參數(shù);
-u 指定用戶;

如果遇到運行memcached時遇到問題,錯誤提示如下:

/usr/local/servers/memcached/bin/memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory

則運行 LD_DUBUG=libs 就可以知道m(xù)emcached啟動時庫的加載路徑。具體如下:

# LD_DEBUG=libs /usr/local/servers/memcached/bin/memcached -v
???? 10929:???? find library=libevent-1.4.so.2 [0]; searching
???? 10929:????? search cache=/etc/ld.so.cache
???? 10929:????? search path=/lib/tls/i686/sse2:/lib/tls/i686:/lib/tls/sse2:/lib/tls:/lib/i686/sse2:/lib/i686:/lib/sse2:/lib:/usr/lib/tls/i686/sse2:/usr/lib/tls/i686:/usr/lib/tls/sse2:/usr/lib/tls:/usr/lib/i686/sse2:/usr/lib/i686:/usr/lib/sse2:/usr/lib??? (system search path)
???? 10929: trying file=/lib/tls/i686/sse2/libevent-1.4.so.2
???? 10929: trying file=/lib/tls/i686/libevent-1.4.so.2
???? 10929: trying file=/lib/tls/sse2/libevent-1.4.so.2
???? 10929: trying file=/lib/tls/libevent-1.4.so.2
???? 10929: trying file=/lib/i686/sse2/libevent-1.4.so.2
???? 10929: trying file=/lib/i686/libevent-1.4.so.2
???? 10929: trying file=/lib/sse2/libevent-1.4.so.2
???? 10929: trying file=/lib/libevent-1.4.so.2
???? 10929: trying file=/usr/lib/tls/i686/sse2/libevent-1.4.so.2
???? 10929: trying file=/usr/lib/tls/i686/libevent-1.4.so.2
???? 10929: trying file=/usr/lib/tls/sse2/libevent-1.4.so.2
???? 10929: trying file=/usr/lib/tls/libevent-1.4.so.2
???? 10929: trying file=/usr/lib/i686/sse2/libevent-1.4.so.2
???? 10929: trying file=/usr/lib/i686/libevent-1.4.so.2
???? 10929: trying file=/usr/lib/sse2/libevent-1.4.so.2
???? 10929: trying file=/usr/lib/libevent-1.4.so.2
???? 10929:

然后給libevent-1.4.so.2建立一個鏈接后再運行memcached:
# ln -s /usr/local/servers/libevent/lib/libevent-1.4.so.2 /lib/libevent-1.4.so.2

4. 安裝php的memcache擴展

可以使用php自帶的pecl安裝程序
# /usr/local/servers/php5/bin/pecl install memcache

也可以從源碼安裝
# tar zxf memcache-2.2.3.tgz
# cd memcache-2.2.3
# /usr/local/servers/php5/bin/phpize
# ./configure --enable-memcache=/usr/local/servers/memcached --with-php-config=/usr/local/servers/php5/bin/php-config --with-apxs2=/usr/sbin/apxs
# make && make inst

安裝完后會有類似這樣的提示:
Installing shared extensions: /usr/local/servers/php5/lib/php/extensions/no-debug-non-zts-20060922/

把這個記住,然后修改php.ini,把

extension_dir = "./"
修改為
extension_dir = "/usr/local/servers/php5/lib/php/extensions/"

并添加一行
extension="no-debug-non-zts-20060922/memcache.so"

5. 用phpinfo查看


測試模塊

$memcache = new Memcache;
$memcache->connect('localhost', 12000) or die ("Could not connect");

$version = $memcache->getVersion();
echo "Server's version: ".$version."
\n";

$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;

$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)
\n";

$get_result = $memcache->get('key');
echo "Data from the cache:
\n";

var_dump($get_result);

?>

顯示結(jié)果:

Server's version: 1.2.6
Store data in the cache (data will expire in 10 seconds)
Data from the cache:

object(stdClass)[3]? public 'str_attr' => string 'test' (length=4)? public 'int_attr' => int 123

關(guān)鍵詞標(biāo)簽:linux,PHP擴展,memcac

相關(guān)閱讀

文章評論
發(fā)表評論

熱門文章 plsql developer怎么連接數(shù)據(jù)庫-plsql developer連接數(shù)據(jù)庫方法 plsql developer怎么連接數(shù)據(jù)庫-plsql developer連接數(shù)據(jù)庫方法 2021年最好用的10款php開發(fā)工具推薦 2021年最好用的10款php開發(fā)工具推薦 php利用淘寶IP庫獲取用戶ip地理位置 php利用淘寶IP庫獲取用戶ip地理位置 在 PHP 中使用命令行工具 在 PHP 中使用命令行工具

相關(guān)下載

    人氣排行 詳解ucenter原理及第三方應(yīng)用程序整合思路、方法 plsql developer怎么連接數(shù)據(jù)庫-plsql developer連接數(shù)據(jù)庫方法 PHP中防止SQL注入攻擊 PHP會話Session的具體使用方法解析 PHP運行出現(xiàn)Notice : Use of undefined constant 的解決辦法 PHP如何清空mySQL數(shù)據(jù)庫 CakePHP程序員必須知道的21條技巧 PHP采集圖片實例(PHP采集)