添加php模塊APC或xcache

1、APC,全稱是Alternative PHP Cache,官方翻譯叫」可選PHP緩存」。它爲咱們提供了緩存和優化PHP的中間代碼的框架。 APC的緩存分兩部分:系統緩存和用戶數據緩存。
系統緩存
它是指APC把PHP文件源碼的編譯結果緩存起來,而後在每次調用時先對比時間標記。若是未過時,則使用緩存的中間代碼運行。默認緩存3600s(一小時)。可是這樣仍會浪費大量CPU時間。所以能夠在php.ini中設置system緩存爲永不過時(apc.ttl=0)。不過若是這樣設置,改運php代碼後須要重啓WEB服務器。目前使用較多的是指此類緩存。
用戶數據緩存
緩存由用戶在編寫PHP代碼時用apc_store和apc_fetch函數操做讀取、寫入的。若是數據量不大的話,能夠一試。若是數據量大,使用相似memcache此類的更佳
2、編譯安裝:
wget http://pecl.php.net/get/APC-3.1.9.tgz
tar xzvf APC-3.1.9.tgz
cd APC-3.1.9
/usr/local/php/bin/phpize
./configure --enable-apc --enable-apc-mmap --with-php-config=/usr/local/php/bin/php-config --prefix=/usr/local/apc
make && make install
ll  /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
vi /etc/php.ini
添加模塊
[apc]
extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/apc.so"
apc.enabled = 1
apc.cache_by_default = on
apc.shm_segments = 1
apc.shm_size = 64
apc.ttl = 7200
apc.user_ttl = 7200
apc.num_files_hint = 0
apc.write_lock = On
3、yum安裝:
首先要安裝apc的依賴包:
yum install php-pear php-devel httpd-devel pcre-devel gcc make
而後使用pecl安裝apc:
pecl install apc
添加apc擴展到配置文件:
echo "extension=apc.so" > /etc/php.d/apc.ini
最後記得重啓服務器:
service httpd restart ,而後檢查的phpinfo()中的函數信息
4、另一款php加速器XCache
wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz
tar xvzf xcache-3.2.0.tar.gz
cd xcache-3.2.0
/usr/local/php/bin/phpize
./configure --enable-xcache --enable-xcache-coverager --with-php-config=/usr/local/php/php-config --prefix=/usr/local/xcahe
make
make install
mv /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so /usr/local/php/lib/php/extensions/PECL
在php.ini添加配置信息:
extension = xcache.so
; xcache
xcache.admin.user = "admin"
xcache.admin.pass = "(執行) echo ’(你的密碼)’|md5sum(得出的密文)"
;
xcache.size = 24M
xcache.shm_scheme = "mmap"
xcache.count = 2
xcache.slots = 8k
xcache.ttl = 0
xcache.gc_interval = 0
xcache.var_size = 8M
xcache.var_count = 1
xcache.var_slots = 8k
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = On
xcache.mmap_path = "/tmp/xcache"
xcache.coredump_directory = ""
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off
;
xcache.coverager = On
xcache.coveragedump_directory = ""
建立緩存目錄,重啓nginx/php-fpm,查看phpinfo()信息
mkdir /tmp/xcache
chmod 777 /tmp/xcache
若php是yum安裝的,方法以下
wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz
tar xvzf xcache-3.2.0.tar.gz
cd xcache-3.2.0    
/usr/bin/phpize
./configure --enable-xcache --enable-xcache-coverager --with-php-config=/usr/bin/php-config --prefix=/usr/local/xcache
make && make install
生的擴展文件:/usr/lib/php5/20131226/xcache.so 
在php.ini尾部添加:
extension = xcache.so
重啓php-fpm和nginx後查看phpinfo()信息!
另一個加速器eaccelerator
下載:wget --no-check-certificate https://codeload.github.com/eaccelerator/eaccelerator/legacy.tar.gz/master
重命名下來來的master: mv master eaccelerator.tar.gz
解壓縮:tar zvxf eaccelerator.tar.gz cd eaccelerator-eaccelerator-42067ac
加載phpize: /usr/local/php/bin/phpize
配置: ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
執行安裝: make && make install
完成,而後在php.ini中加入:
extension = "eaccelerator.so"
; Local Variables:
; tab-width: 4
; End:
;eaccelerator
eaccelerator.shm_size = "1"
eaccelerator.cache_dir = "/tmp/eaccelerator"
eaccelerator.enable = "1"
eaccelerator.optimizer = "0"
eaccelerator.debug = "0"
eaccelerator.name_space = ""
eaccelerator.check_mtime = "1"
eaccelerator.filter = ""
eaccelerator.shm_max = "0"
eaccelerator.shm_ttl = "3600"
eaccelerator.shm_prune_period = "3600"
eaccelerator.shm_only = "0"
eaccelerator.compress = "0"
eaccelerator.compress_level = "9"
 php

相關文章
相關標籤/搜索