用于 Apache 之上的实时系统的 PHP Profiler
我在 Apache 服务器上有一个 PHP 网站,我想知道是否有工具和其他方法可以对其进行分析以查找代码瓶颈。 我需要知道哪些函数需要很长时间才能处理等等。
像 gprof 之类的东西,除了实时 apache 服务器上的 PHP 之外。
还有哪些其他方法可以查找 PHP 系统中的瓶颈。
I have a PHP website on a Apache server, and I would like to know if there are tools and other ways I can profile this to find bottlenecks on the code. What I need to know is what functions are taking long to process, etc.
Something like gprof, except for PHP on live apache server.
What are other ways to find bottlenecks in a PHP system.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
您可以使用 xdebug - 安装后您可以触发 以各种方式对请求进行分析,最终您会为每个请求提供一个 valgrind 格式的配置文件。 将其加载到 WinCacheGrind、KCacheGrind 或类似的工具并深入查找所有时间都花在哪里!
You can use xdebug - once installed you can trigger profiling of requests in a variety of ways, and you wind up with a valgrind format profile for each request. Load this in WinCacheGrind, KCacheGrind or similar and drill down to find where all the time is spent!
尝试 XDebug ( http://www.xdebug.org/ ),您可以使用 get-parameter 触发它在调试会话期间。 这将创建缓存研磨文件,您可以在 KCacheGrind 或 WinCacheGrind 中检查这些文件(第一个要好得多)...
Try XDebug ( http://www.xdebug.org/ ) you can trigger it with a get-parameter during your debugging-session. This will create cachegrind-files which you can check within KCacheGrind or WinCacheGrind (this first is much better)...
XHProf 就是为此用例而设计的。
XHProf(由 Facebook 于 2009 年开源)为 Facebook 的 XHProfLive——一个实时性能监控系统,提供来自生产层的功能级别洞察。
XHProf 文档的片段:
问候,
卡南·穆图卡鲁潘
XHProf was designed for this use case.
XHProf (open sourced by Facebook in 2009) powers Facebook's XHProfLive -- a real-time performance monitoring system that provides function level insights from production tiers.
A snippet from XHProf doc:
regards,
Kannan Muthukkaruppan
如果您有一个非常有针对性的区域需要查看,您可能需要尝试在代码周围散布这些内容:
if you have a very targeted area to look at, you may want to try sprinkling these around your code:
dtrace 实际上几乎为零开销,除非您启用数千个探测器
认为它也可以在 BSD 上使用
dtrace in fact has almost zero overhead unless you enable thousands of probes
think it is also available on the BSD's
我还要提一下Pinba
在我看来,它更适合多台服务器设置而不是仅一台服务器,但如果您的项目增长......
Let me also mention Pinba
In my opinion, it is more suitable for the multiple servers setup rather than for just one server, but in case your project grow..
您可以使用 phpdebug 来完成此工作。 这是一个 php 扩展。
You can use phpdebug for this job. It's a php extension.
我建议不要构建自己的分析器。 有几个免费的优秀分析器可以为您提供广泛的细节和易用性。 我认为你最好的时间投资是在以下组合中。 我们在我工作的网络开发公司使用这个,并且对此非常满意:
Zend Server PHP 堆栈:
您可以使用免费的社区版,并选择要安装堆栈的哪些部分。 我们只安装了 PHP 部分,并依赖 Linux 发行版中的 Apache 和 MySQL。 Zend Server 提供了一个调试器扩展、一个代码优化器(用于稍微提升速度)、一个字节码缓存(用于大幅提升速度)和一个用于管理 PHP 设置的漂亮 GUI。 商业版本提供了更多内容。 通过 RPM 或 DEB 软件包可以轻松在 Linux 中进行安装。
要使用调试器扩展,您需要一个 IDE:
安装 Zend Studio 这是一个优秀的 PHP IDE(查看功能页面),并且使调试和分析变得非常容易。 无需制作cachegrind 文件或其他多步骤过程,只需单击 Firefox 工具栏中的“配置文件”,Studio 就会开始分析该页面。 细节和易用性非常重要。
也许我听起来像一个 Zend 推销员,也许这听起来超出了您的需要,但我只是一个对他使用的工具非常满意的 PHP 开发人员。 我认为开始使用 Studio 是值得的,但这种组合使它变得很棒,而且 Server 甚至可以大大加快您的实时服务器的速度。 在我看来,这个组合是目前最好的 PHP 开发环境。 查看演示视频。 还有一个关于概要分析的内容。
I would suggest against building your own profiler. There are several excellent profilers freely available that will give you extensive detail and ease of use. I think your best time investment is in the following combination. We use this at the web developent company I work for, and are very pleased with it:
The Zend Server php stack:
You can use the free Community Edition, and choose which parts of the stack you want to install. We installed only the PHP part, and rely on the Apache and MySQL from the Linux distro. Zend Server provides a Debugger extension, a code optimizer (for a slight speed boost), a bytecode cache (for a substantial speed boost) and a nice GUI for managing PHP settings. The commercial version provides much more. Installation in Linux is easy via RPM or DEB packages.
To use the Debugger extension you need an IDE:
Install Zend Studio which is an excellent PHP IDE (check the features page), and makes debugging and profiling very easy. No need to make cachegrind files, or other multistep processes, but just click Profile in the toolbar in Firefox and Studio starts profiling that page. The detail and ease of use are huge.
Maybe I'm sounding like a Zend salesman, and maybe this sounds like more than you need, but I'm just a PHP developer who is very happy with the tools he uses. I think it's time well spent to start using Studio, but the combination makes it great and Server will even speed up your live server quite a bit. In my opinion this combo is simply the best PHP development environment currently available. Check out the demo videos. There's one on profiling too.
如果您在 OpenSolaris 上运行,请考虑 dtrace。 最大的优点可能是你还可以探索其他层,如 Apache、Mysql。
dtrace 的开销较低,您可以有选择地仅启用您想要监视的探测器。
If you are running on OpenSolaris, consider dtrace. The biggest advantage probably is that you can also probe into other layers like Apache, Mysql.
dtrace has low overhead and you can selectively enable only the probes that you want to monitor.