LaneBlog

蝼蚁虽小,也有梦想

PHP Socket服务 | PHP微信开发框架 | 开源博客

XHProf的安装和使用(PHP性能测试神器)

Clicks: 12382 Date: 2014-06-13 16:12:18 Power By 李轩Lane

PHP XHProf

    XHProf是Facebook开发的性能调试工具,帮助我们的PHP程序性能调优,更加健壮。XHProf安装和使用方法将在本章讲解。XHProf是PHP的PECL扩展。没有XDeBug那些耗费资源,更加的小巧。
    流程:程序开头打点,结尾打点。那么XHProf机会记录在两个点之间的所有代码响应时所耗费的时间、内存、CPU等各项指标,我们也可以知道一次请求调用了多少次MySQL,多少次Memcache,更加直观的指明优化道路。
    安装:
------------下载并编译PHP-XHProf源码------------
wget http://pecl.php.net/get/xhprof-0.9.4.tgz
tar -zxvf xhprof-0.9.4.tgz
cd xhprof-0.9.4
cd extension
phpize
./configure --enable-xhprof
make
make test
sudo make install

------------修改php.ini---------------
sudo vim /etc/php.ini
#在php.ini最下方加入以下:
extension=xhprof.so
xhprof.output_dir="/var/www/xhprof"

-----------重启Apache--------------
sudo apache restart
进入刚才解压的安装包文件夹中,将xhprof_lib和xhprof_html复制到项目目录下。 接下来,建立一个头文件head.php,这是要打两个点中的开头的点:
//head.php
<?php
if(extension_loaded('xhprof')){
    //载入下载的XHPROF包中的2个文件夹
    include_once 'xhprof_lib/utils/xhprof_lib.php';
    include_once 'xhprof_lib/utils/xhprof_runs.php';
    xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
}
再建立一个底部文件foot.php,这是要打两个点中的结尾的点:
//foot.php
<?php
if(extension_loaded('xhprof')){
    $ns = 'myXhprof';
    //关闭profiler
    $xhprofData = xhprof_disable();
    //实例化类
    $xhprofRuns = new XHProfRuns_Default();
    $runId = $xhprofRuns->save_run($xhprofData, $ns);
    //前端展示库的URL
    $url = 'http://localhost/xhprof_html/index.php';
    $url .= '?run=%s&source=%s';
    //变量替换
    $url = sprintf($url, $runId, $ns);
    //输入URL
    echo '<a href="'.$url.'" target="_blank">查看结果</a>';
}
使用的最后一步:打点。现在我们建立一个测试文件index.php。测试我大Hello World。
//index.php
<?php
include_once 'head.php';
echo 'Hello World';
include_once 'foot.php';
可以看到,在http://localhost/index.php中,最下面是我们在foot.php中写的“查看结果”,点击进去,可以看到本次请求所使用到的所有函数的列表,每个函数所耗费的时间、CPU、Memory等信息,点击第一栏可以根据所选排序。点击[View Full Callgraph]可以看到由本列表所生成的流程图,从入口到哪个函数,又到哪个函数,这个函数调用了哪个函数,这个函数调用了多少次Memcache等,一幕了然。减少MC的调用,减少这个,减少那个,请求的响应速度能不快吗? 技巧: 我有1000个文件,现在我需要用XHProf检测一下我整个项目,难道要每个文件头部和尾部都要加上include吗? 在php.ini中添加:
auto_prepend_file = /var/www/head.php
auto_append_file = /var/www/foot.php
或者在.htaccess中添加
php_value auto_prepend_file = /var/www/head.php
php_value auto_append_file = /var/www/foot.php
报错: 1、点击[View Full Callgraph]查看图片的时候报错:failed to execute cmd:" dot -Tpng". stderr:`sh: dot:command not found`。 原因:原因:未安装图形化工具 解决:
//红帽系列
yum install graphviz
//Ununtu
apt-get install graphviz
//OS X
brew install graphviz

Reply: inetryconydot On 2020-01-27 05:09:34

