話說PHP官方發布PHP5.4已經有一陣了,根據使用的情況來看,似乎還是很不錯的。從初始發布到現在升級到的PHP5.4.4,修正不少的Bug。PHP5.4新的版本,除了提供了更多新的特性,還有大幅的效率提升。這個版本趨於穩定之后,我決定把我的服務器升級到PHP5.4.4。
服務器上的軟件包,一直以來都是編譯安裝,因此對於這些東西自己也是比較可控的。從PHP官方網站下載最新的源代碼包,解壓縮並且安裝,這沒有什么特別的。以下是我使用的安裝編譯參數:
./configure --prefix=/usr/local/php-5.4.4/ --with-config-file-path=/usr/local/php-5.4.4/etc --with-mysql --with-mysqli --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-pdo-mysql
make ZEND_EXTRA_LIBS='-liconv'
make install
在安裝eaccelerator的時候,出現了奇葩的錯誤:/home/package/eaccelerator-0.9.6.1/eaccelerator.c: In function ‘eaccelerator_restore’:
/home/package/eaccelerator-0.9.6.1/eaccelerator.c:878: warning: assignment discards qualifiers from pointer target type
/home/package/eaccelerator-0.9.6.1/eaccelerator.c: In function ‘eaccelerator_compile_file’:
/home/package/eaccelerator-0.9.6.1/eaccelerator.c:1317: error: ‘zend_class_entry’ has no member named ‘line_start’
/home/package/eaccelerator-0.9.6.1/eaccelerator.c: At top level:
/home/package/eaccelerator-0.9.6.1/eaccelerator.c:1913: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘eaccelerator_functions’
/home/package/eaccelerator-0.9.6.1/eaccelerator.c:1938: error: ‘eaccelerator_functions’ undeclared here (not in a function)
make: *** [eaccelerator.lo] Error 1
看報錯情況來看,eaccelerator似乎與新版本的PHP不兼容。於是分別嘗試了另外兩個加速器,APC和xcache。
安裝APC時出現了一個比較糾結的問題,啟動php-fpm時會報出php-fpm Segmentation fault錯誤,后來在網上搜索了之后沒有發現解決方案,之后便選定了xcache。看到官方網站上最近發布的2.0版本,已經完全支持了PHP5.4,於是下載回來編譯安裝,一切正常!
之前看過一個關於三種加速器性能比較的文章(傳送門:《關於PHP加速eAccelerator、APC和Zend Optimizer》),發現三者的懸殊較小,eaccelerator以微弱優勢勝出。看來,選擇xcache也是個不錯的選擇。