您的位置:首页 > 运维架构 > 网站架构

用xdebug的函数跟踪功能测试网站性能

2012-03-20 17:48 197 查看
相信做php开发的朋友很多都认识xdebug,它确实是php开发过程中检查错误与性能分析的好工具。本章将介绍它的一个蛮不错的功能:函数跟踪。它可以根据程序在实际运行时的执行顺序,跟踪记录所有函数的执行时间,以及函数调用时的上下文,包括实际参数和返回值。

要开启xdebug的函数跟踪功能,需要在php.ini中做一些设置。设置如下:

extension=php_xdebug.dll

[xdebug]

xdebug.auto_trace=on

xdebug.trace_options=1

xdebug.trace_output_dir="E:\web\server\tmp\xdebug\trace"

xdebug.trace_output_name=trace.%c
配置好了时候,重启Apache,然后执行页面就会在E:\web\server\tmp\xdebug\trace目录下生成报告文件。
打开报告文件,格式类似如下:

0.0348 379272 -> dirname() E:\web\host\mysite.com\framework\Controller.php:27

0.0395 655712 -> require(E:\web\host\mysite.com\framework\smarty\Smarty.class.php) E:\web\host\mysite.com\framework\Controller.php:27

0.0396 657784 -> defined() E:\web\host\mysite.com\framework\smarty\Smarty.class.php:37

0.0396 657824 -> define() E:\web\host\mysite.com\framework\smarty\Smarty.class.php:38

0.0397 657840 -> defined() E:\web\host\mysite.com\framework\smarty\Smarty.class.php:45

0.0398 657864 -> dirname() E:\web\host\mysite.com\framework\smarty\Smarty.class.php:46

0.0399 657864 -> define() …………………………………………………………………………………………………………………………..…………………………………………………………………………………………………………………………..

0.0206 300960 -> require_once(E:\web\host\mysite.com\app\protected\models\Test.php)

0.0209 300672 -> is_resource() E:\web\host\mysite.com\framework\Model.php:63

0.0209 300672 -> Model->_connect() E:\web\host\mysite.com\framework\Model.php:63

0.0210 301776 -> PDO->__construct() E:\web\host\mysite.com\framework\Model.php:71

0.0253 299736 -> Test->selectData() E:\web\host\mysite.com\app\protected\controllers\DefaultController.php:25

0.0254 299896 -> Model->select() E:\web\host\mysite.com\app\protected\models\Test.php:43
从报告中,可以看到require(E:\web\host\mysite.com\framework\smarty\Smarty.class.php)花了0.0047s,另外Test->selectData()函数花了0.0043秒,这两个函数花的时间远远高于其他函数所花的时间,好了,有了这些报告,我们就知道可以从哪些地方优化网站性能了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: