日期:2014-05-17  浏览次数:20438 次

【汇总】PHP扩展【xhprof,eaccelerator】

环境

1.PHP 5.3.8,使用fastcgi方式安装,安装目录/usr/local/php

2.CentOS 5.5

?

xhprof

生成xhprof.so

#unzip -o xhprof-0.9.2.zip
#cd xhprof-0.9.2
#cd xhprof-0.9.2/xhprof-0.9.2/extension/
#/usr/local/php/bin/phpize
#./configure --with-php-config=/usr/local/php/bin/php-config
#make
#make install

将生成的xhprof.so放入php的extension_dir下,配置php.ini后,重启php

// 放入php的extension_dir目录下
...

// 配置php.ini
#vi /usr/local/php/lib/php.ini
---
[xhprof]
extension="xhprof.so";
xhprof.output_dir="/var/cache/xhprof"
---

// 重启php
#pkill -o php-fpm
#/usr/local/php/sbin/php-fpm

// 查看phpinfo,检查xhprof是否安装成功
...?

将xhprof_lib,xhprof_html移动到网站目录下

...

写php代码,使用xhprof模块

<?php

// 开启xhprof
if(function_exists('xhprof_enable')) { 
    xhprof_enable(); 
}

// 你的php代码

// 生成报告
if(function_exists('xhprof_disable')) {
    $xhprof_data = xhprof_disable();
    include_once "xhprof_lib/utils/xhprof_lib.php";
    include_once "xhprof_lib/utils/xhprof_runs.php";

    $xhprof_runs = new XHProfRuns_Default();
    $identifier = rand(0,9999);
    $run_id = $xhprof_runs->save_run($xhprof_data, $identifier);

    echo "<a target=\"_blank\" href=\"xhprof_html/index.php?run={$run_id}&source={$identifier}\">view xhprof </a>";
}
?

eaccelerator

生成eaccelerator.so

#tar -zxvf eaccelerator-0.9.6.1.zip
#cd eaccelerator-0.9.6.1
#/usr/local/php/bin/phpize
#./configure --with-php-config=/usr/local/php/bin/php-config
#make
#make install
?

将生成的eaccelerator.so放入php的extension_dir下,配置php.ini后,重启php

// 放入php的extension_dir目录下  
...  
  
// 配置php.ini  
#vi /usr/local/php/lib/php.ini  
---  
[eaccelerator]
extension="eaccelerator.so"
eaccelerator.shm_size="32"
eaccelerator.cache_dir="/tmp"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
eaccelerator.keys = "disk_only"
eaccelerator.sessions = "disk_only"
eaccelerator.content = "disk_only"
---  
  
// 重启php  
#pkill -o php-fpm
#/usr/local/php/sbin/php-fpm
  
// 查看phpinfo,检查eaccelerator是否安装成功
...

?

eaccelerator详细配置说明

此为转载,特此说明,转载地址:http://www.21andy.com/blog/20100207/1646.html

---

eaccelerator.shm_size="32"
eAccelerator 可以使用的共享内存的数量 (以兆为单位) . "0" 是指操作系统的默认值. 默认值是 "0".可根据服务器的实际情况来调整,16,32,64,128都是可以的。

eaccelerator.cache_dir="/home/php/tmp"
这个目录是给磁盘缓存使用. eAccelerator 在这里储存预先编译好的代码, 进程数据, 内容以及用户的自定义内容. 同样的数据也能被储存在共享内存中 (这样可以提高访问速度). 默认的设置是 "/tmp/eaccelerator".

eaccelerator.enable="1"
开启或关闭 eAccelerator。"1" 为开启,"0" 为关闭。默认值为 "1"。

eaccelerator.optimizer="1"
启或关闭内部优化器,可以提升代码执行速度。"1" 为开启,"0" 为关闭。默认值为 "1"。

eaccelerator.check_mtime="1"
打开或者关闭 PHP 的文件修改检查. "1" 是指打开, "0" 是指关闭. 如果您在修改以后重新编译 PHP 的文件,那么您应当设置为 "1". 默认值是 "1".

eaccelerator.debug="0"
开启或关闭调试日志记录。"1" 为开启,"0" 为关闭。默认值为 "0"。会将缓存命中得记录写入日志。

eaccelerator.filter=""
判断哪些 PHP 文件必须缓存。您可以指定缓存和不缓存的文件类型(如 "*.php *.phtml"等)
如果参数以 "!" 开头,则匹配这些参数的文件被忽略缓存。默认值为 "",即,所有 PHP 文件都将被缓存。

eaccelerator.shm_max="0"
当使用 " eaccelerator_put() " 函数时禁止其向共享内存中存储过大的文件。该参数指定允许存储的最大值,单位:字节 (10240, 10K, 1M)。"0" 为不限制。默认值为 "0"。

eaccelerator.shm_ttl="0"
当 eAccelerator 获取新脚本的共享内存大小失败时,它将从共享内存中删除所有在最后 "shm_ttl" 秒内没有存取的脚本缓存。默认值为 "0",即:不从共享内春中删除任何缓存文件。

eaccelerator.shm_prune_period="0"
当 eAc