php 编译(针对Apache)

PHP需要MySQL客户端模块支持,需要下载MySQL软件。
# cd /usr/local/src
# tar zvxf mysql-5.0.67-linux-i686-icc-glibc23.tar.gz
# mv mysql-5.0.67-linux-i686-icc-glibc23 /usr/local/mysql
# tar zvxf php-5.2.8.tar.gz
# cd php-5.2.8
# ./configure --prefix=/usr/local/php \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mysql \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir  \
--with-bz2 \
--with-openssl \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-ftp \
--enable-mbstring \
--enable-sockets \
--enable-exif \
--disable-ipv6 \
--disable-cgi \
--disable-cli
# make
# make install
# mkdir /usr/local/php/etc
# cp php.ini-dist /usr/local/php/etc/php.ini

php 5.2.11 with php-5.2.11-fpm编译安装

安装libevent(版本不低于libevent-1.4.12)
wget http://syslab.comsenz.com/downlo ... .4.12-stable.tar.gz
tar zxvf libevent-1.4.12-stable.tar.gz
cd libevent-1.4.12-stable
./configure --prefix=/usr/local/libevent
make && make install


安装php-fpm 0.6
wget http://syslab.comsenz.com/downlo ... m-0.6-5.2.11.tar.gz
tar -zxvf php-fpm-0.6-5.2.11.tar.gz
./php-fpm-0.6-5.2.11/generate-fpm-patch     //生成fpm补丁在/usr/local/src下


下载php-5.2.11.tar.gz
wget http://syslab.comsenz.com/downloads/linux/php-5.2.11.tar.gz
tar xvfz php-5.2.11.tar.gz
cd php-5.2.11
patch -p1 < ../fpm.patch
./buildconf --force
mkdir fpm-build && cd fpm-build
../configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-fpm  --with-fpm-bin=/usr/local/php/bin/php-fpm --with-fpm-conf=/usr/local/php/etc/php-fpm.conf --with-fpm-log=/usr/local/php/var/php-fpm.log --with-fpm-pid=/usr/local/php/var/php-fpm.pid  --with-fpm-user=www --with-fpm-group=www --with-libevent=/usr/local/libevent/ --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp --with-libxml-dir --with-mcrypt --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --enable-zend-multibyte --disable-ipv6 --enable-fastcgi  
make && make install

启动php-fpm
/etc/init.d/php-fpm start

默认端口9000启动,需要套接字启动,需要修改/usr/local/php/etc/php-fpm.conf

Eaccelerator 安装及配置

# cd /usr/local/src
# tar jxvf eaccelerator-0.9.5.2.tar.bz2
# cd eaccelerator-0.9.5.2
# /usr/local/php/bin/phpize
# ./configure \
    --enable-eaccelerator=shared \
    --with-php-config=/usr/local/php/bin/php-config \
    --with-eaccelerator-shared-memory \
    --with-eaccelerator-sessions \
    --with-eaccelerator-content-caching
# make
# make install
# mkdir /usr/local/php/ext
# ln -s /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so  /usr/local/php/ext/eaccelerator.so

tidy 安装 php扩展模块

来源: http://hi.baidu.com/leechl

首先要安装libtidy, 否则安装过程会报"configure: error: Cannot find libtidy"的错误.
libtidy的项目地址是:http://tidy.sourceforge.net/ , 我是在这里下载的http://anduin.linuxfromscratch.org/files/BLFS/sources/tidy-cvs_20070326.tar.bz2 或者  mylinux.5d6d.com/userdirs/c/f/mylinux/attachments/month_1102/tidy-cvs_20070326.tar.bz2

安装libtity

#tar jxf tidy-cvs_20070326.tar.bz2
#cd tidy-cvs_20070326
#./configure --prefix=/usr && make && make install

安装tidy的php扩展

#cd /home/php-5.2.8
#./configure --with-php-config=/home/php/bin/php-config && make && make install
#strip /home/php/lib/php/extensions/no-debug-non-zts-20060613/tidy.so
#vi /home/php/lib/php.ini
加入extension=tidy.so
#/home/php/sbin/php-fpm reload

安装好之后发现tidy.so没有load进去, 查了老半天看php_error.log, 发现有下面一行

PHP Startup: Unable to load dynamic library '/home/php/lib/php/extensions/no-debug-non-zts-20060613/tidy.so' - libtidy-0.99.so.0: cannot open shared object file: No such file or directory in Unknown on line 0

原来是找不到库文件, 虽然安装了库文件, 但是要用 /sbin/ldconfig 命令来重新加载. 于是执行如下命令.

