[文章作者:张宴 本文版本: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) | 阅读(106626)
CoachOutlet Email Homepage
2012-5-18 17:11
coach outlet has become a popular shopping experience for consumers around the world, and a desirable distribution channel for manufacturer's and retailers. Coach outlet online develops very quickly because it runs by its own special way and it contents the customers greatly.
Air Jordan Email Homepage
2012-5-18 17:11
Thank you for shopping in our store. We are a reliable online jordan bags seller, specialist in providing numbers of new air jordan bags at amazing price . If you need practical, fashionable and well-known nike dunks, you can consider to choosing on the nike Outlet. Its nice and popular design will make you feel a sense of fresh air.
Nike Air Max Email Homepage
2012-5-18 17:12
This nike air max for sale belongs to the sounding just what are termed as nike air vintage best sellers, many other products and services for the reason that range appearing companies the actual nike air Galliera, plus the nike air outlet monogram selection. nike dunks are made of high leather materials which can be durable and fashionable.They will make you become the focus in the streets or audience.
xujie123
2012-5-21 11:01
Our online store offers you discounted Designer louis vuitton replica wallet at present. You could find them in desirable quality and price. If you don't mind high class louis vuitton uk, have a good time here.louis vuitton Store Online Handbags can also bring great accuracy as well as practical applicability and fashionable.Have you ever dreamed of being as charming as Madonna? Have you ever thought of becoming an envy of all your friends? If so, come to louis vuitton outlet.<br/>
xujie555
2012-5-21 13:23
coach factory outlet uses graceful accessories to match the classical logo of coach, which is the best combination of coach. The handmade coach products?can make you more charming and graceful.coach factory online provides people many coach goods. If you wish to snatch the coach handbag, then this best method is made for that you like for coach discount.coach factory outlet online is a fashion brand to ensure its quality. With designer coach shoulder bags, you will always attract people's attention. The bags will emphasize your personal style and taste.<br/>
xujie333
2012-5-21 14:45
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 factory outlet is really sizzling kinds of shopping way for you. With the usage of the replica designer coach bags, you can surely be able to change your individual looks in a stunning manner.Coach bags on sale from the coach outlet are cheap or discount prices that you certainly will stand out from the crowd on your next camping trip!<br/>
coach88888888 Email
2012-8-13 17:29
Coach Factory Outlet offer excellent, elegant coach products in order to generate room for your new collections.They're purchased more quickly that you may at any time imagine.Most significantly, the coach designer purses of Coach Factory Online industry won't deteriorate your individual fashions at all. Rather they would immediately change your overall looks marvelously.I find it all very odd But this is no different than Coach Outlet Online any other company that has an outlet presence and really doesn’Coach Outlet Store t explain it to the customer.By the fashion, novel appearance, sophisticated technology, superior quality, Coach Outlet won domestic and international customers, their products exported to the Middle East, Southeast Asia and other regions.
Buy Codeine Online Email Homepage
2012-8-25 01:00
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.
Bonfire Email Homepage
2012-9-6 23:39
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.
Bonfire
google organic seo Email Homepage
2012-9-7 00:00
This is like my fourth time stopping over your Blog. Normally, I do not make comments on website, but I have to mention that this post really pushed me to do so. Really great post .
kteen Email Homepage
2012-9-7 01:37
Preservation and promotion of health is achieved through a combination of physical, mental and social well-being, sometimes called "the triangle of health." Health is a positive concept focuses on the social and personal resources, as well as physical capacities.
john Email
2012-9-7 02:06
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! pakistani restaurant in Melbourne
drug forum Email Homepage
2012-9-7 03:38
I am speechless after seeing these pictures! I love them all! I teach kindergarten and I'm going to make a theme, and photographs have given me so many ideas! You are so talented! Thanks!<a href="http://www.drugdiscussions.com/">drug forum</a>
organic seo company Email Homepage
2012-9-7 05:35
Wonderful post. I am searching awesome news and idea. What I have found from your site, it is actually highly content. You have spent long time for this post. It's a very useful and interesting site. Thanks!
cost effective seo Email Homepage
2012-9-7 06:08
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.
cost effective seo
google advertising company Email Homepage
2012-9-7 06:51
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.google advertising company
locksmith in bethesda md Email Homepage
2012-9-12 08:01
Hi buddy, your blog's design is simple and clean and i like it. Your blog posts are superb. Please keep them coming. Greets!!!
Washington dc locksmith Email Homepage
2012-9-12 17:48
I admire The Valuable information you offer in your articles. I Will bookmark your blog and check my buy ritalin online.
Thanks for posting!
emeca
2012-9-12 23:39
Your site is good Actually, i have seen your post and That was very informative and very entertaining for me. Thanks for posting Really Such Things. I should recommend your site to my friends. Cheers.

locksmith in silver spring md  
sleepystupid
Towing in dallas Email Homepage
2012-9-13 17:58
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.They use all natural ingredients to create organic products.
分页: 2/8 第一页 上页 1 2 3 4 5 6 7 8 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]