| Subcribe via RSS

PHP静态,动态编译性能对比测试

10月 28th, 2008 | 2 Comments | Posted in PHP < by Johnny Woo >

1. 软件版本
Web服务器
nginx-0.7.17
php-5.2.6
eaccelerator-0.9.5.3
2. PHP编译方式
第一种为纯静态编译
编译参数如下

./configure --prefix=/usr/local/webserver/php-static \
--with-config-file-path=/usr/local/webserver/php-static \
--enable-fastcgi \
--enable-fpm \
--enable-force-cgi-redirect \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--enable-gd-native-ttf \
--with-freetype-dir \
--with-mysql=/usr/local/mysql \
--with-mcrypt \
--with-mhash \
--with-curl \
--with-curlwrappers \
--with-zlib-dir \
--with-zlib \
--with-pear \
--with-openssl \
--without-pdo-sqlite \
--without-sqlite \
--disable-debug \
--disable-rpath \
--without-iconv \
--enable-bcmath \
--enable-pcntl \
--enable-mbstring \
--enable-exif \
--enable-zip \
--enable-ftp

第二种以及第三种将所有模块作为动态链接库
编译参数如下

./configure --prefix=/usr/local/webserver/php \
--with-config-file-path=/usr/local/webserver/conf \
--enable-fastcgi \
--enable-fpm \
--with-fpm-conf=/usr/local/webserver/conf/php-fpm.conf \
--enable-force-cgi-redirect \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--enable-gd-native-ttf \
--with-freetype-dir \
--with-mysql=/usr/local/webserver/mysql \
--with-libxml-dir \
--with-curl \
--with-curlwrappers \
--with-zlib \
--with-pear \
--enable-mbstring \
--enable-exif \
--disable-debug \
--disable-rpath \
--without-pdo-sqlite \
--without-sqlite \
--without-iconv

3.测试方法
将bcmath模块作为测试对象,以下为测试脚本

<?php
$a = '1.234';
$b = '5';
$i=0;
while($i<1000)
{
    
echo bcadd($a, $i);   
    
echo bcadd($a, $i, 4)
    
echo bcdiv($i, '6.55957', 3);
    
$i++;
}
?>

另一台服务器发起http_load对指定脚本进行获取.对比最终的fetch数
4.测试数据
全部模块为静态编译,加载eaccelerator
USER %CPU %MEM VSZ RSS TTY STAT START TIME
root 0 1.2 94740 3284 ? Ss 04:44 00:00
nobody 0.3 1.8 95232 4720 ? S 04:44 00:00
nobody 0.2 1.6 95128 4368 ? S 04:44 00:00
nobody 0.3 1.6 95128 4368 ? S 04:44 00:00
nobody 0.3 1.6 95128 4368 ? S 04:44 00:00
nobody 0.4 1.6 95128 4368 ? S 04:44 00:00
nobody 0.4 1.6 95128 4368 ? S 04:44 00:00
nobody 0.4 1.6 95128 4368 ? S 04:44 00:00
nobody 0.4 1.6 95128 4368 ? S 04:44 00:00
nobody 0.3 1.6 95128 4368 ? S 04:44 00:00
nobody 0.3 1.6 95128 4368 ? S 04:44 00:00
nobody 0.4 1.6 95128 4368 ? S 04:44 00:00
nobody 0.4 1.6 95128 4368 ? S 04:44 00:00
nobody 0.4 1.6 95128 4372 ? S 04:44 00:00
nobody 0.4 1.6 95128 4372 ? S 04:44 00:00
nobody 0.8 1.6 95128 4372 ? S 04:44 00:00
nobody 0.5 1.6 95128 4372 ? S 04:44 00:00
nobody 0.9 1.6 95128 4372 ? S 04:44 00:00
nobody 2.9 1.6 95128 4372 ? S 04:44 00:01
nobody 9.6 1.6 95128 4376 ? S 04:45 00:02
nobody 10.8 1.6 95128 4376 ? S 04:45 00:02
nobody 9.9 1.6 95128 4376 ? S 04:45 00:02
nobody 10.6 1.6 95128 4376 ? S 04:45 00:02
nobody 10.1 1.6 95128 4376 ? S 04:45 00:02
nobody 10 1.6 95128 4376 ? S 04:45 00:01
nobody 5.6 1.6 95128 4376 ? S 04:45 00:00
SUM 76.6 41.4 2473044 112916
速度测试结果
161.396 fetches/sec, 2.75422e+06 bytes/sec
166.377 fetches/sec, 2.83923e+06 bytes/sec
164.772 fetches/sec, 2.81184e+06 bytes/sec
164.692 fetches/sec, 2.81047e+06 bytes/sec
166.4 fetches/sec, 2.83962e+06 bytes/sec

只加载bcmath动态库以及eaccelerator
USER %CPU %MEM VSZ RSS TTY STAT START TIME
root 0 1.1 89944 3104 ? Ss 04:49 00:00
nobody 1.1 1.7 90396 4508 ? S 04:49 00:00
nobody 1.4 1.5 90336 4156 ? S 04:49 00:00
nobody 1.2 1.5 90336 4156 ? S 04:49 00:00
nobody 1.2 1.5 90336 4156 ? S 04:49 00:00
nobody 1 1.5 90336 4156 ? S 04:49 00:00
nobody 1.2 1.5 90336 4156 ? S 04:49 00:00
nobody 0.8 1.5 90336 4156 ? S 04:49 00:00
nobody 0.9 1.5 90336 4156 ? S 04:49 00:00
nobody 0.8 1.5 90336 4156 ? S 04:49 00:00
nobody 1.1 1.5 90336 4156 ? S 04:49 00:00
nobody 1 1.5 90336 4156 ? S 04:49 00:00
nobody 1 1.5 90336 4156 ? S 04:49 00:00
nobody 1.1 1.5 90336 4156 ? S 04:49 00:00
nobody 1 1.5 90336 4156 ? S 04:49 00:00
nobody 1.2 1.5 90336 4156 ? S 04:49 00:00
nobody 1.2 1.5 90336 4156 ? S 04:49 00:00
nobody 1.1 1.5 90336 4156 ? S 04:49 00:00
nobody 1 1.5 90336 4156 ? S 04:49 00:00
nobody 1.1 1.5 90336 4156 ? S 04:49 00:00
nobody 3.2 1.5 90336 4156 ? S 04:49 00:02
nobody 9.6 1.5 90336 4156 ? S 04:49 00:02
nobody 10.2 1.5 90336 4156 ? S 04:49 00:02
nobody 10.3 1.5 90336 4156 ? S 04:49 00:02
nobody 8.6 1.5 90336 4156 ? S 04:49 00:02
nobody 9.1 1.5 90336 4156 ? S 04:49 00:02
SUM 71.4 38.8 2348404 107356
速度测试结果
161.5 fetches/sec, 2.756e+06 bytes/sec
163.6 fetches/sec, 2.79183e+06 bytes/sec
162.5 fetches/sec, 2.77306e+06 bytes/sec
160.098 fetches/sec, 2.73208e+06 bytes/sec
162.592 fetches/sec, 2.77464e+06 bytes/sec

