分析在 apache 中运行的 PHP
我想知道在 apache 上运行的应用程序正在调用哪些函数以及每个请求花费的时间。
有没有任何工具或任何其他方式可以获取这些数据。
我还想知道每个函数花费了多少时间。
应用程序正在运行,无法停止。
所以我需要获取运行环境本身的详细信息。
提前致谢。
I want to know what functions are being called and what time each request is taking for an application which is running on apache.
Is there any tool or any other way where i can get this data.
I also want to know how much time each function is taking.
The application is running it cannot be stopped.
So i need to get the details in the running environment itself.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最常用的行业工具之一是: http://www.xdebug.org/
我用过它虔诚地已经很长一段时间了!它的首页执行以下操作:
“Xdebug 扩展通过提供大量有价值的调试信息来帮助您调试脚本。Xdebug 可以提供的调试信息包括以下内容:
One of the most used industry tools for this is: http://www.xdebug.org/
I have used it religiously for a long time now! From it's front-page it does the following:
"The Xdebug extension helps you debugging your script by providing a lot of valuable debug information. The debug information that Xdebug can provide includes the following:
Xdebug 可以编写一个分析文件,您可以在kcachegrind 或 wincachegrind。
Xdebug can write a profiling file that you can analyze in kcachegrind or wincachegrind.
这取决于您想要主动还是被动分析。
New Relic 等被动工具在后台默默工作,收集有关所有内容的一些信息通过牺牲少量的计算资源来满足请求。这些通常包含有关整个服务器堆栈的更多信息。这些通常用于生产环境,这听起来正是您所需要的。
活动分析器用于开发,每个请求仅运行一次,专门收集有关您正在处理的应用程序部分的大量信息,但代价是性能大幅下降。最常见的 PHP 主动分析器可能是 Xdebug。
分析 Xdebug 数据的方法:
注意:如果您使用虚拟机、vagrant、docker 等,请确保将输出目录设置为可在虚拟机外部访问的共享卷,
例如
(php.ini)
xdebug.profiler_output_dir = "/project_root/tmp"
如果您使用 PHPStorm:
工具 >分析 Xdebug Profiler 快照...
对于那些在 MacOS:
使用 homebrew 安装 qcachegrind 和 AppViz
brew install qcachegrind
brew 安装 graphviz
然后从命令行运行它:
qcachegrind cachegrind.out.1394
或者运行 qcachegrind 并使用 GUI 导航器打开 xdebug 生成的 cachegrind 文件
It depends on whether you want active or passive profiling.
Passive tools such as New Relic work silently in the background and collect a little information about all requests by sacrificing a small amount of compute resources. These generally have more information regarding the entire server stack. These are typically used for production environments, which sounds like what you require.
Active profilers are used for development and will run just once per request, collecting a lot of information specifically about the part of the application you are working on at the cost of a large performance hit. The most common PHP active profiler is probably Xdebug.
Ways to analyse the data from Xdebug:
NOTE: If you use a virtual machine, vagrant, docker etc make sure you set the output dir to a shared volume, accessible outside of the virtual machine
e.g.
(php.ini)
xdebug.profiler_output_dir = "/project_root/tmp"
If you use PHPStorm:
Tools > Analyse Xdebug Profiler snapshot...
For those using Xdebug on MacOS:
Using homebrew install qcachegrind and AppViz
brew install qcachegrind
brew install graphviz
Then run it from command line:
qcachegrind cachegrind.out.1394
OR just run qcachegrind and open the cachegrind file generated by xdebug using the GUI navigator
有几个 PHP 分析工具,
例如
There are couple of PHP profiling tools,
such as