# /sbin/ldconfig -f /etc/ld.so.conf
#/home/php/sbin/php-fpm restart

php-fpm.conf参数说明

emergency_restart_threshold 默认值 10

emergency_restart_interval  默认值 1m = 60s
表示在emergency_restart_interval(60)秒内出现SIGSEGV或者SIGBUS错误的php-cgi进程数如果超过emergency_restart_threshold个,php-fpm就会优雅重启。

request_terminate_timeout
请求处理超时时间,类似PHP中的max_execution_time

request_slowlog_timeout
超过这个时间的定义为slow请求。这些请求会进入slowlog日志

rlimit_files
文件句柄的最大限制

max_requests
在重启之前每个进程最多处理多少个请求。

libxlst 下载

简单介绍libxslt
libxslt 包括 libxslt 库文件. 它扩展了libxml2库,以支持 XSLT 文件.

软件包信息

下载地址 http://ftp.acc.umu.se/pub/GNOME/sources/libxslt/1.1/

php.ini 中开启短标签

控制参数: short_open_tag = On
如果设置为Off,则不能正常解析类似于这样形式的php文件:
<?
phpinfo()
?>

而只能解析
<?php
phpinfo()
?>
这样形式的php文件
所以要想php支持短标签,需要我们把short_open_tag  设置为On.

PHP 5.3新版特性浅析

注:本文转自51cto.com

从php4到php5,从个人框架到开源框架的发展,见证着php从山寨走上正规大军的发展。php6还在酝酿中,相信php5会作为php6小试牛刀的场地。php5.3是php5的一个里程碑,加入了大量新特性。

我个人总感觉php功能是越来越多了,但是php的语法却越来越丑陋了,有时加入了新功能,而新功能带来了问题,为了修复问题,又要加入新的语法来修复,郁闷。估计php用语法修复问题是为了更好的解析。

一、mysql驱动mysqlnd

一直以来,php都是通过mysql客户端连接mysql,而现在mysql官方已经推出php版的mysql客户端,而这个mysqlnd有效降低内存的使用以及提高性能。具体可以看:

http://dev.mysql.com/downloads/connector/php-mysqlnd/

http://forge.mysql.com/wiki/PHP_MYSQLND



从图中可以看出,使用mysqlnd少了从mysql驱动中复制数据到php扩展这一步。mysqlnd使用copy-on-write,也就是写时复制,读引用。

mysqlnd已经内置在php5.3的源码中,编译的时候使用--with-mysql=mysqlnd、--with-mysqli=mysqlnd 和 --with-pdo-mysql=mysqlnd 安装mysqlnd驱动。

mysqlnd的优点

编译php更方便了,不需要libmysql,已经内置在源码中

编译php更方便了,不需要libmysql,已经内置在源码中
使用php许可,避免版权问题
使用php的内存管理,支持php内存限制(memory_limit)
所有数据在内存只有一份,之前的libmysql有两份,参考上图
提供性能统计功能,帮助分析瓶颈
mysqli支持长连接(persistent connections)
性能绝对比libmysql要快
在驱动层增加缓存机制
看了这么多特点,有点矛盾,作为数据库抽象层的PDO能把不同后端的特点发挥出来吗?如果使用mysql作为数据库的话mysqli是不是更好的选择?我总觉得mysqli只是个过度产品,PDO才是未来的。

二、性能提高

md5()大概提高了10%-15%的性能
Better stack implementation in the engine,没明白
常量保存在ROM里(Constants moved to read-only memory),这里没明白意思
改进异常处理,操作码(opcode)更简洁
解决了include(require)_once重复打开的问题,之前once我都是用静态变量实现的,终于解决这个问题了
用gcc4编译的二进制文件将更小
整体性能提高了5%-15%
很多人觉得web的瓶颈在db,所以app应用的性能毫不在乎,我认为主要是因为app扩展比db扩展要容易得多,所以才会产生db瓶颈,但这并不意味着可以不顾虑app的性能,毕竟最终还是要在app里解决各种问题的,作为一名程序员编写高质量的代码是最基本的要求。程序的内存使用量少点和执行速度快点,在高并发下是有很效果的,有些时候你改动下实现方法,能提高几十倍也很正常,当然如果付出要很多收获很少的时候就不要太执着了,我觉得一定要有编写高质量代码的意识。

三、?:操作符

其实就是js里的||,返回的结果不是逻辑类型,而是返回本来变量的值,例如 false ?: 123返回123,而不是true。语法就是有点怪怪!

libpng 下载

http://downloads.sourceforge.net/libpng/libpng-1.2.29.tar.bz2