所有动态库全部加载
USER %CPU %MEM VSZ RSS TTY STAT START TIME
root 0 1.2 98460 3220 ? Ss 04:46 00:00
nobody 3 1.6 98848 4320 ? S 04:46 00:02
nobody 1.8 1.6 98848 4320 ? S 04:46 00:01
nobody 3 1.6 98848 4320 ? S 04:46 00:02
nobody 2.9 1.6 98848 4320 ? S 04:46 00:02
nobody 1.5 1.6 98848 4320 ? S 04:46 00:01
nobody 1.2 1.6 98848 4320 ? S 04:46 00:00
nobody 1.4 1.6 98848 4320 ? S 04:46 00:00
nobody 1.5 1.6 98848 4320 ? S 04:46 00:01
nobody 2 1.6 98848 4320 ? S 04:46 00:01
nobody 4 1.6 98848 4320 ? S 04:46 00:02
nobody 1.3 1.6 98848 4320 ? S 04:46 00:00
nobody 1.5 1.6 98848 4320 ? S 04:46 00:01
nobody 1.5 1.6 98848 4320 ? S 04:46 00:01
nobody 1.3 1.6 98848 4320 ? S 04:46 00:00
nobody 1.3 1.6 98848 4320 ? S 04:46 00:00
nobody 1.5 1.6 98848 4320 ? S 04:46 00:01
nobody 1.5 1.6 98848 4320 ? S 04:46 00:01
nobody 3.2 1.6 98848 4320 ? S 04:46 00:02
nobody 3.6 1.6 98848 4320 ? S 04:46 00:02
nobody 1.9 1.6 98848 4320 ? S 04:46 00:00
nobody 7.2 1.6 98848 4320 ? S 04:47 00:01
nobody 0 1.6 98848 4320 ? S 04:47 00:00
nobody 7.9 1.6 98848 4320 ? S 04:47 00:00
nobody 1.4 1.6 98848 4320 ? S 04:47 00:00
nobody 3.2 1.6 98848 4320 ? S 04:47 00:00
SUM 60.6 41.2 2569660 111220
速度测试结果
160.9 fetches/sec, 2.74576e+06 bytes/sec
164.6 fetches/sec, 2.8089e+06 bytes/sec
164.1 fetches/sec, 2.80036e+06 bytes/sec
164.2 fetches/sec, 2.80207e+06 bytes/sec
163.7 fetches/sec, 2.79354e+06 bytes/sec

同时我们测试phpinfo函数
对比结果如下
加载全部模块/静态编译
251.4 fetches/sec
257.799 fetches/sec
258.993 fetches/sec
257.798 fetches/sec
249.2 fetches/sec
只加载最小模块
290.199 fetches/sec
332.1 fetches/sec
332.5 fetches/sec
319.8 fetches/sec
332.8 fetches/sec

5.测试总结
使用静态方式和动态方式来加载模块对于php的执行效率并没有非常显著的影响
甚至原先认为在内存占用方面,动态编译由于模块只需要加载一份在真实内存中,内存占用会比较小的假象
在实际测试结果中也没有获得印证
两者的差异几乎可以忽略.而动态加载所获得的机动性和便利性.则大大高于静态编译.
而是否加载了不必要的模块.会略微的影响到内存占用,但是不会影响到其他函数或者模块的执行效率
更不会影响到PHP本身的执行效率
在最后一次测试中.由于phpinfo需要遍历所有的模块并取出对应的参数
所以全部加载的效率远低于只加载必要模块.
如果是服务器需要处理很多外部请求.建议将模块数量最小化.
如果是量并不大到一定程度.全部加载没有太大影响.

阅读内文 Tags: , , ,

使用系统默认路径编译PHP出错解决

10月 27th, 2008 | 3 Comments | Posted in PHP < by Johnny Woo >

原先的文章中
我的PHP编译相关的库
都是指定了prefix编译到特定目录中
而在php中configure中.都是指定路径
类似–with-libxml-dir=/usr/local/webserver/libxml
而在这次我尝试将所有的支持包都安装在默认路径中
在php的编译过程中.出现了问题
./configure之后报错
configure: error: GD build test failed.
而如果without-gd后.编译PHP成功
接着讲gd库作为动态链接库编译,也能够成功
翻阅了网上的资料.基本都没有提到.也有两篇提到的.
都是吧openssl或者mycrypt去掉就好了
最终也没有所以然
最后在这篇文章中
http://bbs.chinaunix.net/viewthread.php?tid=473127
我找到灵感.
文章中提到安装了gd和相应包后
“最后ldconfig刷新一下
ldconfig -v
确认有
libjpeg.so.62 =>; libjpeg.so.62.0.0
libpng.so.3 =>; libpng.so.3.1.2.5
libpng12.so.0 =>; libpng12.so.0.1.2.5
libfreetype.so.6 =>; libfreetype.so.6.3.2″
我突然想到前面编译成功了.但是可能没有ldconfig刷新
立马到机器上刷新
然后ldconfig -v | grep jpeg等等发现果然系统里面没有,而且刷新后还是没有
然后看了下整个输出
系统只包含了一下几个目录,
/usr/local/webserver/bdb/lib:
/lib:
/usr/lib:
第一个是我手动加入了.而默认的就只有/lib和/usr/lib
我记得默认编译都是放入/usr/local/lib的
到目录里一看.果然编译好的lib都在这里.
然后
echo “/usr/local/lib” >> /etc/ld.so.conf
ldconfig
再看输出.已经有了这几个动态库
然后再到php目录里去configure
果然问题解决了.

阅读内文

php-fpm测试

10月 27th, 2008 | 4 Comments | Posted in PHP < by Johnny Woo >

1. 软件版本
Nginx 0.7.17
php 5.2.6
php-fpm 0.5.9
编译参数
./configure –prefix=/usr/local/webserver/php \
–with-config-file-path=/usr/local/webserver/conf \
–enable-fastcgi \
–enable-fpm \
–with-fpm-conf=/usr/local/webserver/conf/php-fpm.conf \
–enable-force-cgi-redirect \
–with-gd \
–with-jpeg-dir \
–with-png-dir \
–enable-gd-native-ttf \
–with-freetype-dir \
–with-mysql=/usr/local/webserver/mysql \
–with-libxml-dir \
–with-mcrypt \
–with-mhash \
–with-curl \
–with-curlwrappers \
–with-zlib-dir \
–with-zlib \
–with-pear \
–with-openssl \
–without-pdo-sqlite \
–without-sqlite \
–disable-debug \
–disable-rpath \
–without-iconv \
–enable-bcmath \
–enable-pcntl \
–enable-mbstring \
–enable-exif \
–enable-zip \
–enable-ftp

3. 补丁安装方法
下载fpm补丁
将fpm加入php
patch -p1 < php-5.2.6-fpm-0.5.9.diff
在./configure后加入–enable-fastcgi –enable-fpm 以启用fpm

