最後更新: 2016-05-09
介紹
php5-xcache 是一個 PHP 的 opcode cacher 及 optimizer 來
opcode cacher 的功能: compiled state of PHP scripts into the shm (RAM)]
optimizer 的功能:
主頁: http://xcache.lighttpd.net/
主要功能:
- Optimized opcode cache.
- Readonly Cacher Protection
- Automatically disables itself if the cache is corrupted
- Disassembler
- Decompiler (opcode --> php code)
-
Administrator Script
view statistics
view cached php/variable list
clear cache - Win32 Binary
Debian 上的安裝
安裝: Debian6:
apt-get install php5-xcache
安裝: Centos6:
yum install php-xcache xcache-admin
安裝後會有以下檔案
- /usr/share/xcache/admin/*.php <-- php xcache panel
- /etc/php5/conf.d/xcache.ini <-- Configure File
- /usr/lib/php5/20060613+lfs/xcache.so <-- 它就是 xcache 的本身
驗證安裝:
在 phpinfo() 可以見到
XCache
XCache XCache Version 3.1.1 Modules Built cacher optimizer coverager
設定
/usr/share/xcache/xcache.ini:
# 載入 xcache zend_extension = /usr/lib/php5/20060613+lfs/xcache.so # Name Default value xcache.admin.user "admin" xcache.admin.pass "Your_PW" <--- (<?php echo md5($your_password) ?>) xcache.admin.enable_auth "on" <--- 當 on 時而 pass 是 "", 那 admin page 是用不到的 xcache.shm_scheme = "mmap" <--- shm allocator scheme implemenation xcache.cacher On xcache.stat = On <--- 當它 Off 時, 系統會有更高效能, 因為 php 不用每次 access 都調用 stat() xcache.optimizer On # #----------------------- # xcache.size = 16M <-- Default: 16M xcache.count = 1 <-- Specify how many chunks to split the cache (cpu count) ( cat /proc/cpuinfo |grep -c processor ) 當那個 chunks 在編譯時, 其他程序/現成無法存取此共享記憶體 如果 "xcache.size=16M" 及 "xcache.count=2" 時, 那每個 pool 只有 8M xcache.slots = 8K <-- hash hints (必須 count(items) > slots) xcache.ttl seconds = 0 <-- 0=forever (unit: sec) xcache.gc_interval = 300 <-- 多久才 scan 1 次 ttl 過期的 cache (unit: sec) # #---------------------- # xcache.var_size = 0 <--- Disable 此功能 xcache.var_slots = 8K xcache.var_gc_interval 300 # #----------------------- # xcache.readonly_protection Off <-- make sure only XCache module itself can modify the shared memory xcache.mmap_path string "/dev/zero" <-- [xcache.coverager] xcache.coverager = Off xcache.coredump_directory "" <-- coverage viewer script 用的 xcache.test Off
獨立 Server 可以設定成
; 0=forever xcache.ttl=0 ; 0=no scan xcache.gc_interval = 0
Readonly Protection
It is implemented by mmap'ing twice on same memory,
1 for read/write(rw) and the other for readonly(ro). XCache stores data into rw cache,
and fix the pointers up to ro cache, so all access is read from the ro memory.
Admin Page
Centos7 Install Xcache
Install:
yum install -y php-xcache xcache-admin
Configure:
/etc/php.d/xcache.ini
[xcache-common] extension = xcache.so xcache.admin.enable_auth = Off xcache.shm_scheme = "mmap" xcache.mmap_path = "/dev/zero" xcache.count = 1 xcache.slots = 8K xcache.size = 64M xcache.var_size = 0M xcache.cacher = On xcache.stat = On xcache.optimizer = Off
Admin Page:
Script:
/usr/share/xcache/xxx.php
設定:
/etc/httpd/conf.d/xcache.conf
Alias /xcache /usr/share/xcache <Directory /usr/share/xcache> # Apache 2.4 Require ip 115.160.172.18 </Directory>
Gen Admin pw
http://x.x.x.x/xcache/cacher/mkpassword.php
PHP 的主要設定檔位於及順序
PHP will scan for SAPI specified ini first in the form of php-{$sapi}.ini, and the general php.ini later
For Example:
- cgi /etc/php-cgi.ini
- cgi-fcgi /etc/php-cgi-fcgi.ini
- cli /etc/php-cli.ini