[文章作者:张宴 本文版本:v1.0 最后修改:2007.06.28 转载请注明出处:http://blog.zyan.cc]

  经济学中有一条著名的80-20定律,引用到编程中,就是:80%的性能瓶颈是由20%的代码引起的。借助PHP的XDebug扩展,可以有效地找出这20%的代码。

  一、安装配置
  1、下载PHP的XDebug扩展,网址:http://xdebug.org/

  2、在Linux下编译安装XDebug
引用
tar -xzf xdebug-2.0.0RC3.gz
cd xdebug-2.0.0RC3
/usr/local/php/bin/phpize
./configure --enable-xdebug
cp modules/xdebug.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20020429/

  注:/usr/local/php/lib/php/extensions/no-debug-non-zts-20020429/不同的PHP版本路径不同,也不一定要放在该路径,可以在zend_extension_ts中自行指定xdebug.so所在位置。

引用
vi /usr/local/php/lib/php.ini

  修改php.ini,去除PHP加速模块,增加以下配置信息支持XDebug扩展

引用
mkdir -p /tmp/xdebug
chmod 755 /tmp/xdebug
chown www:www /tmp/xdebug
/usr/local/apache/bin/apachectl -k restart


  3、客户端(Windows):WinCacheGrind
  下载地址:http://sourceforge.net/projects/wincachegrind/

  二、分析过程
  1、访问你的网站,将首页上各种链接点击几遍,XDebug在/tmp/xdebug目录生成以下文件:
  usr_local_apache_htdocs_app_checknum_chknum_php_cachegrind.out
  usr_local_apache_htdocs_app_login_showHeaderLogin_php_cachegrind.out
  usr_local_apache_htdocs_app_play_play_php_cachegrind.out
  usr_local_apache_htdocs_app_user_member_php_cachegrind.out
  usr_local_apache_htdocs_tag_tags_php_cachegrind.out
  usr_local_apache_htdocs_top_top_php_cachegrind.out

  2、将以上文件拷贝到Windows上,用客户端软件WinCacheGrind打开每个文件,发现以下PHP程序执行所耗费的时间最长:
  /usr/local/apache/htdocs/tag/tags.php      耗时840ms

  三、分析结果:
  1、/usr/local/apache/htdocs/tag/tags.php

  点击在新窗口中浏览此图片

  (1)耗时最长的filter_tags函数出现在/usr/local/apache/htdocs/tag/tags.php的第158行:
  $tags .= filter_tags($videos[$i]['tags'])." ";

  (2)filter_tags函数引自/usr/local/apache/htdocs/include/misc.php,getForbiddenTags函数被filter_tags函数调用了21次,filter_tags函数耗费的时间中绝大多数因getForbiddenTags函数所致。getForbiddenTags函数的内容如下:

  (4)对getForbiddenTags函数进行分析,其中的PHP函数trim被调用了16827次。
  点击在新窗口中浏览此图片

  (5)可能造成瓶颈的原因:
  要过滤的156个关键字逐行存放在/usr/local/apache/template/tags/forbidden_tags.txt文件中,文本数据库的效率不高。
  逐行读取函数fgets、以及去除字符串两边的空白或者指定的字符的函数trim在高负载下的效率低,可以测试fopen、fread、fscanf之类的文件读取函数,对比一下。

Tags: ,



技术大类 » PHP/JS/Shell | 评论(158) | 引用(0) | 阅读(107018)
simonliu
2008-7-22 16:19
好像要加上这个才能加载xdebug.so模块吧?
extension=xdebug.so
chinawolfs Email
2008-7-31 09:32
确实不错....但我安装在ngnix上,好像没有用,请问是什么原因呢?
我的MSN是chinawolfs@hotmail.com
diuwo
2009-3-5 16:25
forbidden_tags 哈哈 确实很让人头疼 当行数超过10000的时候 头疼吧 哈哈
cyzkl
2009-4-22 19:58
感觉用zendprofile 也不错。。。。图形化
JeremyWei Email Homepage
2009-8-1 20:34
# xdebug.profiler_output_name="script"  这行不需要吧,使用默认的文件格式就好了吧,
要不生成的profiler文件名都是script.*格式的,但是WinCacheGrind好像只能打开cachegrind.out.*格式的文件。
桂林 Email Homepage
2011-10-25 15:39
不错,提高效率
coach factory outlet Email Homepage
2012-5-17 10:44
Today, following half a century, mentor leather-bases coach factory outlet continues to be the delicate craft of leather-based master is accountable for,Would you like to meet more friends, or go with the times? If yes, coach factory online is opening welcome doors to you.in the market you definitely can find various colorways that are designed in as well as the high quality that applied in. For most of you would like to come. So just come to our coach factory outlet online store to choose one.
louis vuitton sale Email Homepage
2012-5-17 10:44
Louis Vuitton belt at louis vuitton sale is one kind of fashion accessory with high cost performance among the Louis Vuitton accessories.Offering quality LV products with favorable prices, louis vuitton outlet store is at your service. Hurry up, or you can not seize the chance.in fact, louis vuitton is one of the most famous fashion design master.he opened the fist suitcase shop called after his name.
coach outlet online Email Homepage
2012-5-17 10:44
I heard of coach outlet online through the advertisement when I was shopping. And now I often brow the webpage and buy Coach bags online.It is a symbol regarding position not to mention nature.Here I would like to launch a excellent bags pertaining to business men.Which may be coach outlet store.coach outlet has always been simple,durable style features to win consumers.The products are more flexible,with easy bleaching,wear characteristics,and simply use a damp cloth.
coach outlet, Email Homepage
2012-5-17 10:45
Remember the coach outlet provide coach bags which won't be deteriorated into its overall styles by any means. It will maintain its looks, colors, and uniqueness for long time.coach outlet store online has been voted by Hour Detroit magazine readers as the Best of Detroit in their 12th annual readers'poll.Lots of women like which usually amount normally include a coach outlet online ,it provides coziness to many girls that don't even think it is a great bushel of great interest directly to them.
Coach Outlet Online Email Homepage
2012-5-18 10:14
to obtain Coach Outlet Online in Hainan is amongst the brand new darling from residential holiday makers.He has served as Chairman and Chief Executive Officer of Coach since November 1995. He has served as a member of Coach Outlet Board of Directors since June 1, 2000, the date of incorporation. 
Coach  Outlet Email Homepage
2012-5-18 10:38
Coach Outlet was founded in 1941, in a loft in New York City.as a partnership called the Gail Manufacturing Company. Gail Manufacturing Company began as a family-owned business, with six leatherworkers who made small leather goods, such as wallets and handbags.Coach Outlet Online Store guarantee that all the coach handbags offered are own high quality. In addition , all of them are sold at an unexpected low price.If you want to purchase, just visit their website. 
Coach  Outlet Email Homepage
2012-5-18 10:45
Five years later in 1985, the Cahns decided to sell Coach Outlet after determining that none of their three children had any desire to take over the family leatherware business . Coach was then sold to Sara Lee Corporation for $30 million dollars.electric, diesel and mainline electric multiple units (EMU, DMU, MEMU), metro Coach Outlet Canada and Diesel Electric Tower Cars (DETC), Accident Relief Medical Vans (ARMV), Inspection Cars (RA), Fuel Test Cars, Track Recording Cars, the latest coaches are for the Deccan Odyssey . 
Louis Vuitton Email Homepage
2012-5-18 10:51
During this period, Louis Vuitton incorporated its leather into most of its products, ranging from small purses and wallets to larger pieces of luggage.To emphasize Jacobs's fashionable volte face, Kate Moss-last season's saucy Louis Vuitton UK dominatrix was recast for spring as the ballerina on that music box in a gleaming white baby doll frock and Barbie white stilettos. 
Louis Vuitton UK Email Homepage
2012-5-18 10:57
This Louis Vuitton UK for sale belongs to the sounding just what are termed as Louis Vuitton vintage best sellers, many other products and services for the reason that range appearing companies.In 1983, the company joined with America's Cup to form the Louis Vuitton Cup, a preliminary competition (known as an eliminatory regatta) for the yacht race. 
xujie777 Email
2012-5-18 15:35
We aim to make all our customers satisfy with our products. You will find a variety of Men's fashion louis vuitton uk, fashion Women's cheap Louis Vuitton bags in our store at affordable price.Thinking of interesting ways to cost a milestone birthday? louis vuitton online shop had one of the most distinctive distinctive celebrations.bakery along with living room operated by means of about three moment louis vuitton online Most effective Pastry Chef’s of the year Rammy Nominee Chef’s.
xujie777 Email
2012-5-18 15:35
The choices are likely to be basically countless seeing that louis vuitton outlet occurs with the help of completely new and also incredible concepts once in a while.Louis vuitton Wholesale Monogram Canvas HandbagsLouis Vuitton Collection Beach Handbags louis vuitton bags outlet Damier Canvas HandbagsLouis vuitton Mahina HandbagsLouis Vuitton Monogram Mini Lin HandbagsLouis Vuitton Monogram Multicolore HandbagsLouis vuitton Monogram Vernis HandbagsLouis Vuitton Wholesale Epi Leather HandbagsLouis Vuitton For Men HandbagsLouis Vuitton Damier Canvas WalletsLouis Vuitton Epi Leather WalletsLouis Vuitton Monogram Canvas WalletsLouis Vuitton Monogram Vernis WalleLouis Vuitton ShoesLouis Vuitton Men wallets.As the Authentic Louis Vuitton are so high-priced, so came the louis vuitton handbags outlet.
xujie777 Email
2012-5-18 15:35
coach outlet has become a popular shopping experience for consumers around the world, and a desirable distribution channel for manufacturer's and retailers.Getting your hands on coach outlet store online can be a hefty investment of hundreds of dollars.But do not despair,the Coach Outlet store could be the answer to your prayers.coach outlet online is your smart choice when you want to get the discount Coach accessory. You can find the exact Coach Bags and other accessory you want at a low price that's right for you. My dear friends, let the coach outlet online pave your way into the world of high fashion with their ultimate fashion factory.
Christian Louboutin Email Homepage
2012-5-18 17:10
christian louboutin have own characteristic designs. The beautiful crystals have added the magical finishing touch to countless bridal gowns. Just get some for yourself. The first Men's Boutique, christian louboutin uk Boutique Homme on Rue Jean-Jacques Rousseau in Paris, opened in the summer of 2012.
Louis Vuitton UK Email Homepage
2012-5-18 17:11
Cheap louis vuitton uk wholesale offers a variety of options to satisfy your needs. Some new ones even has fashionable styles fold over flap to disguise the snap closure and a draw string is added for a convenient closure. Louis vuitton outlet online just like a person who want to show himself in front of other people, because he is confident enough, he can attain the respect of other people.
分页: 1/8 第一页 1 2 3 4 5 6 7 8 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]