4.测试方法
取服务端的一个页面
var_dump($_SERVER);
phpinfo();
?>
另一台服务器发起请求
./http_load -parallel 25 -seconds 10 urls

5.CPU以及内存使用情况
对使用fpm启动的php-cgi以及spawn-fcgi启动的php-cgi进行比对
使用http_load对两者进行访问
然后获取服务器内的内存使用以及响应速度
fpm的使用后CPU下降的比较缓慢.而spawn-cgi的进程cpu下降很快.
很多情况下是使用完后进程CPU便回到0.0

php-fpm
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME
root 27724 0 1.2 103468 3400 ? Ss 02:45 00:00
nobody 27725 0.6 2.1 103988 5672 ? S 02:45 00:00
nobody 27726 0.5 2.1 103988 5672 ? S 02:45 00:00
nobody 27727 0.6 2 103988 5352 ? S 02:45 00:00
nobody 27728 0.7 2 103988 5348 ? S 02:45 00:00
nobody 27729 0.5 2 103988 5348 ? S 02:45 00:00
nobody 27730 0.6 2 103988 5348 ? S 02:45 00:00
nobody 27731 0.5 2 103988 5348 ? S 02:45 00:00
nobody 27732 0.7 2 103988 5344 ? S 02:45 00:00
nobody 27733 0.5 2 103988 5344 ? S 02:45 00:00
nobody 27734 0.2 2 103988 5340 ? S 02:45 00:00
nobody 27735 0.7 2 103988 5348 ? S 02:45 00:00
nobody 27736 0.3 2 103988 5344 ? S 02:45 00:00
nobody 27737 0.7 2 103988 5348 ? S 02:45 00:00
nobody 27738 0.5 2 103988 5348 ? S 02:45 00:00
nobody 27739 0.7 2 103988 5348 ? S 02:45 00:00
nobody 27740 0.8 2 103988 5352 ? S 02:45 00:00
nobody 27741 0.4 2 103988 5348 ? S 02:45 00:00
nobody 27742 0.5 2 103988 5344 ? S 02:45 00:00
nobody 27743 0.6 2 103988 5344 ? S 02:45 00:00
nobody 27744 0.5 2 103988 5348 ? S 02:45 00:00
nobody 27745 0.7 2 103988 5352 ? S 02:45 00:00
nobody 27746 0.4 2 103988 5348 ? S 02:45 00:00
nobody 27747 0.5 2 103988 5344 ? S 02:45 00:00
nobody 27748 0.6 2 103988 5348 ? S 02:45 00:00
nobody 27749 0.7 2 103988 5352 ? S 02:45 00:00

spwan-cgi
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME
www 27760 0 2.4 103452 6320 ? Ss 02:47 00:00
www 27761 0.2 2.1 103976 5548 ? S 02:47 00:00
www 27762 0.2 1.9 103980 5212 ? S 02:47 00:00
www 27763 0.2 1.9 103980 5212 ? S 02:47 00:00
www 27764 0.2 1.9 103980 5212 ? S 02:47 00:00
www 27765 1.4 1.9 103980 5224 ? S 02:47 00:00
www 27766 0.2 1.9 103980 5212 ? S 02:47 00:00
www 27767 0.4 1.9 103980 5220 ? S 02:47 00:00
www 27768 0.5 1.9 103980 5212 ? S 02:47 00:00
www 27769 0.5 1.9 103980 5216 ? S 02:47 00:00
www 27770 2.4 1.9 103980 5236 ? S 02:47 00:01
www 27771 3.1 2 103980 5248 ? S 02:47 00:01
www 27772 2.4 1.9 103980 5236 ? S 02:47 00:01
www 27773 1.3 1.9 103980 5224 ? S 02:47 00:00
www 27774 0.4 1.9 103980 5212 ? S 02:47 00:00
www 27775 0.4 1.9 103980 5212 ? S 02:47 00:00
www 27776 0.3 1.9 103980 5216 ? S 02:47 00:00
www 27777 0.1 1.9 103980 5212 ? S 02:47 00:00
www 27778 0.2 1.9 103980 5212 ? S 02:47 00:00
www 27779 0.2 1.9 103980 5212 ? S 02:47 00:00
www 27780 0.1 1.9 103980 5212 ? S 02:47 00:00
www 27781 0.1 1.9 103980 5212 ? S 02:47 00:00
www 27782 0.1 1.9 103980 5212 ? S 02:47 00:00
www 27783 0 1.9 103980 5212 ? S 02:47 00:00
www 27784 0 1.9 103980 5212 ? S 02:47 00:00
www 27785 0 1.9 103980 5212 ? S 02:47 00:00

6.反应时间
fetches/sec
php-fpm
264.468
269.657
266.5
267.7
267.334
spawn-cgi
246.153
258.742
256.1
256.9
251.6

7.测试结果
php-fpm的使用非常方便,配置都是在php-fpm.ini的文件内
而启动,重启都可以从php/sbin/php-fpm中进行
更方便的是修改php.ini后可以直接使用php-fpm reload进行加载
无需杀掉进程就可以完成php.ini的修改加载
结果显示使用php-fpm可以使php有不小的性能提升
php-fpm控制的进程.cpu回收的速度比较慢.内存分配的很均匀
而spawn-cgi控制的进程CPU下降的很快.而内存分配的比较不均匀.
有很多进程似乎未分配到,而另外一些却占用很高.
可能是由于进程任务分配的不均匀导致的.而这也导致了总体响应速度的下降
而php-fpm合理的分配.导致总体响应的提到以及任务的平均

阅读内文 Tags: , , ,

PHP模块编译无法辨识问题

10月 17th, 2008 | No Comments | Posted in PHP < by Johnny Woo >

1.问题描述
编译PHP模块iconv
cd /root/php-5.2.6/ext/iconv
执行phpize
/root/php/bin/phpize
检查./configure选项
./configure –help
`configure’ configures this package to adapt to many kinds of systems.

Usage: ./configure [OPTION]… [VAR=VALUE]…

To assign environment variables (e.g., CC, CFLAGS…), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
-h, –help display this help and exit
–help=short display options specific to this package
–help=recursive display the short help of all the included packages
-V, –version display version information and exit
-q, –quiet, –silent do not print `checking…’ messages
–cache-file=FILE cache test results in FILE [disabled]
-C, –config-cache alias for `–cache-file=config.cache’
-n, –no-create do not create output files
–srcdir=DIR find the sources in DIR [configure dir or `..']

Installation directories:
–prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local]
–exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]

By default, `make install’ will install all the files in
`/usr/local/bin’, `/usr/local/lib’ etc. You can specify
an installation prefix other than `/usr/local’ using `–prefix’,
for instance `–prefix=$HOME’.

For better control, use the options below.