php-fpm.log 日志中的错误(摘自互联网)

几台使用了 nginx+php-fpm 的机器上,偶尔能看到php-fpm.log中有这样的内容


引用
Oct 28 23:13:53.849419 [NOTICE] fpm_got_signal(), line 73: received SIGCHLD
Oct 28 23:13:53.849490 [WARNING] fpm_children_bury(), line 229: child 15044 (pool default) exited on signal 11 SIGSEGV after 1.332818 seconds
Oct 28 23:13:53.850341 [NOTICE] fpm_children_make(), line 305: child 15122 (pool default) started

如果得到SIGSEGV信号的进程比较多的话,还能看到如下的日志


引用
Oct 28 09:03:15.812009 [WARNING] fpm_children_bury(), line 256: failed processes threshold (10 in 60 sec) is reached, initiating reload
Oct 28 09:03:15.812030 [NOTICE] fpm_pctl(), line 208: switching to 'reloading' state

然后php-fpm就会重启。其中的
failed processes threshold (10 in 60 sec) is reached
是在php-fpm.conf中设置的,表示在60秒内出现SIGSEGV或者SIGBUS错误的php-cgi进程数如果超过10个,php-fpm就会重启。可以通过把php-fpm.conf中的 emergency_restart_threshold的值设置的大一些来增加这个重启的阀值,比如增加到60个,在有些时候,这能够避免php-fpm重启,但这并不是解决问题的根本办法

SIGSEGV信号一般表示


引用
SIGSEGV --- Segment Fault. The possible cases of your encountering this error are:
1.buffer overflow --- usually caused by a pointer reference out of range.
2.stack overflow --- please keep in mind that the default stack size is 8192K.
3.illegal file access --- file operations are forbidden on our judge system

其中的第三条,跟本问题的关系比较大。也就是php-cgi访问了一个不存在的或者没有权限访问的文件
我用的php-fpm补丁是0.5.8版的,按照一些说法,只要设置了


引用
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;

之后,php-cgi如果找不到文件或者没有权限访问的话 会提示No input file specified. 或者Access denied.
问题到这里似乎又陷入了僵局
后来又在php.ini中找到了php-cgi的一个参数 cgi.fix_pathinfo


引用
cgi.fix_pathinfo  boolean
对 CGI 提供了真正的 PATH_INFO/PATH_TRANSLATED 支持。以前 PHP 的行为是将 PATH_TRANSLATED 设为 SCRIPT_FILENAME,而不管 PATH_INFO 是什么。有关 PATH_INFO 的更多信息见 cgi 规格。将此值设为 1 将使 PHP CGI 修正其路径以遵守规格。设为 0 将使 PHP 的行为和从前一样。默认为零。用户应该修正其脚本使用 SCRIPT_FILENAME 而不是 PATH_TRANSLATED。

把这个参数的值设置为1 ,cgi会多做一些检查,来判断请求的路径中,那部分是文件名,哪部分是路径名
下面是google groups上的一段话


引用
when cgi.fix_pathinfo was set to "1" it caused a lot of checks in order to find which part of SCRIPT_FILENAME is a file name and which is PATH_INFO. In case of missing file it caused NULL
in path_translated, which caused the crash.


资料引用:http://www.knowsky.com/536760.html

php-5.3.3 with php-fpm的编译安装

在php-fpm.org 网站上已经说明了。
PHP 5.3.3 is released and now bundles PHP-FPM。
告诉我们,在php-5.3.3版本中已经绑定了php-fpm 所以,再编译这个版本的时候不需要做打php-fpm补丁的操作了。
下面我就把如何编译并配置php-5.3.3 的步骤写出来,分享给大家。

1  wget http://syslab.comsenz.com/downloads/linux/php-5.3.3.tar.gz
2   tar zxvf php-5.3.3.tar.gz
3   cd php-5.3.3
4   './configure' '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php/etc' '--enable-fpm'  '--with-fpm-user=www' '--with-fpm-group=www' '--with-mysql=/usr/local/mysql' '--with-mysql-sock=/tmp' '--with-libxml-dir' '--with-gd' '--with-jpeg-dir' '--with-png-dir' '--with-freetype-dir' '--with-iconv-dir' '--with-zlib-dir' '--with-mcrypt' '--enable-soap' '--enable-gd-native-ttf' '--enable-ftp' '--enable-mbstring' '--enable-exif' '--enable-zend-multibyte' '--disable-ipv6' '--enable-fastcgi'  '--with-pear' '--with-curl' '--with-openssl'   

5   make && make install

