在 Ubuntu 中使用 Xdebug2 的分析数据调试 PHP
我的问题是基于这篇文章。
如何通过 Xdubug2 制作有关 PHP 代码的分析数据,然后将其放入 KCacheGrind 这样的应用程序?
我已经在 Ubuntu 中成功使用了 Xdebug,因为它在浏览器中突出显示了我的错误消息。 但是,我还没有找到像xdebug
这样的终端工具。
我想要像这样的 PHP 代码的可视化视图
My question is based on this article.
How can you make the profiling data about a PHP code by Xdubug2 and then put it to an app like KCacheGrind?
I have used successfully Xdebug in my Ubuntu, since it highlights my error messages in the browser. However, I have not find any terminal tool like xdebug
.
I would like to have a visual view of my PHP code like this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看 WebGrind (http://code.google.com/p/webgrind/)
Take a look at WebGrind (http://code.google.com/p/webgrind/)
将此行添加到您的 php.ini
xdebug.profiler_enable = 1
然后,如果您碰巧通过 Web 服务器运行 PHP,则需要重新启动 Web 服务器,否则不会应用conf 更改。
如果您通过 cli 运行 PHP,那么当然不需要重新启动。
现在,当您运行 PHP 脚本时,会在 xdebug.profiler_output_dir php.ini 设置指定的目录中创建一个 cachegrind.out.PID 文件。 默认为/tmp。
该文件是 kcachegrind 能够加载的文件。
还有其他方法可以调用此配置文件生成,您可以在 http://www. xdebug.org/docs/all_settings#profiler_enable
Add this line to your php.ini
xdebug.profiler_enable = 1
Then, if you happen to run PHP through a webserver you need to restart the webserver, otherwise the conf change is not picked up.
If you are running PHP through cli, then of course no restart is necessary.
Now, when you run your PHP script, a cachegrind.out.PID file is created in the directory specified by xdebug.profiler_output_dir php.ini setting. It is /tmp by default.
That files is the one kcachegrind is able to load.
There are other means to invoke this profile generation, you can read about them at http://www.xdebug.org/docs/all_settings#profiler_enable
我遇到了类似的情况,我只能访问终端,而无法访问要测试的可视环境。 更糟糕的是,我使用的是 Windows 机器和 Putty。
可用的解决方案是
对我来说,答案是将 Cachegrind 文件 SCP 到我的本地 Windows 计算机上,并使用 WinCachegrind 查看它们。 您可以将它们 SCP 到您的 Linux 机器上并在文件上运行 KCacheGrind。 这样做的缺点是您可能没有相同的文件结构,因此您将无法查看源代码。 如果您的本地计算机上也有源代码,或者可以在那里获取源代码,那么您也可以解决此问题。 在 vim(或其他编辑器)中打开 Cachegrind 文件,然后执行全局搜索并替换路径,将它们更改为本地计算机上的正确源路径。
我希望这就是您正在寻找的。
编辑以解决评论:
如果您正在努力获取略有不同的 callgrind 文件。 为此,您需要在 Linux 中运行(我认为您就是这样)并拥有可用的 callgrind 和 valgrind 程序。 这里最后要假设的是,您正在将 PHP 作为 Apache mod 运行,而不是以其他方式运行。 在apache启动时使用callgrind工具,然后在浏览器中运行请求。 这不仅会为您提供有关 php 调用树的详细信息,还会为您提供有关 Apache 中可能造成问题的许多内容的详细信息。
这是一个示例
-X 将以调试模式启动 apache,只有一个线程。 从这里打开 Web 浏览器并点击您想要的 php 脚本。 然后返回并关闭 apache。 这也应该结束 callgrind 解析。
如果您不需要 apache 或 Web 浏览器,您可以尝试仅使用 php 命令运行 callgrind ,
这应该会给您相同的结果,但不需要所有 apache 的东西。
I ran into a similar situation where I only had access to a terminal and not visual environment on which to test. Even worse, I was using a windows machine and Putty.
The solutions available are
For me the answer was to SCP the cachegrind files onto my local windows machine, and using WinCachegrind to look at them. You could SCP them onto your linux box and run KCacheGrind on the files. The downside to this, is that you may not have the same file structure, so you won't be able to view the sourcecode. If you have the source also on your local machine, or can get it there, you can fix this too. Open up the cachegrind files in vim (or other editor) and do a global search and replace on the paths to change them to the correct source path on your local machine.
I hope this is what you were looking for.
EDIT to address comment:
If you are working to get a callgrind file that is somewhat different. For this, you need to be running in Linux (which I think you are) and have the callgrind and valgrind programs available. The last thing to assume here is that you are running PHP as an Apache mod and not in some other fashion. Use the callgrind tool against the starting of apache and then run the request in the browser. This will give you detailed information not only on the php call tree, but also on many things in Apache that may be causing trouble.
here is an example of the
The -X will start apache in debug mode with only one thread. From here open a web browser and hit the php script you want. Then go back and shutdown apache. This should also end the callgrind parse.
If you do not need apache or a web browser, you can try running callgrind with just the php command
That should give you the same results but without all the apache stuff.