Fine tuning of the installation directories:
–bindir=DIR user executables [EPREFIX/bin]
–sbindir=DIR system admin executables [EPREFIX/sbin]
–libexecdir=DIR program executables [EPREFIX/libexec]
–datadir=DIR read-only architecture-independent data [PREFIX/share]
–sysconfdir=DIR read-only single-machine data [PREFIX/etc]
–sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
–localstatedir=DIR modifiable single-machine data [PREFIX/var]
–libdir=DIR object code libraries [EPREFIX/lib]
–includedir=DIR C header files [PREFIX/include]
–oldincludedir=DIR C header files for non-gcc [/usr/include]
–infodir=DIR info documentation [PREFIX/info]
–mandir=DIR man documentation [PREFIX/man]

System types:
–build=BUILD configure for building on BUILD [guessed]
–host=HOST cross-compile to build programs to run on HOST [BUILD]
–target=TARGET configure for building compilers for TARGET [HOST]

Optional Features:
–disable-FEATURE do not include FEATURE (same as –enable-FEATURE=no)
–enable-FEATURE[=ARG] include FEATURE [ARG=yes]
–enable-shared=PKGS build shared libraries default=yes
–enable-static=PKGS build static libraries default=yes
–enable-fast-install=PKGS optimize for fast installation default=yes
–disable-libtool-lock avoid locking (might break parallel builds)

Optional Packages:
–with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
–without-PACKAGE do not use PACKAGE (same as –with-PACKAGE=no)
–with-libdir=NAME Look for libraries in …/NAME rather than …/lib
–with-php-config=PATH Path to php-config php-config
–without-iconv=DIR Exclude iconv support
–with-gnu-ld assume the C compiler uses GNU ld default=no
–with-pic try to use only PIC/non-PIC objects default=use both
–with-tags=TAGS include additional configurations automatic

Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L if you have libraries in a
nonstandard directory CPPFLAGS C/C++ preprocessor flags, e.g. -I if you have
headers in a nonstandard directory
CPP C preprocessor
CXXCPP C++ preprocessor

