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

Jamina ·
更新时间:2024-09-21
· 903 次阅读

  相信做php开发的朋友很多都认识xdebug,它确实是php开发过程中检查错误与性能分析的好工具。本章将介绍它的一个蛮不错的功能:函数跟踪。它可以根据程序在实际运行时的执行顺序,跟踪记录所有函数的执行时间,以及函数调用时的上下文,包括实际参数和返回值。   要开启xdebug的函数跟踪功能,需要在php.ini中做一些设置。设置如下:   extension=php_xdebug.dll   [xdebug]   xdebug.auto_trace=on   xdebug.trace_options=1   xdebug.trace_output_dir="E:webserver mpxdebug race"   xdebug.trace_output_name=trace.%c   配置好了时候,重启Apache,然后执行页面会在E:webserver mpxdebug race目录下生成报告文件。   打开报告文件,格式类似如下:   0.0348     379272    -> dirname() E:webhostmysite.comframeworkController.php:27   0.0395     655712    -> require(E:webhostmysite.comframeworksmartySmarty.class.php) E:webhostmysite.comframeworkController.php:27   0.0396     657784    -> defined() E:webhostmysite.comframeworksmartySmarty.class.php:37   0.0396     657824    -> define() E:webhostmysite.comframeworksmartySmarty.class.php:38   0.0397     657840    -> defined() E:webhostmysite.comframeworksmartySmarty.class.php:45   0.0398     657864    -> dirname() E:webhostmysite.comframeworksmartySmarty.class.php:46   0.0399     657864    -> define() …………………………………………………………………………………………………………………………..…………………………………………………………………………………………………………………………..   0.0206     300960    -> require_once(E:webhostmysite.comappprotectedmodelsTest.php)   0.0209     300672    -> is_resource() E:webhostmysite.comframeworkModel.php:63   0.0209     300672    -> Model->_connect() E:webhostmysite.comframeworkModel.php:63   0.0210     301776    -> PDO->__construct() E:webhostmysite.comframeworkModel.php:71   0.0253     299736    -> Test->selectData() E:webhostmysite.comappprotectedcontrollersDefaultController.php:25   0.0254     299896    -> Model->select() E:webhostmysite.comappprotectedmodelsTest.php:43   从报告中,可以看到require(E:webhostmysite.comframeworksmartySmarty.class.php)花了0.0047s,另外Test->selectData()函数花了0.0043秒,这两个函数花的时间远远高于其他函数所花的时间,好了,有了这些报告,我们知道可以从哪些地方优化网站性能了。



性能 测试网 测试网站 函数 功能测试 网站性能 xdebug 测试

需要 登录 后方可回复, 如果你还没有账号请 注册新账号