Compile php+php-fpm with ICC v11.1
打算把生产环境的PHP升级到5.2.11, 于是重新使用ICC编译了PHP-5.2.11+PHP-FPM-0.6.
结果编译时失败,出现以下错误:
fpm_atomic.h(116): catastrophic error: #error directive: unsupported architecture. please write a patch and send it in
#error unsupported architecture. please write a patch and send it in
开始以为是我使用独立安装造成的,不过尝试了integrated安装,问题也一样.
于是检查了fpm_atomic.h 116行:
#else
#error unsupported architecture. please write a patch and send it in
#endif
原来是没有检测当前arch的宏分支. 由于icc的x86_64是定义了__x86_64 而不是__amd64__.
修改了一下:
#elif ( __amd64__ || __amd64 || __x86_64__ )
Patch (php-fpm-icc.patch) :
=====================================
@@ -37,7 +37,7 @@
return res;
}
-#elif ( __amd64__ || __amd64 )
+#elif ( __amd64__ || __amd64 || __x86_64__ )
typedef int64_t atomic_int_t;
typedef uint64_t atomic_uint_t;
======================================
我把patch提交到了php-fpm mailinglist.
附:更新版本的PHP-5.2.11+php-fpm0.6-x86_64 编译过程:
环境准备:
* Icc v11.1.059 EM64T
* MYSQL: mysql-percona分支, ICC优化
* google-perftools-1.4 (我使用tcmallock_minimal来优化PHP)
* php-5.2.11.tar.bz2
* php-fpm-0.6~5.2.11.tar.gz
1. 生成php-fpm patch
tar zxvf php-fpm-0.6~5.2.11.tar.gz
cd php-fpm-0.6-5.2.11
cd fpm
path -p0 < php-fpm-icc.patch ( 这是修正fpm_atomic.h)
cd ../..
./php-fpm-0.6-5.2.11/generate-fpm-patch
这生成一个fpm.patch
2. 准备php源码
tar zxvf php-5.2.11.tar.gz
cd php-5.2.11
patch -p1 < ../fpm.patch
./buildconf –force
3. 编译:
./compile-php.sh
=======compile-php.sh============
#!/bin/bash
make distclean
VERSION=5.2.11
DEST=/opt/php-$VERSION
CFLAGS=’ -O3 -ip -unroll2 -no-prec-div -fp-model source -restrict -static-intel -xSSE2,SSE3,SSE4.1,SSE4.2 -axSSE2,SSE3,SSE4.1,SSE4.2 ‘ \
CXXFLAGS=’ -O3 -ip -unroll2 -no-prec-div -fp-model source -restrict -static-intel -xSSE2,SSE3,SSE4.1,SSE4.2 -axSSE2,SSE3,SSE4.1,SSE4.2 -fno-implicit-templates -fno-exceptions -fno-rtti’ \
LDFLAGS=’ -ltcmalloc_minimal -L/opt/local/lib’ \
CC=icc \
CXX=icpc \
LD=xild \
AR=xiar \
./configure \
–prefix=$DEST \
–with-libdir=lib64 \
–with-fpm \
–enable-force-cgi-redirect \
–enable-fastcgi \
–enable-mbstring \
–enable-mbregex \
–enable-pcntl \
–enable-exif \
–enable-sockets \
–enable-sysvsem \
–enable-sysvshm \
–enable-inline-optimization \
–enable-zend-multibyte \
–disable-ipv6 \
–disable-debug \
–with-mysql=/opt/mysql \
–with-mysqli \
–with-config-file-path=$DEST/etc \
–with-config-file-scan-dir=$DEST/etc/php.d \
–with-zlib \
–with-curl \
–with-gettext \
–with-jpeg-dir=/usr \
–with-png-dir=/usr \
–with-freetype-dir=/usr \
–with-iconv \
–with-pcre-regex
make install
[ -e $DEST/etc/php.ini ] || cp -u php.ini-recommend $DEST/etc/php.ini
我习惯把所有优化过的lib都安装到/opt/local,因此需要修改成你自己的配置(通常是/usr/local)
备注:
1. 以上脚本是将php-fpm使用integrated方式安装. 省事也是官方推荐的方式.
2. 若使用mysqlnd,可以修改为:
–with-mysql=mysqlnd \
–with-mysqli=mysqlnd \
不过由于mysqlnd只在官方的5.3中存在,除了我自己的特制php source,估计没人会在5.2.x使用到mysqlnd吧.
Comments
Leave a Reply