<a href=http://rebizsearch.com/in.cgi?5&group=BgMeds&parameter=Amoxil><b>Buy Cheap <font color=red>Amoxicillin</font> High Quality!</b></a> <font color=green>* Secure ordering! * Free Shipping Worldwide * Lowest price guaranteed! * Fully licensed pharmacy * NO PRESCRIPTION REQUIRED * Superior customer service 24/7 -- Very easy to get Amoxicillin online! * 100% Satisfaction Guaranteed * We accept: VISA, MasterCard, E-check, AMEX and more.</font> <b>Amoxicillin (Amoxil)</b> is used to treat infections due to organisms that are susceptible to the effects of amoxicillin. Common infections that amoxicillin is used for include infections of the middle ear, tonsils, throat, larynx (laryngitis), bronchi (bronchitis), lungs (pneumonia), urinary tract, and skin. It also is used to treat gonorrhea. <a href=http://rebizsearch.com/in.cgi?5&group=BgMeds&parameter=Amoxil><b>Buy Cheap <font color=red>Amoxicillin</font> High Quality!</b></a> Amoxicillin © 2008-2013, Top Pharmacy List! * Medication Without A Prescription! * You Can Find: The Best Quality Pills, Special Discount Medication, Full Information, Best Price Pill Or Capsules, Fast Delivery, Alternative Tablets, Fda Approved Brand & Generic Drugs Without Prescription! No Hidden Costs Or Membership Fees, Easy Ordering Process! <b>Frequently Asked Questions</b> - What does Generic mean? - What is the difference between Soft and Regular tabs? - How do you ship orders and how long does it take? Tags: Amoxicillin Online <b>Amoxicillin During Pregnancy</b> Order Cheap Buy Order Cheap Amoxicillin Sale Amoxicillin In Los Angeles <quote>read news...</quote> Amoxicillin Buy Without Prescription Buy Amoxicillin Online No Script Michigan Buy Amoxicillin on line Where To Buy Amoxicillin In Springfield Order Amoxicillin Buy Amoxicillin Cheap Fort Saskatchewan Amoxicillin Buy Online Amoxicillin Order In Lincoln Amoxicillin Over The Counter Amoxicillin Fast Delivery To Hull Amoxicillin Online Nz Expired Amoxicillin Amoxicillin Amoxil <b>Amoxicillin Chlamydia</b> Amoxicillin Uses Buy Amoxicillin Online In Sheffield Amoxicillin Online Pharmacy Detroit Cheap Amoxicillin Pill In England Amoxicillin Trihydrate Amoxicillin 500 Mg Amoxicillin Online Sydney Australia Amoxil Amoxicillin <quote>read more...</quote> Buy Amoxicillin In Amsterdam Buy Amoxicillin Online No Prescription Amoxicillin 500 Sale Amoxicillin Connecticut Order Amoxicillin Deutschland/Online Kaufen Amoxicillin Sale Amoxicillin In Us Without Doctor Rx Amoxicillin Antibiotic Side Effects Pill Amoxicillin In Leon Buy Amoxicillin Uk No Prescription Sale Amoxicillin Texas Amoxicillin Prescription <i>Amoxicillin 500</i> <quote>...</quote> Amoxicillin Fast Delivery To Idaho Amoxicillin For Sale Maryland Buy Amoxicillin Edinburgh Amoxicillin Northern Ireland Cheap Amoxicillin Online Uk Allergic Reactions To Amoxicillin Sale Amoxicillin In Usa Amoxicillin During Pregnancy Cheap Amoxicillin Without A Prescr'S Idaho Amoxicillin For Sinus Infection No Prescription Amoxicillin Ca Nada Amoxicillin 875 Mg Amoxicillin For Sale No Script Brisbane Amoxicillin 250mg Us Pharmacy No Prescription Master Card Amoxicillin Florida Buy Amoxicillin From Mexico Amoxicillin Augmentin Amoxicillin Online Without Prescription <b>Buy Amoxicillin No Prescription</b> Buy Amoxicillin cheap Order Amoxicillin Purchase Phoenix Vente Amoxicillin Sale Amoxicillin In Missouri No Prescription Allergic Reactions To Amoxicillin Amoxicillin Generic Usa Buy Amoxicillin Online In Kingston Amoxicillin Sinus Infection <i>Online Pharmacy Cod Amoxicillin Buy In Coventry</i> Amoxicillin Buy In Uk Online Buy Amoxicillin Without Prescription Cheap Amoxicillin Amoxicillin For Sale Usa Amoxicillin Order In Toronto Amoxicillin Buy Without Prescription Lowest Price How To Buy Buy Amoxicillin Sale Amoxicillin In Ohio Buy Amoxicillin Online In Reading Amoxicillin Fast Delivery To Kingston Amoxicillin Overinght Texas Amoxicillin Buy Online Online Pharmacy London Uk Cheapest Amoxicillin Uk Cheap Buy Amoxicillin Without Prescription Amoxicillin Overinght Us Amoxicillin No Prescription Super Buy Cheap Amoxicillin Buy In Baltimoredf Amoxicillin Antibiotic Side Effects Cheap Amoxicillin In France Amoxicillin Online Without Prescription Usa Amoxicillin Amoxil <quote>USA TODAY NEWS...</quote> Amoxicillin Without Prescription Order Amoxicillin In Canada Buy Amoxicillin Online Pharmacy South Dakota Amoxicillin For Sale Amoxicillin Cheap Canada Pharmacy Amoxicillin Sale Amoxicillin In Norway Without Receipt Amoxicillin 250mg Order Amoxicillin Online Discount Montana Amoxicillin And Cod Saturday Delivery In Troyes <b>Amoxicillin Dosage For Sinus Infection</b> What Is Amoxicillin Used For Buying Amoxicillin In Internet Drugs Without Prescription Israel No Prescription Amoxicillin Cod Accepted Usa Wellington Amoxicillin Best Price On Amoxicillin In Stokeontrent Allergic Reactions To Amoxicillin Buy Amoxicillin In Kelowna Order Amoxicillin Online Discount Kansas Rash From Amoxicillin <b>Amoxicillin Online</b> Buy Amoxicillin Uk Online Amoxicillin Cod Fedex Hawaii Softtabs No Prescription Amoxicillin Florida Buying Amoxicillin Uk Amoxicillin Buy Without Prescription Levitra No Prescription Amoxicillin Baltimore Amoxicillin Allergy Discount On Amoxicillin In Sweden Amoxicillin Dosage For Sinus Infection No Prescription Needed Amoxicillin Wisconsin <b>Amoxicillin Rash</b> Soft Tabs No Prescription Amoxicillin Ohio Buy Generic Amoxicillin Uk Amoxicillin Buy Online Overnight Vermont Amoxicillin For Sale Buy Amoxicillin Online

回复

Add Comment
©2014 www.lanecn.com , All rights reserved. Power By Li Xuan.  京ICP备14005030号