標籤:src start uil release 頁面 apach 傳遞 fas 規則
PHP預設會將Operate Code檔案丟棄,緩衝加速是將其儲存下來,放置共用記憶體中,以便在下次調用該PHP頁面時重用,避免相同代碼的重複編譯
___________________________________________________________
■ LAMP環境PHP解析原理
___________________________________________________________
Apache接收客戶的PHP程式請求,並根據規則過濾之
Apache將PHP程式請求傳遞給PHP處理模組libphp5.so
PHP引擎定位磁碟上的PHP檔案,並將其載入到記憶體中解析
PHP處理模組libphp5.so將PHP源碼編譯成opcode
PHP處理模組libphp5.so執行opcode,然後把opcode緩衝起來
Apache接收用戶端新的PHP程式請求,PHP引擎直接讀取緩衝執行opcode檔案,並將結果返回
■ LNMP環境PHP解析原理
___________________________________________________________
Nginx接收用戶端的PHP程式訪問請求
Nginx根據副檔名等過濾規則將PHP程式請求傳遞給解析PHP的FCGI(PHP FPM)進程
PHP FPM進程調用PHP解析器讀取網站磁碟上的PHP檔案,並載入到記憶體中
PHP解析器將PHP程式編譯成為opcode檔案,然後把opcode緩衝起來
PHP FPM引擎執行opcode樹後,返回資料給Nginx,進而返回用戶端
Nginx接收客戶新的PHP程式請求,PHP FPM引擎就會直接讀取緩衝中的opcode並執行,將結果返回
■ 緩衝加速外掛程式安裝配置(xcache)
___________________________________________________________
[root@Web_server src]# wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.bz2
[root@Web_server src]# tar xf xcache-3.2.0.tar.bz2
[root@Web_server src]# cd xcache-3.2.0
[root@Web_server xcache-3.2.0]# /usr/local/php/bin/phpize
[root@Web_server xcache-3.2.0]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
[root@Web_server xcache-3.2.0]# make && make install
[root@Web_server xcache-3.2.0]# ll /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/
total 2208
-rwxr-xr-x 1 root root 1021684 Apr 13 10:33 opcache.a
-rwxr-xr-x 1 root root 538161 Apr 13 10:33 opcache.so
-rwxr-xr-x 1 root root 692628 Apr 18 09:44 xcache.so #<==產生xcache.so模組
[root@Web_server xcache-3.2.0]# cat /usr/local/src/xcache-3.2.0/xcache.ini >> /usr/local/php/etc/php.ini
[root@Web_server xcache-3.2.0]# tail -85 /usr/local/php/etc/php.ini | egrep -v "^;|^$"
[xcache-common]
extension = xcache.so
[xcache.admin]
xcache.admin.enable_auth = On
xcache.admin.user = "mOo"
xcache.admin.pass = "md5 encrypted password"
[xcache]
xcache.shm_scheme = "mmap"
xcache.size = 256M
xcache.count = 2
xcache.slots = 8K
xcache.ttl = 86400
xcache.gc_interval = 3600
xcache.var_size = 64M
#更改標紅參數,生產環境根據硬體和業務資料來調整
[root@Web_server xcache-3.2.0]# /usr/local/php/bin/php -v #檢查配置
PHP 5.5.31 (cli) (built: Apr 13 2016 10:29:58)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
with XCache v3.2.0, Copyright (c) 2005-2014, by mOo
with XCache Cacher v3.2.0, Copyright (c) 2005-2014, by mOo
[root@Web_server ~]# echo -n "szk" |md5sum
[root@Web_server ~]# vim /usr/local/php/etc/php.ini #配置xcache使用者密碼
xcache.admin.user = "szk"
xcache.admin.pass = "005eff7dd9626f0c30f2eb8003ceafc9"
[root@Web_server ~]# cp -a /usr/local/src/xcache-3.2.0/htdocs/ /data/www/xadmin
[root@Web_server ~]# chown -R nobody.nobody /data/www/xadmin
[root@Web_server ~]# /etc/init.d/php-fpm start
■ 緩衝加速外掛程式安裝配置(OPcache)
___________________________________________________________
#若5.5版本,會自動安裝opcache外掛程式,編譯時間--enable=opcache啟用
[root@Web_server ~]# ll /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/
-rwxr-xr-x 1 root root 538161 Apr 13 10:33 opcache.so
[root@Web_server ~]# vim /usr/local/php/etc/php.ini #若編譯沒有啟用,則在設定檔中添加下面內容即可
zend_extension=opcache.so
[opcache]
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable=1
opcache.enable_cli=1
[root@Web_server ~]# /usr/local/php/bin/php -v
PHP 5.5.31 (cli) (built: Apr 13 2016 10:29:58)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
PHP開啟緩衝加速