分析 PHP 代码
我想找到一种方法来确定 PHP 中每个函数以及 PHP 中每个文件的运行时间。 我有一个旧的 PHP 应用程序,我正在尝试找到其中的“粗糙点”,因此我想客观地找到哪些例程和页面需要很长时间才能加载。
是否有任何预制工具可以实现这一点,或者我是否坚持使用 microtime 并构建自己的分析框架?
I'd like to find a way to determine how long each function in PHP, and each file in PHP is taking to run. I've got an old legacy PHP application that I'm trying to find the "rough spots" in and so I'd like to locate which routines and pages are taking a very long time to load, objectively.
Are there any pre-made tools that allow for this, or am I stuck using microtime, and building my own profiling framework?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
上周我实际上做了一些优化工作。 XDebug 确实是一条出路。
只需将其启用为扩展(由于某种原因,它无法在我的 Windows 机器上与 ze_extension 一起使用),使用 xdebug.profiler_enable_trigger=On 设置 php.ini 并使用 XDEBUG_PROFILE=1 作为 get 或 post 调用普通网址变量来分析该请求。 没有什么比这更容易的了!
另外,我真的可以推荐 webgrind ,一个基于网络(php)的 google Summer Of Code 项目,可以读取并解析您的调试输出文件!
I have actually done some optimisation work last week. XDebug is indeed the way to go.
Just enable it as an extension (for some reason it wouldn't work with ze_extension on my windows machine) , setup your php.ini with xdebug.profiler_enable_trigger=On and call your normal urls with XDEBUG_PROFILE=1 as either a get or a post variable to profile that very request. There's nothing easier!
Also, i can really reccommend webgrind , a webbased (php) google Summer Of Code project that can read and parse your debug output files!
这是一个很好的提示。
当您使用 XDebug 来分析 PHP 时,请设置 profiler_trigger 并在书签中使用它来触发 XDebug 分析器;)
Here is a nice tip.
When you use XDebug to profile your PHP, set up the profiler_trigger and use this in a bookmarklet to trigger the XDebug profiler ;)
查看 xdebug,它允许进行深入的分析。 这里有关于如何使用 xdebug 的说明。
感谢 SchizoDuckie 的 提及 Webgrind< /a>. 这是我第一次听说。 非常有用(+1)。
否则,您可以在 Linux 上使用 kcachegrind 或其较小的衍生版本 wincachegrind。 这两个应用程序都会读取 xdebug 的分析器输出文件并对其进行总结,以供您查看。
take a look into xdebug, which allows in-depth profiling. And here's an explanation of how to use xdebug.
Kudos to SchizoDuckie for mentioning Webgrind. This is the first I've heard of it. Very useful (+1).
Otherwise, you can use kcachegrind on linux or its lesser derivative wincachegrind. Both of those apps will read xdebug's profiler output files and summarize them for your viewing pleasure.
我曾经看过 Zend Core 的截屏视频。 看起来不错,但实际上要花钱,我不知道这对你来说是否是一个问题。
I once saw a screen-cast for Zend Core. Looks pretty good, but it actually costs money, I don't know if that's an issue for you.
XDebug 很好,但在我看来,它的使用或设置并不容易。
Zend Studio 内置的分析器非常易于使用。 您只需点击浏览器工具栏上的按钮,然后BAM您就拥有了代码配置文件。 ts 可能不如 CacheGrind 转储那么深入,但它对我来说总是足够好。
您确实还需要设置 Zend Platform,但这对于开发使用来说非常简单且免费 - 但您仍然需要支付 Zend Studio 许可证的费用。
XDebug is nice but its not that easy to use or setup IMO.
The profiler built into Zend Studio is very easy to use. You just hit a button on a browser toolbar and BAM you have your code profile. ts perhaps not as indepth as a CacheGrind dump, but its always been good enough for me.
You do need to setup Zend Platform too, but thats straightforward and free for development use - you'd still have to pay for the Zend Studio licence though.
如果您安装了 xdebug 扩展,您可以将其设置为导出运行配置文件,您可以在 WinCacheGrind(在 Windows 上)中读取该配置文件。 我不记得在 Linux 上读取文件的应用程序的名称。
If you install the xdebug extension you can set it up to export run profiles, that you can read in WinCacheGrind (on Windows). I can't recall the name of the app that reads the files on Linux.
xdebug 的分析功能非常好。 如果你让它以 valgrind 格式保存输出,那么你可以使用 KCachegrind 或 Wincachegrind 之类的东西来查看调用图,如果你是一个视觉型的人,那么你可以更轻松地弄清楚发生了什么。
xdebug's profiling functions are pretty good. If you get it to save the output in valgrind-format, you can then use something like KCachegrind or Wincachegrind to view the call-graph and, if you're a visual kind of person, work out more easily what's happening.
除了具有非常强大的实时调试功能之外,NuSphere (www.nusphere.com) 的 PhpED 还具有内置分析器,只需从 IDE 内部单击即可运行。
In addition to having seriously powerful real-time debugging capabilities, PhpED from NuSphere (www.nusphere.com) has a built-in profiler that can be run with a single click from inside the IDE.
最简单的解决方案是使用 Zend Profiler,您不需要使用 Zend Platform,您可以直接从浏览器运行它,它非常准确并且具有您需要的最多功能,并且它集成在 Zend Studio 中
The easiest solution is to use Zend Profiler, you don't need Zend Platform to use is, you can run it directly from your browser, it's quite accurate and has the most features you need and it's integrated in the Zend Studio