溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

CentOS下PHP安裝memcache擴(kuò)展問(wèn)題的解決方法

發(fā)布時(shí)間:2021-09-10 17:17:17 來(lái)源:億速云 閱讀:150 作者:chen 欄目:系統(tǒng)運(yùn)維

本篇內(nèi)容介紹了“CentOS下PHP安裝memcache擴(kuò)展問(wèn)題的解決方法”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

系統(tǒng)版本是5.2,把安裝memcached的方法記錄下先:

代碼如下:


cd ~/memcached
wget -c http://www.monkey.org/~provos/libevent-1.4.10-stable.tar.gz
wget -c http://memcached.googlecode.com/files/memcached-1.2.8.tar.gz
#安裝libevent
tar -zxvf libevent-1.4.10-stable.tar.gz
cd libevent-1.4.10-stable
./configure
make
make install
#安裝memcached
cd ..
tar -zxvf memcached-1.2.8.tar.gz
cd memcached-1.2.8
./configure
make
make install
#如果是64位系統(tǒng),還需要把libevent的文件復(fù)制到/wp-content/lib64/下,用來(lái)解決error while loading shared libraries的問(wèn)題
cp -R /wp-content/local/lib/libevent* /wp-content/lib64/

好了,開(kāi)始安裝php的擴(kuò)展,惡夢(mèng)開(kāi)始了,本以為直接用yum來(lái)安裝php-devel.x86_64和php-pecl-memcache.x86_64這兩個(gè)擴(kuò)展就可以了,可裝了后 phpinfo()里根本找不到memcache擴(kuò)展,把已經(jīng)裝的這兩個(gè)擴(kuò)展remove重來(lái),還是不行,goooooooooooooogle,找到了一篇文章《PHP Pecl Memcached module installation problems》,有救嘍,先remove掉php-pecl-memcache.x86_64,然后執(zhí)行了

pecl install memcache

順利安裝上了,打開(kāi)/etc/php.d/看了下,沒(méi)有memcache.ini,好吧,手動(dòng)到/etc/php.ini加上了 extension=memcache.so,好了,重啟httpd,刷新 phpinfo() ,竟然還沒(méi)有,我郁悶了。。

回頭想想,我好像漏了一個(gè)地方?jīng)]有檢查,馬上打開(kāi) /wp-content/lib64/php/modules/ 查看,果然沒(méi)有memcache.so,會(huì)在哪呢? find -name之,原來(lái)躲在 /wp-content/local/lib/php/extensions/no-debug-non-zts-20060613/ 下,復(fù)制到 /wp-content/lib64/php/modules/ 再試,久違的 memcache擴(kuò)展出現(xiàn)了。 T T

CentOS下PHP安裝memcache擴(kuò)展問(wèn)題的解決方法

Memcached參數(shù)說(shuō)明:

  • -d選項(xiàng)是啟動(dòng)一個(gè)守護(hù)進(jìn)程

  • -m分配給Memcache使用的內(nèi)存數(shù)量,單位是MB

  • -u運(yùn)行Memcache的用戶

  • -l監(jiān)聽(tīng)的服務(wù)器IP地址

  • -p設(shè)置Memcache監(jiān)聽(tīng)的端口,最好是1024以上的端口

  • -c最大運(yùn)行的并發(fā)連接數(shù),默認(rèn)是1024,按照你服務(wù)器的負(fù)載量來(lái)設(shè)定

  • -P設(shè)置保存Memcache的pid文件

啟動(dòng):

memcached -d -u root -m 128 -c 8192

查看狀態(tài):

watch “echo stats | nc 127.0.0.1 11211″

CentOS下PHP安裝memcache擴(kuò)展問(wèn)題的解決方法

狀態(tài)說(shuō)明:

  • uptime:memcached運(yùn)行的秒數(shù)

  • cmd_get:查詢緩存的次數(shù)。這兩個(gè)數(shù)據(jù)相除一下就能得到平均每秒請(qǐng)求緩存的次數(shù)


  • cmd_set:設(shè)置key=>value的次數(shù)

  • get_hits:緩存命中的次數(shù)。緩存命中率 = get_hits/cmd_get * 100%

  • scurr_items:現(xiàn)在在緩存中的鍵值對(duì)個(gè)數(shù)

相關(guān)網(wǎng)址:

Libevent:http://www.monkey.org/~provos/libevent/
Memcached:http://danga.com/memcached/
PHP Memcached Extension:http://pecl.php.net/package/memcache

undefined


[shell]
[root@~]# pecl install memcache
downloading memcache-2.2.6.tgz ...
Starting to download memcache-2.2.6.tgz (35,957 bytes)
..........done: 35,957 bytes
11 source files, building
WARNING: php_bin /opt/php/bin/php appears to have a suffix /bin/php, but config variable php_suffix does not match
running: phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
Enable memcache session handler support? [yes] : n
[/shell]

[shell]
running: make INSTALL_ROOT="/var/tmp/pear-build-root/install-memcache-2.2.6" install
Installing shared extensions: /var/tmp/pear-build-root/install-memcache-2.2.6/opt/php/lib/php/extensions/no-debug-non-zts-20090626/
running: find "/var/tmp/pear-build-root/install-memcache-2.2.6" | xargs ls -dils
11370548 4 drwxr-xr-x 3 root root 4096 Jan 6 15:55 /var/tmp/pear-build-root/install-memcache-2.2.6
11370602 4 drwxr-xr-x 3 root root 4096 Jan 6 15:55 /var/tmp/pear-build-root/install-memcache-2.2.6/opt
11370603 4 drwxr-xr-x 3 root root 4096 Jan 6 15:55 /var/tmp/pear-build-root/install-memcache-2.2.6/opt/php
11370604 4 drwxr-xr-x 3 root root 4096 Jan 6 15:55 /var/tmp/pear-build-root/install-memcache-2.2.6/opt/php/lib
11370605 4 drwxr-xr-x 3 root root 4096 Jan 6 15:55 /var/tmp/pear-build-root/install-memcache-2.2.6/opt/php/lib/php
11370606 4 drwxr-xr-x 3 root root 4096 Jan 6 15:55 /var/tmp/pear-build-root/install-memcache-2.2.6/opt/php/lib/php/extensions
11370607 4 drwxr-xr-x 2 root root 4096 Jan 6 15:55 /var/tmp/pear-build-root/install-memcache-2.2.6/opt/php/lib/php/extensions/no-debug-non-zts-20090626
11370601 236 -rwxr-xr-x 1 root root 235639 Jan 6 15:55 /var/tmp/pear-build-root/install-memcache-2.2.6/opt/php/lib/php/extensions/no-debug-non-zts-20090626/memcache.so

Build process completed successfully
Installing '/opt/php/lib/php/extensions/no-debug-non-zts-20090626/memcache.so'
install ok: channel://pecl.php.net/memcache-2.2.6
configuration option "php_ini" is not set to php.ini location
You should add "extension=memcache.so" to php.ini
[/shell]

“CentOS下PHP安裝memcache擴(kuò)展問(wèn)題的解決方法”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI