[文章作者:张宴 本文版本: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 | 评论(132) | 引用(0) | 阅读(79150)
nick
2012-9-20 09:15
Nice to be visiting your blog again, it has been months for me. Well this article that I've been waited for so long. moving companies washington dc
GFGF Email Homepage
2012-9-26 11:09
and you also don't need to be considered a Karen Millen UK teenager to put on these playful patterns. Today, florals are available in broad wide variety of age-friendly sizes, colours and prints. But, abstract floral styles of dark and bright are often hit. Sophistication is title on the game. Floral patterns in dark and bright seem stunning and sophisticated. This contrast appears cool, sleek and very flattering relaxing choice.Newspaper Print Pattern:Newspaper print attire lately emerged like a new tendency in Karen Millen sale style world. For those, who desire to seem distinct from all, newspaper print attire creates a smart choice. These sorts of attire offer wearer a specific seem and design that's consideration grabbing. a single has for being extremely cautious even though donning newspaper print dresses. These attire need soberness and hence, there's no must perform with countless colours all at once.All these patterns include sass for your Karen Millen dresses design statement. These stunning patterns will catch the eyesight of crowd and make you really feel positively superb and fabulous.
john Homepage
2012-10-12 03:14
I was working and suddenly I visits your site frequently and recommended it to me to read also. The writing style is superior and the content is relevant. Thanks for the insight you provide the readers!
home mortgage loan company
Chika Email Homepage
2012-10-12 04:59
Certainly a fantastic piece of work ... It has relevant information. Thanks for posting this. Your blog is so interesting and very informative.Thanks sharing. Definitely a great piece of work Thanks for your work.
24 Hour taxi service
john Homepage
2012-10-12 05:56
I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post. Hats off to you! The information that you have provided is very helpful.
intercom nyc
john Homepage
2012-10-13 02:30
The idea behind this article is excellent, and for me the first item ("Create your own damn content!") is the real gem here: most of the people spend their entire lives only consuming what is created by others, and creating nothing themselves--or never sharing what they create, which is better than not creating at all, though not the best they could do.
home mortgage loan company
Sean
2012-10-13 06:00
I am glad to see that people are actually writing about this issue in such a smart way, showing us all different sides to it. Please keep it up. I cant wait to read whats next.
24 Hour taxi service
card access control systems
2012-10-26 02:29
I think the natural and biological sources of vitamins and minerals are best compared with other packaging and plastic products. Always try to push things you need in your home. It is not only going to be cheaper, but it will be much more beneficial to your health and your family. card access control systems
cctv security system
2012-10-26 04:26
Hi! This is my first visit to your blog! We are a team of volunteers and new initiatives in the same niche. Blog gave us useful information to work. You have done an amazing job! cctv security system
Ethan
2012-12-6 23:21
If you need more traffic to your website check out the website in my name. It really helped me and i think it can help your website. locksmith washington dc
Ethan
2012-12-7 00:53
This is such a great post, and was thinking much the same myself. Another great update.replace ignition
Ethan
2012-12-7 02:22
Thanks, I was looking for information and your blog really helped me.Ignition lock
Ethan
2012-12-7 03:22
Good info and Thanks for this.car locksmith
Ethan
2012-12-7 04:14
Hey great stuff, thank you for sharing this useful information and i will let know my friends as well.fha mortgage loan
Ethan
2012-12-7 05:51
Thanks for the great post. You have a well written and informative blog especially for us.online home loans
nico
2012-12-7 19:36
nice to share my love is wonderful to tell you that a healthy green gives you the best Organic vitamins, herbal remedies and organic supplements.
rug cleaning washington dc
nico
2012-12-7 20:14
Very efficiently written information. It will be beneficial to anybody who utilizes it, including me. Keep up the good work. For sure i will check out more posts. This site seems to get a good amount of visitors.
change locks
ewa
2012-12-14 15:25
I'm still learning from you, but I try to reach my goals. Since then enjoy reading all the information that appears on your blog.Keep come. Loved it!
carpet cleaning contractors
ewa
2012-12-14 15:51
You provided a valuable service to the community. Thank you for doing such a great job all these years.
natural supplements
Ethan
2012-12-14 16:24
Thanks for your marvelous posting! I actually enjoyed reading it, you will be a great author.I will ensure that I bookmark your blog and will come back in the foreseeable future. I want to encourage that you continue your great job, have a nice weekend!think you’ve made some truly interesting points
fairfax va local movers
分页: 3/7 第一页 上页 1 2 3 4 5 6 7 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]