XHProf是一个分层PHP性能分析工具。它报告函数级别的请求次数和各种指标,包括阻塞时间,CPU时间和内存使用情况。一个函数的开销,可细分成调用者和被调用者的开销,XHProf数据收集阶段,它记录调用次数的追踪和包容性的指标弧在动态callgraph的一个程序。它独有的数据计算的报告/后处理阶段。在数据收集时,XHProfd通过检测循环来处理递归的函数调用,并通过给递归调用中每个深度的调用一个有用的命名来避开死循环。XHProf分析报告有助于理解被执行的代码的结构,它有一个简单的HTML的用户界面( PHP写成的)。基于浏览器的性能分析用户界面能更容易查看,或是与同行们分享成果。也能绘制调用关系图。
推荐阅读:http://blog.aboutc.net/php/17/php-profiler-xhprof#xhprof_enable_parameters
# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm # rpm -ivh epel-release-6-8.noarch.rpm # wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm # rpm -ivh remi-release-6.rpm # vim /etc/yum.repos.d/ remi.repo
[remi] name=Les RPM de remi pour Enterprise Linux 6 - $basearch #baseurl=http://rpms.famillecollet.com/enterprise/6/remi/$basearch/ mirrorlist=http://rpms.famillecollet.com/enterprise/6/remi/mirror enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
yum install httpd mysql-server php php-devel php-mysql php-mbstring php-mcrypt php-gd
chkconfig --level 235 httpd on chkconfig --level 235 mysqld on
service httpd start service mysqld start
[root@CentOS-Josen cache]# netstat -tuln | grep ':3306' tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
mysql -u root 然后退出quit mysqladmin -u root password 'yourpassword'
vi /var/www/html/info.php <?php phpinfo(); ?>
yum install php-pecl-xhprof 下载xhprof.tar.gz地址:http://download.csdn.net/detail/e421083458/7028089 将xhprof.tar.gz 放到/var/www/html cd /var/www/html tar -zxvf xhprof.tar.gz mv facebook-xhprof-ec8b884/ xhprof chown -R apache:apache /var/www/html/xhprof chmod -R 775 /var/www/html/xhprof cd /etc/php.d/ vim xhprof.ini,改成:xhprof.output_dir = /var/www/html/xhprof_html yum install graphviz 重启apache 或者nginx
<?php define('IS_XHPROF_ENABLE', true); if(IS_XHPROF_ENABLE){ xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); xhprof_enable(); } 代码部分................... write_to_xhprof(); function write_to_xhprof() { if(IS_XHPROF_ENABLE){ // stop profiler $xhprof_data = xhprof_disable(); $XHPROF_ROOT = dirname(__FILE__); include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php"; include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php"; echo "xhoprof"; // save raw data for this profiler run using default // implementation of iXHProfRuns. $xhprof_runs = new XHProfRuns_Default(); // save the run under a namespace "xhprof_foo" $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_test"); } } ?>