注:如果在以上步骤中,提示找不到libevent 等错误时,那说明你还没有安装libevent这个库,所以需要手动安装一下。可以用yum install -y libevent 这个命令搞定。

如果你顺利执行完以上5步,那么你已经安装好了php-5.3.3

接下来就是需要配置了。
cp  /usr/local/src/php-5.3.3/php.ini-development  /usr/local/php/etc/php.ini
cp  /usr/local/php/etc/php-fpm.conf.default   /usr/local/php/etc/php-fpm.conf

vi  /usr/local/php/etc/php-fpm.conf
需要修改的地方为:
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024

这些地方需要删除行开头的分号。

启动php-fpm  
命令为  /usr/local/php/sbin/php-fpm  -c /usr/local/php/etc/php.ini  -y /usr/local/php/etc/php-fpm.conf
你也可以使用系统启动脚本
cp /usr/local/src/php-5.3.3/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
/etc/init.d/php-fpm start


注:php-5.3.3 并非稳定版本,不建议在生成环境中使用。另外从php-5.3版本起,mysql的驱动已经支持了mysqlnd,据说这个驱动有效减少了内存使用。具体请看 http://mylinux.5d6d.com/thread-408-1-1.html

libjpeg 下载

http://linux.softpedia.com/progDownload/libjpeg-Download-160.html

php探针


放到web根目录下,直接访问,比phpinfo看到的更详细:
<?php
        header("content-Type: text/html; charset=utf-8");
    error_reporting(E_ERROR | E_WARNING | E_PARSE);
        ob_start();
     
    $mysqlReShow = "none";
    $mailReShow = "none";
    $funReShow = "none";
    $opReShow = "none";
    $sysReShow = "none";
     
    define("YES", "<span class='resYes'>YES</span>");
    define("NO", "<span class='resNo'>NO</span>");
    define("ICON", "<span class='icon'>2</span> ");
    $phpSelf = $_SERVER[PHP_SELF] ? $_SERVER[PHP_SELF] : $_SERVER[SCRIPT_NAME];
    define("PHPSELF", preg_replace("/(.{0,}?\/+)/", "", $phpSelf));
     
    if ($_GET['act'] == "phpinfo")
    {
        phpinfo();
        exit();
    }
    elseif($_POST['act'] == "CONNECT")
    {
        $mysqlReShow = "show";
        $mysqlRe = "MYSQL连接测试结果:";
        $mysqlRe .= (false !== @mysql_connect($_POST['mysqlHost'], $_POST['mysqlUser'], $_POST['mysqlPassword']))?"MYSQL服务器连接正常, ":
        "MYSQL服务器连接失败, ";
        $mysqlRe .= "数据库 <b>".$_POST['mysqlDb']."</b> ";
        $mysqlRe .= (false != @mysql_select_db($_POST['mysqlDb']))?"连接正常":
        "连接失败";
    }
    elseif($_POST['act'] == "SENDMAIL")
    {
        $mailReShow = "show";
        $mailRe = "MAIL邮件发送测试结果:发送";
        $mailRe .= (false !== @mail($_POST["mailReceiver"], "MAIL SERVER TEST", "This is a test email."))?"完成":"失败";
    }
    elseif($_POST['act'] == "FUNCTION_CHECK")
    {
        $funReShow = "show";
        $funRe = "函数 <b>".$_POST['funName']."</b> 支持状况检测结果:".isfun($_POST['funName']);
    }
    elseif($_POST['act'] == "CONFIGURATION_CHECK")
    {
        $opReShow = "show";
        $opRe = "配置参数 <b>".$_POST['opName']."</b> 检测结果:".getcon($_POST['opName']);
    }
     
     
    // 系统参数
     
     
    switch (PHP_OS)
    {
        case "Linux":
        $sysReShow = (false !== ($sysInfo = sys_linux()))?"show":"none";
        break;
        default:
        break;
    }
     
