Trace where code is coming from (PHP)

前端 未结 5 1692
北恋
北恋 2021-02-04 21:07

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

相关标签:
5条回答
  • 2021-02-04 21:11

    phptrace is an awesome and simple tool to trace php code executions, you can have a try.

    0 讨论(0)
  • 2021-02-04 21:24

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

    Resources:

    • 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

    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.

    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 file output:

    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]
    
    0 讨论(0)
  • 2021-02-04 21:28

    You can also use the apd extension; this will write a file for each request containing a log of what PHP functions were called during the request.

    0 讨论(0)
  • 2021-02-04 21:29

    To trace the origin of a specific function, you can do this:

    $reflFunc = new ReflectionFunction('function_name');
    print $reflFunc->getFileName() . ':' . $reflFunc->getStartLine();
    

    See How to find out where a function is defined?

    To trace the origin of a specific class, you can do this:

    $reflClass = new ReflectionClass('class_name');
    print $reflClass->getFileName() . ':' . $reflClass->getStartLine();
    

    To get a list of all the includes that went into making a page, you can do this:

    var_dump(get_included_files());
    

    To get a list of all the functions that are defined on a page, you can do this:

    var_dump(get_defined_functions());
    

    To get a list of all the user-defined functions on a page, you can do this:

    $defined_functions = get_defined_functions();
    var_dump($defined_functions["user"]);
    
    0 讨论(0)
  • 2021-02-04 21:38

    Check out the debug_backtrace function - this should always be available, even on production servers.

    0 讨论(0)
提交回复
热议问题