相信做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的函数跟踪功能测试网站性能
发表于:2017-01-09
作者:网络转载
来源:
- 周排行
- 月排行
-   Web功能测试常用方法
-   优化网站性能架构提升用户体验(下)
-   常见的Web安全漏洞及测试方法介绍
-   Web 测试教程:包含优秀实践的综合指南
-   如何在手机上测试Web项目?
-   APP测试和Web测试的区别
-   WEB端与移动端测试区别总结
-   Web系统功能测试18个点总结
-   如何自动执行跨浏览器兼容测试?
-   大型网站压力测试及优化方案
-   盘点十大最新Web UI测试工具
-   如何在手机上测试Web项目?
-   Web测试页面状态码总结