跟踪代码来自何处 (PHP) [英] Trace where code is coming from (PHP)

查看:35
本文介绍了跟踪代码来自何处 (PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在浏览客户的服务器,运行疯狂的专有论坛软件 (vBulletin) 甚至更糟糕的 SEO mods (vbseo).我想不通找出页面的 php 代码来自哪里!如何追踪这个返回 PHP 页面的 URL:http://www.example.com/forum/members/connie.html我刚刚加入了一个项目,其代码基于带有 VBSEO 插件的经过大量修改的 vBullitin 安装.这个特殊的插件是可怕的意大利面条式代码,包含数十个 include()、.htaccess 重定向和可能的 .httpd.conf 更改.然后它从数据库中提取字符串,所以我什至无法使用 grep 来查找代码文件!

I'm going through a customer's server, running crazy proprietary forum software (vBulletin) and even worse SEO mods (vbseo). I cannot figure out where the php code for a page is coming from! How to trace this URL back to a PHP page: http://www.example.com/forum/members/connie.html I just joined a project with the code based on a heavily modified vBullitin install with the VBSEO plugin. This particular plugin is horrific spaghetti code with tens of include()s, .htaccess redirects and possibly .httpd.conf changes. Then it pulls strings from a database so I cannot even use grep to find the code file!

有什么方法可以堆栈跟踪 PHP 来记录运行以生成页面的所有代码?我有 root 访问权限,但我不应该停止或重新启动服务器.用于生成页面的文件的 include() 层次结构的简单列表就足够了.

Is there any way to stack-trace PHP to log all the code that runs to produce a page? I have root access but I am not supposed to stop or restart the server. A simple list of the include() hierarchy of files that went into producing the page would suffice.

请注意,我不能使用 debug_backtrace,因为我不知道我要查找的代码在哪里!debug_backtrace 函数与我需要的完全相反.

Note that I cannot use debug_backtrace because I don't know where the code I'm looking for is! The debug_backtrace function is the exact opposite of what I need.

谢谢.

推荐答案

听起来您需要使用 Xdebug.大多数常见的 IDE 都支持它,例如 NetbeansPHPStorm.

Sounds like you need to step through it with Xdebug. Most common IDE's support it such as Netbeans and PHPStorm.

资源:

  • Tracing PHP apps with Xdebug
  • Xdebug with Netbeans
  • Xdebug with PHPstorm (I recommend)
  • Xdebug with Eclipse
  • Chrome Xdebug extension (I recommend)
  • Firefox Xdebug plug-in

在上述两个 IDE 中,您可以 CTRL+单击一个函数/方法,它将带您到文件中定义它的行.您还可以跟踪函数和变量的使用情况.

In both the above mentioned IDE's, you can CTRL+Click a function/method and it will take you to the line in the file where it is defined. You can also track usages for both functions and variables.

跟踪代码内置于 xdebug 中.下面是 Zend 的一个例子:

Tracing code is built-in to xdebug. Here's an example from Zend:

<?php

  xdebug_start_trace('c:/data/fac.xt');

  print fac(7);

  function fac($x)
  {
    if (0 == $x) return 1;
    return $x * fac($x - 1);
  }

  xdebug_stop_trace();

?>

跟踪文件输出:

TRACE START [2007-10-26 12:18:48]
    0.0068      53384     -> fac() C:\www\fac.php:5
    0.0069      53584       -> fac() C:\www\fac.php:10
    0.0069      53840         -> fac() C:\www\fac.php:10
    0.0070      54096           -> fac() C:\www\fac.php:10
    0.0070      54376             -> fac() C:\www\fac.php:10
    0.0071      54656               -> fac() C:\www\fac.php:10
    0.0072      54936                 -> fac() C:\www\fac.php:10
    0.0072      55216                   -> fac() C:\www\fac.php:10
    0.0073      55392     -> xdebug_stop_trace() C:\www\fac.php:13
    0.0237      55392
TRACE END   [2007-10-26 12:18:48]

这篇关于跟踪代码来自何处 (PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