/*========================================================================*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>;PHP探针</title>
<style type="text/css">
<!--
body,div,p,ul,form,h1 { margin:0px; padding:0px; }
body { background:#252724; }
div,a,input { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color:#7D795E; }
div { margin-left:auto; margin-right:auto; width:720px; }
input { border: 1px solid #414340; background:#353734; }
a,#t3 a.arrow,#f1 a.arrow { text-decoration:none; color:#978F78; }
a:hover { text-decoration:underline; }
a.arrow { font-family:Webdings, sans-serif; color:#343525; font-size:10px; }
a.arrow:hover { color:#ff0000; text-decoration:none; }
.resYes { font-size: 9px; font-weight: bold; color: #33CC00; }
.resNo { font-size: 9px; font-weight: bold; color: #CC3300; }
.myButton { font-size:10px; font-weight:bold;  background:#3D3F3E; border:1px solid #4A4C49; border-right-color:#2D2F2C; border-bottom-color:#2D2F2C; color:#978F78; }
.bar { border:1px solid #2D2F2C; background:#6C6754; height:8px; font-size:2px; }
.bar li { background:#979179; height:8px; font-size:2px; list-style-type:none; }
table { clear:both; background:#2D2F2C; border:3px solid #41433E; margin-bottom:10px; }
td,th { padding:4px; background:#363835; }
th { background:#7E7860; color:#343525; text-align:left; }
th span { font-family:Webdings, sans-serif; font-weight:normal; padding-right:4px; }
th p { float:right; line-height:10px; text-align:right; }
th a { color:#343525; }
h1 { color:#009900; font-size:35px; width:300px; float:left; }
h1 b { color:#cc3300; font-size:50px; font-family: Webdings, sans-serif; font-weight:normal; }
h1 span { font-size:10px; padding-left:10px; color:#7D795E;  }
#t12 { float:right; text-align:right; padding:15px 0px 30px 0px; }
#t12 a { line-height:18px; color:#7D795E; }
#t3 td{ line-height:30px; height:30px; text-align:center; background:#3D3F3E; border:1px solid #4A4C49; border-right:none; border-bottom:none; }
#t3 th,#t3 th a { font-weight:normal; }
#m4 td {text-align:center;}
.th2 th,.th3 { background:#232522; text-align:center; color:#7D795E; font-weight:normal;  }
.th3 { font-weight:bold; text-align:left; }
#footer table { clear:none; }
#footer td { text-align:center; padding:1px 3px; font-size:9px; }
#footer a { font-size:9px; }
#f1 { text-align:right; padding:15px; }
#f2 {float:left; border:1px solid #dddddd; }
#f2 td { background:#FF6600; }
#f2 a { color:#ffffff; }
#f3 { border: 1px solid #888888; float:right; }
#f3 a { color:#222222; }
#f31 { background:#2359B1; color:#FFFFFF; }
#f32 { background:#dddddd; }
-->
</style>
</head>
<body>
<br />
<form method="post" action="<?=PHPSELF."#bottom"?>">
        <div>
<!-- =============================================================
页头
============================================================= -->
                <a name="top"></a>
                <table width="100%" border="0" cellspacing="1" cellpadding="0" id="t3">
                        <tr>
                                <td><a href="#sec1">服务器特征</a></td>
                                <td><a href="#sec2">;PHP基本特征</a></td>
                                <td><a href="#sec3">;PHP组件支持状况</a></td>
                                <td><a href="#sec4">自定义检测</a></td>
                                <td><a href="<?=PHPSELF?>" class="t211">刷新</a></td>
                                <td><a href="#bottom" class="arrow">66</a></td>
                        </tr>
                </table>
<!-- =============================================================
服务器特性
============================================================= -->
                <table width="100%" border="0" cellspacing="1" cellpadding="0">
                        <tr>
                                <th colspan="2"><p>
                                                <a href="#top" class="arrow">5</a>
                                                <br />
                                                <a href="#bottom" class="arrow">6</a>
                                        </p>
                                        <span>8</span>服务器特性
                                        <a name="sec1" id="sec1"></a>
                                </th>
                        </tr>
                        <?if("show"==$sysReShow){?>
                        <tr>
                                <td>CPU个数</td>
                                <td><?=$sysInfo['cpu']['num']?></td>
                        </tr>
                         <tr>
                            <td>CPU型号</td>
                            <td><?=$sysInfo['cpu']['model']?></td>
                          </tr>
                          <tr>
                            <td>CPU二级缓存</td>
                            <td><?=$sysInfo['cpu']['cache']?></td>
                          </tr>
                        <?}?>
                        <tr>
                                <td>服务器时间</td>
                                <td><?=date("Y年n月j日 H:i:s")?>
                                         北京时间:
                                        <?=gmdate("Y年n月j日 H:i:s",time()+8*3600)?></td>
                        </tr>
                        <?if("show"==$sysReShow){?>
                        <tr>
                                <td>服务器运行时间</td>
                                <td><?=$sysInfo['uptime']?></td>
                        </tr>
                        <?}?>
                        <tr>
                                <td>服务器域名/IP地址</td>
                                <td><?=$_SERVER['SERVER_NAME']?>
                                        (
                                        <?=@gethostbyname($_SERVER['SERVER_NAME'])?>
                                        )</td>
                        </tr>
                        <tr>
                                <td>服务器操作系统
                                        <?$os = explode(" ", php_uname());?></td>
                                <td><?=$os[0];?>
                                         内核版本:
                                        <?=$os[2]?></td>
                        </tr>
                        <tr>
                                <td>主机名称</td>
                                <td><?=$os[1];?></td>
                        </tr>
                        <tr>
                                <td>服务器解译引擎</td>
                                <td><?=$_SERVER['SERVER_SOFTWARE']?></td>
                        </tr>
                        <tr>
                                <td>Web服务端口</td>
                                <td><?=$_SERVER['SERVER_PORT']?></td>
                        </tr>
                        <tr>
                            <td>服务器语言</td>
                            <td><?php echo getenv("HTTP_ACCEPT_LANGUAGE");?></td>
                        </tr>
                        <tr>
                                <td>服务器管理员</td>
                                <td><a href="mailto:<?=$_SERVER['SERVER_ADMIN']?>">
                                        <?=$_SERVER['SERVER_ADMIN']?>
                                        </a></td>
                        </tr>
                        <tr>
                                <td>本文件路径</td>
                <td><?=$_SERVER['DOCUMENT_ROOT']. "<br />".$_SERVER['$PATH_INFO']?></td>
                        </tr>
                        <tr>
                                <td>目前还有空余空间 diskfreespace</td>
                                <td><?=round((@disk_free_space(".")/(1024*1024)),2)?>
                                        M</td>
                        </tr>
                        <?if("show"==$sysReShow){?>
                        <tr>
                                <td>内存使用状况</td>
                                <td> 物理内存:共
                                        <?=$sysInfo['memTotal']?>
                                        M, 已使用
                                        <?=$sysInfo['memUsed']?>
                                        M, 空闲
                                        <?=$sysInfo['memFree']?>
                                        M, 使用率
                                        <?=$sysInfo['memPercent']?>
                                        %
                                        <?=bar($sysInfo['memPercent'])?>
                    Cache化内存为
                                        <?=$sysInfo['memCached']?>
                    M, 真实内存使用率为
                                        <?=$sysInfo['memRealPercent']?>
                    %
                    <?=bar($sysInfo['memRealPercent'])?>
                                        SWAP区:共
                                        <?=$sysInfo['swapTotal']?>
                                        M, 已使用
                                        <?=$sysInfo['swapUsed']?>
                                        M, 空闲
                                        <?=$sysInfo['swapFree']?>
                                        M, 使用率
                                        <?=$sysInfo['swapPercent']?>
                                        %
                                        <?=bar($sysInfo['swapPercent'])?>
                                </td>
                        </tr>
                        <tr>
                                <td>系统平均负载</td>
                                <td><?=$sysInfo['loadAvg']?></td>
                        </tr>
                        <?}?>
                </table>
<!-- =============================================================
PHP基本特性
============================================================== -->
                <table width="100%" cellpadding="0" cellspacing="1" border="0">
                        <tr>
                                <th colspan="2"><p>
                                                <a href="#top" class="arrow">5</a>
                                                <br />
                                                <a href="#bottom" class="arrow">6</a>
                                        </p>
                                        <span>8</span>;PHP基本特性
                                        <a name="sec2" id="sec2"></a>
                                </th>
                        </tr>
                        <tr>
                                <td width="49%">;PHP运行方式</td>
                                <td width="51%"><?=strtoupper(php_sapi_name())?></td>
                        </tr>
                        <tr>
                                <td>;PHP版本</td>
                                <td><?=PHP_VERSION?></td>
                        </tr>
                        <tr>
                                <td>运行于安全模式</td>
                                <td><?=getcon("safe_mode")?></td>
                        </tr>
                        <tr>
                                <td>支持ZEND编译运行</td>
                                <td><?=(get_cfg_var("zend_optimizer.optimization_level")||get_cfg_var("zend_extension_manager.optimizer_ts")||get_cfg_var("zend_extension_ts")) ?YES:NO?></td>
                        </tr>
                        <tr>
                                <td>允许使用URL打开文件 allow_url_fopen</td>
                                <td><?=getcon("allow_url_fopen")?></td>
                        </tr>
                        <tr>
                                <td>允许动态加载链接库 enable_dl</td>
                                <td><?=getcon("enable_dl")?></td>
                        </tr>
                        <tr>
                                <td>显示错误信息 display_errors</td>
                                <td><?=getcon("display_errors")?></td>
                        </tr>
                        <tr>
                                <td>自动定义全局变量 register_globals</td>
                                <td><?=getcon("register_globals")?></td>
                        </tr>
                        <tr>
                                <td>程序最多允许使用内存量 memory_limit</td>
                                <td><?=getcon("memory_limit")?></td>
                        </tr>
                        <tr>
                                <td>;POST最大字节数 post_max_size</td>
                                <td><?=getcon("post_max_size")?></td>
                        </tr>
                        <tr>
                                <td>允许最大上传文件 upload_max_filesize</td>
                                <td><?=getcon("upload_max_filesize")?></td>
                        </tr>
                        <tr>
                                <td>程序最长运行时间 max_execution_time</td>
                                <td><?=getcon("max_execution_time")?>
                                        秒</td>
                        </tr>
                        <tr>
                                <td>magic_quotes_gpc</td>
                                <td><?=(1===get_magic_quotes_gpc())?YES:NO?></td>
                        </tr>
                        <tr>
                                <td>magic_quotes_runtime</td>
                                <td><?=(1===get_magic_quotes_runtime())?YES:NO?></td>
                        </tr>
                        <tr>
                                <td>被禁用的函数 disable_functions</td>
                                <td><?=(""==($disFuns=get_cfg_var("disable_functions")))?"无":str_replace(",","<br />",$disFuns)?></td>
                        </tr>
                        <tr>
                                <td>;PHP信息 ;PHPINFO</td>
                                <td><?=(false!==eregi("phpinfo",$disFuns))?NO:"<a href='$phpSelf?act=phpinfo' target='_blank' class='static'>;PHPINFO</a>"?></td>
                        </tr>
                </table>
<!-- =============================================================
PHP组件支持
============================================================== -->
                <table width="100%" cellpadding="0" cellspacing="1" border="0">
                        <tr>
                                <th colspan="4"><p>
                                                <a href="#top" class="arrow">5</a>
                                                <br />
                                                <a href="#bottom" class="arrow">6</a>
                                        </p>
                                        <span>8</span>;PHP组件支持
                                        <a name="sec3" id="sec3"></a>
                                </th>
                        </tr>
                        <tr>
                                <td width="38%">拼写检查 ASpell Library</td>
                                <td width="12%"><?=isfun("aspell_check_raw")?></td>
                                <td width="38%">高精度数学运算 BCMath</td>
                                <td width="12%"><?=isfun("bcadd")?></td>
                        </tr>
                        <tr>
                                <td>历法运算 Calendar</td>
                                <td><?=isfun("cal_days_in_month")?></td>
                                <td>DBA数据库</td>
                                <td><?=isfun("dba_close")?></td>
                        </tr>
                        <tr>
                                <td>dBase数据库</td>
                                <td><?=isfun("dbase_close")?></td>
                                <td>DBM数据库</td>
                                <td><?=isfun("dbmclose")?></td>
                        </tr>
                        <tr>
                                <td>FDF表单资料格式</td>
                                <td><?=isfun("fdf_get_ap")?></td>
                                <td>FilePro数据库</td>
                                <td><?=isfun("filepro_fieldcount")?></td>
                        </tr>
                        <tr>
                                <td>Hyperwave数据库</td>
                                <td><?=isfun("hw_close")?></td>
                                <td>图形处理 GD Library</td>
                                <td><?=isfun("gd_info")?></td>
                        </tr>
                        <tr>
                                <td>IMAP电子邮件系统</td>
                                <td><?=isfun("imap_close")?></td>
                                <td>Informix数据库</td>
                                <td><?=isfun("ifx_close")?></td>
                        </tr>
                        <tr>
                                <td>LDAP目录协议</td>
                                <td><?=isfun("ldap_close")?></td>
                                <td>MCrypt加密处理</td>
                                <td><?=isfun("mcrypt_cbc")?></td>
                        </tr>
                        <tr>
                                <td>哈稀计算 MHash</td>
                                <td><?=isfun("mhash_count")?></td>
                                <td>mSQL数据库</td>
                                <td><?=isfun("msql_close")?></td>
                        </tr>
                        <tr>
                                <td>SQL Server数据库</td>
                                <td><?=isfun("mssql_close")?></td>
                                <td>MySQL数据库</td>
                                <td><?=isfun("mysql_close")?></td>
                        </tr>
                        <tr>
                                <td>SyBase数据库</td>
                                <td><?=isfun("sybase_close")?></td>
                                <td>Yellow Page系统</td>
                                <td><?=isfun("yp_match")?></td>
                        </tr>
                        <tr>
                                <td>Oracle数据库</td>
                                <td><?=isfun("ora_close")?></td>
                                <td>Oracle 8 数据库</td>
                                <td><?=isfun("OCILogOff")?></td>
                        </tr>
                        <tr>
                                <td>;PREL相容语法 PCRE</td>
                                <td><?=isfun("preg_match")?></td>
                                <td>;PDF文档支持</td>
                                <td><?=isfun("pdf_close")?></td>
                        </tr>
                        <tr>
                                <td>;Postgre SQL数据库</td>
                                <td><?=isfun("pg_close")?></td>
                                <td>SNMP网络管理协议</td>
                                <td><?=isfun("snmpget")?></td>
                        </tr>
                        <tr>
                                <td>VMailMgr邮件处理</td>
                                <td><?=isfun("vm_adduser")?></td>
                                <td>WDDX支持</td>
                                <td><?=isfun("wddx_add_vars")?></td>
                        </tr>
                        <tr>
                                <td>压缩文件支持(Zlib)</td>
                                <td><?=isfun("gzclose")?></td>
                                <td>XML解析</td>
                                <td><?=isfun("xml_set_object")?></td>
                        </tr>
                        <tr>
                                <td>FTP</td>
                                <td><?=isfun("ftp_login")?></td>
                                <td>ODBC数据库连接</td>
                                <td><?=isfun("odbc_close")?></td>
                        </tr>
                        <tr>
                                <td>Session支持</td>
                                <td><?=isfun("session_start")?></td>
                                <td>Socket支持</td>
                                <td><?=isfun("socket_accept")?></td>
                        </tr>
                        <tr>
                                <td>浮点型数据显示的有效位数(precision)</td>
                                <td><?=getcon("precision")?></td>
                                <td>socket超时时间(default_socket_timeout)</td>
                                <td><?=getcon("default_socket_timeout")?>秒</td>
                        </tr>
                        <tr>
                                <td>"<?...?>"短标签(short_open_tag)</td>
              &nbs

fpm_unix_init_child() setrlimit(RLIMIT_NOFILE) failed: Invalid argument

错误信息:
[ERROR] fpm_unix_init_child(), line 168: setrlimit(RLIMIT_NOFILE) failed: Invalid argument (22)  

根据错误信息可以判定,原因在于rlimit_nofile参数那里。首先要看一下系统中ulimit -n
我做了以下三步:
1.  vim /etc/init.d/nginx  在 start 部分添加
ulimit -SHn 51200 如:
start() {
        echo -n $"Starting $prog: "
        ulimit -SHn 51200
        daemon $NGINX_SBIN -c $NGINX_CONF
        RETVAL=$?
        echo
        return $RETVAL
}

2. vim /usr/local/php/sbin/php-fpm  也在start 部分添加
ulimit -SHn 51200 如:
start)
                echo -n "Starting php_fpm "
                ulimit -SHn 51200
                $php_fpm_BIN --fpm $php_opts

                if [ "$?" != 0 ] ; then
                        echo " failed"
                        exit 1
                fi

3. vim /usr/local/php/etc/php-fpm.conf
修改 rlimit_files 参数为 51200
<value name="rlimit_files">51200</value>

分别重启 nginx 和 php-fpm

说明:其实只要保持nginx,php-fpm启动时 ulimit 数值一致就0k了。

编译php时可能出现的错误以及解决办法

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir  --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-sockets --enable-exif --disable-ipv6

错误1: configure:error:xml2-config ont found. Please check your libxml2 installation.
解决: yum install -y  libxml2-devel

错误2: configure:error: Cannot find OpenSSL's <evp.h>
解决: yum install -y openssl-devel

错误3: configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决: yum install -y  libmcrypt-devel

错误4: 在编译php-5.2.10 with php-5.2.10-fpm时,有这样的错误:
/usr/local/src/php-5.2.10/ext/ftp/ ftp.c:291: undefined reference to `SSL_set_fd'
/usr/local/src/php-5.2.10/ext/ftp/ ftp.c:293: undefined reference to `SSL_connect'
/usr/local/src/php-5.2.10/ext/ftp/ ftp.c:287: undefined reference to `SSL_CTX_free'
/usr/local/src/php-5.2.10/ext/ftp/ ftp.c:295: undefined reference to `SSL_shutdown'
collect2: ld returned 1 exit status
make: *** [sapi/cgi/php-cgi] Error 1
解决办法:
1. yum  install -y openssl  openssl-devel  libevent  libevent-devel
2.  make  clean  然后重新  ./config  --with-prefix=/usr/local/php ... (你以前的选项)然后在最后面加上  --with-libevent
3. make