Use these variables to override the choices made by `configure’ or to help
it to find libraries and programs with nonstandard names/locations.
发现并没有–with-iconv或者–enable-iconv选项
那么就是用默认配置
./configure –with-php-config=/root/php/bin/php-config
make && make install
编译出模块后加载到php.ini
然后执行php程序出错
Warning: PHP Startup: Invalid library (maybe not a PHP library) ‘iconv.so’ in Unknown on line 0
报错显示iconv.so不是一个可用的动态链接库
2.解决方法
使用命令检查iconv.so
nm iconv.so | grep get_module
返回确实为空
发现配置参数都是OK的.其他一些选项都是默认的yes
想起来编译PHP如果加上iconv,需要加上–with-iconv
而一般的php模块都会需要加上–enable-模块名的参数
尝试
./configure –with-iconv –with-php-config=/root/php/bin/php-config
make &&make install
编译后再尝试
模块正常加载
看来文档和实际不同
确实真的是很大的问题.要不是php编译里面有这个参数,而我想起来试试看的话
可能一直都无法解决这个问题.至少也是要通过阅读./configure以及make才能知道了.

阅读内文 Tags: , ,

x64系统下PHP 5.2.6静态编译加入GD导致iconv无法使用

10月 15th, 2008 | No Comments | Posted in PHP < by Johnny Woo >

环境如下
CentOS 5.2 x64以及x86
php-5.2.6
gd-2.0.35
freetype-2.3.7
jpegsrc.v6b
libpng-1.2.31
在x64下全部加入编译后

<?php
./
configure --prefix=/root/php --with-config-file-path=/root/php \
--
enable-fastcgi --enable-force-cgi-redirect \
--
with-libxml-dir=/usr/local/webserver/libxml \
--
with-gd=/root/gd \
 --
with-jpeg-dir=/usr/local/webserver/jpeg \
--
with-png-dir=/usr/local/webserver/libpng \
--
enable-gd-native-ttf \
--
with-freetype-dir=/usr/local/webserver/freetype \
--
enable-gd-jis-conv \
--
with-curlwrappers \
--
with-zlib-dir \
--
with-zlib \
--
with-pear \
--
with-openssl \
--
without-pdo-sqlite \
--
without-sqlite \
--
disable-debug \
--
disable-rpath \
--
with-iconv \
--
enable-bcmath \
--
enable-pcntl \
--
enable-mbstring \
--
enable-exif \
--
enable-zip \
--
enable-ftp

发现使用iconv函数
数据输出为空
代码如下

<?php
$str="你好";
print $str;
print "\n";
echo    iconv( "GBK", "UTF-8", $str );
?>

接着我将其他模块去掉.只保留iconv
php执行正常
接着加入了gd库.发现又无法正常输出
将gd库作为模块加入
则iconv能够正常输出
接下来我怀疑是x64特有的内存存取的问题
而这期间,martian也说他的台式机上运行正常,即便加上GD库静态编译也能正常输出iconv
然后我就在台式机上安装干净的虚拟机
从头进行编译
发现x86上使用相同配置方法进行编译的php静态加入gd以及iconv
能够正常的输出iconv
说明确实是在x64位下才会发生的问题
如果是64bit下的linux.使用php加入这两个模块.要记得吧gd作为动态模块加载
才不会导致iconv故障

阅读内文 Tags: , ,

PHP与Perl操作Memcached速度差异比较

9月 26th, 2008 | 4 Comments | Posted in PHP, Perl, memcached < by Johnny Woo >

由于最近在进行memcached方面的工作
在性能测试中
使用了php以及perl对memcached进行操作
结果发现php与perl对memcached操作的性能
差异大约在40~50%之间
以下是测试脚本
所作的操作一样.使用1k的数据重复512000次.
总共插入memcached 500M的数据

php操作脚本

<?php
ini_set("memcache.hash_function","crc32");
$memcache = new Memcache;
$memcache->addServer('localhost', 30001);
$memcache->flush();
for($i=0;$i<512000;$i++){
        
$memcache->set($i,
"共1k的填充数据",0,1000);
}
?>

接着是perl脚本

#!/usr/bin/perl
use Cache::Memcached();
$memcache=new Cache::Memcached{'servers'=>["localhost:30001"]};
$memcache->flush_all();
for($i=0;$i<512000;$i++){
    
$memcache->set($i,
"共1k的填充数据");
}
$memcache->disconnect_all();

从代码行数上来看.两者也几近一致
但是测试结果却是大相径庭
我们在linux下使用time对执行进行计时
3次执行结果如下

[root@lenovo5 ~]# time ./test1k.pl
real    1m2.265s
user    0m36.427s
sys     0m17.114s
[root@lenovo5 ~]# time ./test1k.pl
real    1m2.814s
user    0m36.380s
sys     0m17.463s
[root@lenovo5 ~]# time ./test1k.pl
real    1m13.684s
user    0m44.603s
sys     0m18.366s
[root@lenovo5 ~]# time php ./test1k.php
real    0m38.055s
user    0m11.768s
sys     0m13.891s
[root@lenovo5 ~]# time php ./test1k.php
real    0m38.892s
user    0m12.416s
sys     0m14.044s
[root@lenovo5 ~]# time php ./test1k.php
real    0m38.955s
user    0m12.430s
sys     0m13.088s

差异很明显.perl执行需要1分左右而php只需要40秒不到
就是php的执行比perl的大约快40%
分析之后有几个因素的可能
1.perl的字串处理速度较慢.我们看到perl版本的set中不需要加入长度参数.这样每次插入可能都会需要set函数去判断传入的字串长度.这样可能较慢.但是随后我们发现php的set虽然有长度参数.但是这个参数并非是强制性的.比如我参数写了1000,实际字串有1200.结果将会是插入1200长度的字串,而并没有截断.所以这一点不是非常站得住脚
2.perl的扩展与php扩展实现方式不同.php的memcache客户端是PECL.也就是C扩展,而perl的扩展实现很有可能还是perl.所以会有性能差异.

阅读内文

使用memcached分布式保存PHP session

9月 19th, 2008 | 1 Comment | Posted in PHP, memcached < by Johnny Woo >

安装完memcached之后
参考安装memcached客户端
在php.ini中
将session.save_handler 修改为memcache,并修改save_path指向memcached的地址和端口即可
session.save_handler = memcache
session.save_path = tcp://127.0.0.1:10001

Memcache的PECL这个扩展非常强大
可以支持failover以及分布存储
使用方法很讲但.
只需要在session.save_path的参数列表中
使用逗号分隔各个memcached服务器
则保存的session会经过hash之后保存到各个mc服务器中
而hash的算法.memcache支持两种,crc32以及fnv
memcache.hash_function= {crc32,fnv}
文档中很少有提到fnv算法的,据说其散列要比crc32更好
但是我通过以下小小的程序实验之后,发现仍旧是crc32的散列算法分布的更加平均.

<?php
ini_set("memcache.hash_function","crc32");
$memcache = new Memcache;
$memcache1 = new Memcache;
$memcache2 = new Memcache;
$memcache->addServer('localhost', 11211);
$memcache->addServer('localhost', 11212);
$memcache->flush();
$memcache1->connect('localhost',11211);
$memcache2->connect('localhost',11212);
$fp1 = fopen("mem1.txt","w");
$fp2 = fopen("mem2.txt","w");
for($i=0;$i<1000;$i++){
        
$memcache->set($i,$i,0,1000);
        
fwrite($fp1,$memcache1->get($i)." ");
        
fwrite($fp2,$memcache2->get($i)." ");
}
fclose($fp1);
fclose($fp2);
?>

接着我就session的保存进行了测试
我开了3个memcached进程进行测试

<?php
ini_set("memcache.hash_function","fnv");
ini_set("error_reporting","E_CORE_ERROR");
$memcache1 = new Memcache;
$memcache1->connect('localhost',11211);
$memcache1->flush();
 
$memcache2 = new Memcache;
$memcache2->connect('localhost',11212);
$memcache2->flush();
 
$memcache3 = new Memcache;
$memcache3->connect('localhost',11213);
$memcache3->flush();
$fp1 = fopen("mem1.txt","w");
$fp2 = fopen("mem2.txt","w");
$fp3 = fopen("mem3.txt","w");
for($i=0;$i<1000;$i++){
        
session_start();
        
$ssid=session_id();
        
echo $ssid;
        
session_register("id");
        
$_SESSION["id"]=$ssid;
        
session_write_close();
        
fwrite($fp1,$memcache1->get($ssid)." ");
        
fwrite($fp2,$memcache2->get($ssid)." ");
        
fwrite($fp3,$memcache3->get($ssid)." ");
        
//session_destroy();
}
fclose($fp1);
fclose($fp2);
fclose($fp3);
?>

比较奇怪的是.memcached2一般都会不被选中
而1,3的内容是一致的.可能是为了failover
而当我把1,3关闭一台后.2中将会出现内容,说明memcached2是正常工作的
而不论我的散列算法使用crc32还是fnv
这种现象都存在
最后我发现.这个测试程序存在问题
因为在session_write_close之后.整个程序的session都是唯一的了.
也就是虽然循环了这么多次.里面包含了session_destroy调用.但是返回的session id都是同样的
这就导致了两个文件中的内容一致而另一个文件中没有内容
基于此点
我只能分次调用脚本,脚本修改如下

<?php
ini_set("memcache.hash_strategy","consistent");
ini_set("memcache.hash_function","crc32");
ini_set("error_reporting","E_CORE_ERROR");
ini_set("memcache.allow_failover","0");
$memcache1 = new Memcache;
$memcache1->connect('localhost',10001);
$memcache1->flush();
 
$memcache2 = new Memcache;
$memcache2->connect('localhost',10002);
$memcache2->flush();
 
$memcache3 = new Memcache;
$memcache3->connect('localhost',10003);
$memcache3->flush();
$fp1 = fopen("mem1.txt","a+");
$fp2 = fopen("mem2.txt","a+");
$fp3 = fopen("mem3.txt","a+");
    
session_start();
    
$ssid=session_id();
    
echo $ssid."\n";
    
session_register("id");
    
$_SESSION["id"]=$ssid;
    
//session_destroy();
    
session_write_close();
    
fwrite($fp1,$memcache1->get($ssid)." ");
    
fwrite($fp2,$memcache2->get($ssid)." ");
    
fwrite($fp3,$memcache3->get($ssid)." ");
    
session_destroy();
fclose($fp1);
fclose($fp2);
fclose($fp3);
?>

然后再shell中重复运行多次.返回的ID不同了
再打开mem*.txt文件查看
发现3个文件中,每个session会保存在其中两个文件.然后分布不同
这证明了使用memcache来保存session.一个是做到了failover.第二会按照session id来做hash分布保存

阅读内文 Tags: , , ,

PHP 编程 多语言本地化支持

9月 18th, 2008 | 1 Comment | Posted in PHP < by Martian Guo >

一直认为要让PHP程序支持多语言就是模板+各种语言配置文件
简单的语言配置像这样

$conf['title']='xxx管理系统';
$conf['system']='系统系统';
$conf['user']='用户系统';

利用数组或者是定义常量的方法来管理这些条目,然后通过模板来读取这个数组做一下简单替换
最近发现php 其实是支持I18N 的,需要的模块是gettext
具体实现:

<?php
// I18N 程序范例开始
$package="hello"; // 定义要用的mo文件名称
$locale="zh_CN"; // 指定要用的语系,如:en_US、zh_CN、zh_TW
 
putenv('LANG=$locale');
setlocale(LC_ALL, $locale);
 
bindtextdomain($package, './locale');
textdomain($package);
 
// The .mo file searched is:
// ./locale/zh_CN/LC_MESSAGES/hello.mo
 
echo gettext("Hello World!");
?>;

创建PO文档
xgettext -d [您定义的PACKAGE名称] [程序文件名]

xgettext -d hello hello.php

hello.po 内容如下

# SOME DESCRIPTIVE TITLE.
# Copyright © YEAR Free Software Foundation, Inc.
# FIRST AUTHOR &lt;<a href="mailto:EMAIL@ADDRESS">EMAIL@ADDRESS</a>&gt;, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2003-04-21 22:31+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME &lt;<a href="mailto:EMAIL@ADDRESS%3E\n">EMAIL@ADDRESS&gt;\n</a>"
"Language-Team: LANGUAGE &lt;<a href="mailto:LL@li.org%3E\n">LL@li.org&gt;\n</a>"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
 
#: hello.php:14
msgid "Hello World!"
msgstr "世界,您好!"    // 这段就是添加翻译的内容

创建mo文件

msgfmt -o hello.mo hello.po

将 hello.mo 文件拷贝到相关语系的目录下就可以了,这里是拷贝到

locale/zh_CN/LC_MESSAGES/

补充:
echo gettext(”Hello World!”); 这种写法可以用 echo _(’Hello World!’) 来代替 (可以少打几个字)。 _() 是 gettext 函数的别名。

php 相关gettext 函数介绍

http://cn.php.net/manual/en/book.gettext.php

bind_textdomain_codeset     --  Specify the character encoding in which the
messages from the DOMAIN message catalog will be returned

bindtextdomain                     -- Sets the path for a domain
dcgettext                                -- Overrides the domain for a single lookup
dcngettext                              -- Plural version of dcgettext
dgettext                                  -- Override the current domain
dngettext                                -- Plural version of dgettext
gettext                                    -- Lookup a message in the current domain
ngettext                                 -- Plural version of gettext
textdomain                            -- Sets the default domain

建议使用utf8格式保存po文件

"Content-Type: text/plain; charset=CHARSET\n"

修改成

"Content-Type: text/plain; charset=UTF-8\n"

使用以下命令转换文件编码

iconv -f iso8859-1 -t utf-8 -o hello.po >tmp.po

还要注意需要在php程序中再加入

bind_textdomain_codeset(PACKAGE,'UTF-8');

翻译po文件可以使用一些图形化工具
KBabel http://kbabel.kde.org/
gtranslator http://www.gtranslator.org

其他内容:

什么是 I18N 和 L10N ?
I18N 是 internationalization 的缩写形式,意即在 i 和 n 之间有 18 个字母,本意是指软件的“国际化”;与之类似,L10N 是 localization 的缩写形式,意即在 l 和 n 之间有 10 个字母,本意是指软件的“本地化”。

I18N 和 L10N 从何而来?它们有何区别?
按照软件开发的惯例,最初的软件只有英文版本,根据需要,作者再把软件界面和文档翻译成不同国家、地区的语言版本。但是由于实现翻译的途径、翻译的工作效率、翻译的可重用性等因素各不相同,使翻译工作面临很大困境,也阻碍了软件的推广和应用。为了方便地将软件翻译成不同语言的版本,就需要一套翻译规范和通用工具,这就导致了“国际化”机制的出现。仅仅翻译是不够的,同一种语言在不同国家、地区可能存在多个支系,它们在表达习惯、语法结构甚至文字种类和编码上都有不同,方言更是千奇百怪,通用的翻译其质量肯定是不高的。涉及到计算机领域,还存在操作习惯上的差别,而且对某种语言提供完美的输入、显示、打印、保存、传输并非一件轻而易举的事,这就导致了“本地化”机制的出现。简而言之,“国际化”是“本地化”的一部分,主要是指国际化的实现机制和翻译工作, “本地化”包含“国际化”,是对“国际化”的补充和完善,它还包括为实现对某种特定语言良好的支持而进行的有针对性的翻译调整以及对软件进行的打补丁工作。

I18N 和 L10N 的国际组织是什么?
I18N 和 L10N 的国际组织是 Openi18n 组织,其前身是 li18nux 组织。它原来是制定 GNU/Linux 自由操作系统上软件全球化标准的国际计划,后来扩充到 GNU/Linux 之外所有开放源代码的技术领域,因而更名为 Open Internationalization Initiative,由非营利组织 Free Standards Group 赞助,并为世界各大厂商所支持,对于 GNU/Linux 系统上的多国语言文字处理技术和环境有决定性的影响。各个开源软件开发组织通常都有负责“国际化”和“本地化”工作的分支机构。

I18N 主要使用什么工具工作?
I18N 主要使用 gettext 软件包使软件实现国际化支持。事实上它是一整套 I18N 解决方案。
  Gettext 用于系统的国际化(I18N)和本地化(L10N), 可以在编译程序的时候使用本国语言支持(Native Language Support(NLS)),其可以使程序的输出使用用户设置的语言而不是英文.跟其他程序语言一样,在 PHP 也可以利用 gettext 套件写作 i18n 程序,实现 NLS(Native Language Support) 国际化支持,具体请参考官方文档http://www.gnu.org/software/gettext/manual/gettext.html。

  实现流程:程序设计者在程序码中写入所要显示的信息,在运行程序时并不会直接显示程序设计师所写的信息,而会先去找一个所设置语系的信息档。如果未找到,才会去显示程式码中的信息。

什么是 PO 和 MO 文件?它们有何区别?
PO 是 Portable Object (可移植对象)的缩写形式;MO 是 Machine Object (机器对象) 的缩写形式。PO 文件是面向翻译人员的、提取于源代码的一种资源文件。当软件升级的时候,通过使用 gettext 软件包处理 PO 文件,可以在一定程度上使翻译成果得以继承,减轻翻译人员的负担。MO 文件是面向计算机的、由 PO 文件通过 gettext 软件包编译而成的二进制文件。程序通过读取 MO 文件使自身的界面转换成用户使用的语言。

阅读内文

PHP在64位系统下编译出错

9月 5th, 2008 | 3 Comments | Posted in PHP < by Johnny Woo >

make后报错
/usr/lib/libltdl.so: could not read symbols: File in wrong format
发现其调用32位lib
如果我们直接将调用的文件
ln -s /usr/lib64/libltdl.so.3.1.4 /usr/lib/libltdl.so
PHP可以正常编译
但是为了防止可能出现的问题
我们不使用这种方法
查看configure参数后我发现可以有参数直接指定lib目录
使用–with-libdir=/usr/lib64
加入configure后重新make通过

有个老外也遇见同样问题
http://forums.gentoo.org/viewtopic-p-3926345.html?sid=0c03688539961177d24652f60075387e

阅读内文 Tags: , ,

OP Cache大比拼: APC vs eAccelerator vs xcache, eAccelerator胜出

8月 25th, 2008 | 5 Comments | Posted in PHP < by Johnny Woo >

APC 3.0.19 (Alternative PHP Cache)
配置

extension=apc.so
apc.enabled=1
apc.shm_segments=1
apc.shm_size=128
apc.ttl=7200
apc.user_ttl=7200
apc.num_files_hint=1024
apc.mmap_file_mask=/tmp/apc.XXXXXX
apc.enable_cli=1

结果

7303 fetches, 50 max parallel, 1.67458e+07 bytes, in 300 seconds
2293 mean bytes/connection
24.3433 fetches/sec, 55819.3 bytes/sec
msecs/connect: 3.27583 mean, 2999.74 max, 0.184 min
msecs/first-response: 2043.52 mean, 7853.21 max, 325.513 min
HTTP response codes:
  code 200 -- 7303

eAccelerator 0.9.5.3
配置

[eaccelerator]
extension=eaccelerator.so
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.log_file = "/var/log/httpd/eaccelerator_log"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

结果

7568 fetches, 50 max parallel, 1.73534e+07 bytes, in 300.001 seconds
2293 mean bytes/connection
25.2266 fetches/sec, 57844.6 bytes/sec
msecs/connect: 0.39873 mean, 1.01 max, 0.173 min
msecs/first-response: 1972.44 mean, 5520.1 max, 635.565 min
HTTP response codes:
  code 200 -- 7568

XCache v1.2.2
配置

extension="xcache.so"
[xcache.admin]
; Change xcache.admin.user to your preferred login name
xcache.admin.user = "admin"
; Change xcache.admin.pass to the MD5 fingerprint of your password
; Use md5 -s "your_secret_password" to find the fingerprint
xcache.admin.pass = "e10adc3949ba59abbe56e057f20f883e"
[xcache]
; Change xcache.size to tune the size of the opcode cache
xcache.size = 24M
xcache.shm_scheme = "mmap"
xcache.count = 2
xcache.slots = 8K
xcache.ttl = 0
xcache.gc_interval = 0
; Change xcache.var_size to adjust the size of variable cache
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 = On
[xcache.coverager]
xcache.coverager = Off
xcache.coveragedump_directory = ""

结果

4539 fetches, 50 max parallel, 1.04079e+07 bytes, in 300 seconds
2293 mean bytes/connection
15.13 fetches/sec, 34693.1 bytes/sec
msecs/connect: 0.405883 mean, 0.999 max, 0.182 min
msecs/first-response: 3214.64 mean, 18691.3 max, 772.952 min
HTTP response codes:
  code 200 -- 4539

No OP-Cache
结果

1798 fetches, 50 max parallel, 3.9867e+06 bytes, in 300 seconds
2217.3 mean bytes/connection
5.99332 fetches/sec, 13289 bytes/sec
msecs/connect: 12.0802 mean, 2999.48 max, 0.203 min
msecs/first-response: 6966.64 mean, 59754 max, 381.002 min
41 timeouts
61 bad byte counts
HTTP response codes:
  code 200 -- 1757

结论:
eAccelerator 0.9.5.3
25.2266 fetches/sec

APC 3.0.19
24.3433 fetches/sec

XCache v1.2.2
15.13 fetches/sec

No OP-Cache
5.99332 fetches/sec

eA的效果最好.APC紧随其后.两者的性能表现基本相同.xcache最差.

阅读内文 Tags: , , , , ,

IT流言终结者3:eaccelerator与xcache性能测试对比

8月 22nd, 2008 | 6 Comments | Posted in PHP < by Johnny Woo >

网上有一篇比较eAccelerator与xcache的性能的文章
php缓冲器:eaccelerator与xcache性能测试对比
里面最终的结果是Xcache胜出
而这次由于生产环境调优的关系
我们同样适用Xcache与EA进行对比
选出能够提高生产环境效率的PHP OPCODE缓冲器
这次我们直接使用的是网站程序中的登录模块
整个网站基于SEAGULL 0.61框架.
前端是
APACHE 2.2.4
PHP 5.2.4
Xcache 1.1.2
eAccelerator 0.9.5.3
Zend Engine v2.2.0
测试工具http_load
参数

./http_load -p 50 -f 500 -s 300 phps

eAccelerator配置

extension="eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.log_file = "/var/log/httpd/eaccelerator_log"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

xcache配置

extension="xcache.so"
[xcache.admin]
; Change xcache.admin.user to your preferred login name
xcache.admin.user = "admin"
; Change xcache.admin.pass to the MD5 fingerprint of your password
; Use md5 -s "your_secret_password" to find the fingerprint
xcache.admin.pass = "e10adc3949ba59abbe56e057f20f883e"
[xcache]
; Change xcache.size to tune the size of the opcode cache
xcache.size = 24M
xcache.shm_scheme = "mmap"
xcache.count = 2
xcache.slots = 8K
xcache.ttl = 0
xcache.gc_interval = 0
; Change xcache.var_size to adjust the size of variable cache
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]
xcache.coverager = On
xcache.coveragedump_directory = ""

Zend配置

[Zend]
zend_extension_manager.optimizer=/usr/local/Zend/lib/Optimizer-3.3.0
zend_extension_manager.optimizer_ts=/usr/local/Zend/lib/Optimizer_TS-3.3.0
zend_optimizer.version=3.3.0a
zend_extension=/usr/local/Zend/lib/ZendExtensionManager.so
zend_extension_ts=/usr/local/Zend/lib/ZendExtensionManager_TS.so

测试结果(几次测试中取样代表性数据)

with nothing
1798 fetches, 50 max parallel, 3.9867e+06 bytes, in 300 seconds
2217.3 mean bytes/connection
5.99332 fetches/sec, 13289 bytes/sec
msecs/connect: 12.0802 mean, 2999.48 max, 0.203 min
msecs/first-response: 6966.64 mean, 59754 max, 381.002 min
41 timeouts
61 bad byte counts
HTTP response codes:
  code 200 -- 1757
with eAccelerator v0.9.5.3
作为php扩展模块
7578 fetches, 50 max parallel, 1.73764e+07 bytes, in 300 seconds
2293 mean bytes/connection
25.26 fetches/sec, 57921.2 bytes/sec
msecs/connect: 3.16951 mean, 3000.16 max, 0.141 min
msecs/first-response: 1970.65 mean, 8268.16 max, 197.622 min
HTTP response codes:
  code 200 -- 7578
with Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies
with eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by eAccelerator
作为zend扩展模块
7640 fetches, 50 max parallel, 1.75185e+07 bytes, in 300 seconds
2293 mean bytes/connection
25.4667 fetches/sec, 58395.1 bytes/sec
msecs/connect: 3.14855 mean, 2999.92 max, 0.165 min
msecs/first-response: 1954.57 mean, 8446.03 max, 267.841 min
HTTP response codes:
  code 200 -- 7640
with eAccelerator v0.9.5.3
with Zend Extension Manager v1.2.2
with Zend Optimizer v3.3.0
作为php扩展模块
6732 fetches, 50 max parallel, 1.54365e+07 bytes, in 300 seconds
2293 mean bytes/connection
22.44 fetches/sec, 51454.9 bytes/sec
msecs/connect: 0.40062 mean, 0.761 max, 0.177 min
msecs/first-response: 2218.16 mean, 7707.3 max, 632.3 min
HTTP response codes:
  code 200 -- 6732
with XCache v1.2.2
作为php扩展模块
4371 fetches, 50 max parallel, 9.96732e+06 bytes, in 300.001 seconds
2280.33 mean bytes/connection
14.57 fetches/sec, 33224.4 bytes/sec
msecs/connect: 0.402745 mean, 0.763 max, 0.196 min
msecs/first-response: 3355.27 mean, 54504.3 max, 576.103 min
2 timeouts
25 bad byte counts
HTTP response codes:
  code 200 -- 4369
with XCache v1.2.2
作为php扩展模块
打开xcache.optimizer = On
4871 fetches, 50 max parallel, 1.11603e+07 bytes, in 300.001 seconds
2291.17 mean bytes/connection
16.2366 fetches/sec, 37200.9 bytes/sec
msecs/connect: 4.71709 mean, 3000.64 max, 0.152 min
msecs/first-response: 3047.7 mean, 27066.9 max, 557.86 min
4 bad byte counts
HTTP response codes:
  code 200 -- 4871
with Zend Extension Manager v1.2.2
with XCache v1.2.2
作为zend扩展模块
1583 fetches, 50 max parallel, 3.5877e+06 bytes, in 300 seconds
2266.39 mean bytes/connection
5.27667 fetches/sec, 11959 bytes/sec
msecs/connect: 0.39951 mean, 0.756 max, 0.163 min
msecs/first-response: 9297.83 mean, 59294.4 max, 502.852 min
19 bad byte counts
HTTP response codes:
  code 200 -- 1583

结果显示eAccelerator无论在速度还是稳定性上都大大超过xcache
而且在稳定性上大大提高.使用eA基本上没有出现过bad byte counts
而令人奇怪的就是Zend Optimizer加上eA后反而性能下降
xcache使用zend扩展模式
基本等于没有发挥任何作用.
此次测试没有Optimizer与Xcache的组合
是由于两者相互冲突.一旦加上Optimizer
不论是将xcache作为zend扩展还是php扩展
都会产生问题导致PHP无法执行.
所以最优的环境是只安装eA,如果你的PHP代码是经过加密的
很可惜,可能没有只使用EA性能这么好,不过下降的也不多.
但是比加了Optimizer就无法加载的XCACHE要好

国外有人也测试了一下eAccelerator和APC
结果EA的内存占用以及加速效果都好过APC
Benchmarking APC vs. eAccelerator using Drupal
另外一篇讲述OP-CACHE的文章
PHP op-code caches / accelerators: Drupal large site case study

我们的wordpress博客

with XCache v1.2.2
作为zend模块加载
329 fetches, 50 max parallel, 5.72335e+07 bytes, in 100 seconds
173962 mean bytes/connection
3.29 fetches/sec, 572334 bytes/sec
msecs/connect: 1.09919 mean, 20.231 max, 0.184 min
msecs/first-response: 13970.3 mean, 23204.4 max, 2489.5 min
HTTP response codes:
  code 200 -- 329
with eAccelerator v0.9.5.3
作为php扩展模块
366 fetches, 50 max parallel, 6.36701e+07 bytes, in 100.001 seconds
173962 mean bytes/connection
3.65997 fetches/sec, 636696 bytes/sec
msecs/connect: 0.47335 mean, 4.758 max, 0.21 min
msecs/first-response: 12670.6 mean, 23359.5 max, 1469.66 min
HTTP response codes

PS:
所有的测试都会和参数调优有一定关系.
不是所有的测试都是准确的
测试始终会有局限性.
本例也不例外

阅读内文 Tags: , , ,

PHP 正则表达式 思维导图

7月 25th, 2008 | 3 Comments | Posted in PHP, 思维导图 < by Martian Guo >

源文件下载

阅读内文 Tags: , ,

PHP5 OOP 学习 思维导图

7月 20th, 2008 | 3 Comments | Posted in PHP, 思维导图 < by Martian Guo >

学习PHP5 面向对象程序设计中的一些内容总结。
源文件下载:
php5_oop.mm

阅读内文 Tags: ,

PHP静态编译安装

6月 19th, 2008 | No Comments | Posted in PHP < by Johnny Woo >
groupadd mysql 
useradd mysql -g mysql
cd /root
tar zxvf mysql-5.0.51a.tar.gz
cd mysql-5.0.51a
./
configure --prefix=/usr/local/mysql
make && make install
./
scripts/mysql_install_db --user=mysql
cd /usr/local/mysql
chown -R root /usr/local/mysql
chgrp -R mysql /usr/local/mysql
chown -R root /usr/local/mysql/bin
chgrp -R mysql /usr/local/mysql/bin
chown -R root /usr/local/mysql/var
chgrp -R mysql /usr/local/mysql/var
chmod 777 /usr/local/mysql/var
chown -R root /usr/local/mysql/var/mysql
chgrp -R mysql /usr/local/mysql/var/mysql
chmod 777 /usr/local/mysql/var/mysql
chown -R root /usr/local/mysql/var/mysql/*
chgrp -R mysql /usr/local/mysql/var/mysql/*
chmod 777 /usr/local/mysql/var/mysql/*
chmod 777 /usr/local/mysql/lib/mysql/libmysqlclient.a
 
cd /root
tar zxvf httpd-2.2.4.tar.gz
cd httpd-2.2.4
./configure --prefix=/usr/local/apache2 --enable-deflate --enable-headers --enable-shared=max --enable-module=rewrite --enable-module=so
make && make install
 
cd /root
tar zxvf libevent-1.3e.tar.gz
cd libevent-1.3e
./configure --prefix=/usr/local/libevent
make && make install
 
cd /root
tar zxvf memcached-1.2.2.tar.gz
cd memcached-1.2.2
./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
make && make install
cp /usr/local/libevent/lib/libevent-1.3e.so.1 /usr/lib
/usr/local/memcached/bin/memcached -d -m 50 -p 11211 -u root
 
cd /root
tar zxvf libxml2-2.6.30.tar.gz
cd libxml2-2.6.30
./configure --prefix=/usr/local/libxml
make && make install
 
cd /root
tar zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure --prefix=/usr/local/zlib
make && make install
 
cd /root
tar zxvf libpng-1.2.19.tar.gz
cd libpng-1.2.19
./configure --prefix=/usr/local/libpng
make && make install
 
cd /root
tar zxvf freetype-2.3.5.tar.gz
cd freetype-2.3.5
./configure --prefix=/usr/local/freetype
make && make install
 
cd /usr/local
mkdir jpeg
cd jpeg
mkdir include lib man bin
mkdir man/man1
cd /root
tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
./configure --prefix=/usr/local/jpeg --enable-shared --enable-static
make && make install
 
cp -Rf /usr/local/libpng/include/* /usr/include/
cd /root
tar zxvf gd-2.0.35.tar.gz
cd gd-2.0.35
./configure --prefix=/usr/local/gd --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-jpeg=/usr/local/jpeg
make && make install
 
cd /root
rpm -ivh jdk-1_5_0_15-linux-i586.rpm
rpm -ivh jre-6u5-linux-i586.rpm
rpm -ivh oracle-instantclient-basic-10.2.0.3-1.i386.rpm
rpm -ivh oracle-instantclient-devel-10.2.0.3-1.i386.rpm
 
cd /root
tar -zvxf php-5.2.4.tar.gz
cd /root/php-5.2.4
./configure --prefix=/usr/local/php5 --with-zlib-dir=/usr/local/zlib/ --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php5 --with-openssl --enable-gd-native-ttf --with-jpeg-dir=/usr/local/jpeg/ --with-png-dir=/usr/local/libpng/ --with-freetype-dir=/usr/local/freetype