Trace where the code comes from (PHP)

I go through the client server, run the crazy proprietary forum (vBulletin) and worse the SEO mods (vbseo). I can’t understand where the PHP code for the page comes from! How to trace this URL to a PHP page: http://www.example.com/forum/members/connie.html I just joined a project with code based on a heavily modified vBullitin installation with the VBSEO plugin. This particular plugin is awful spaghetti code with dozens of include () s, .htaccess redirects, and possibly changes to .httpd.conf. It then retrieves the rows from the database, so I can't even use grep to find the code file!

Is there a PHP stack trace method for registering all the code that is executed to create the page? I have root access, but I do not have to stop or restart the server. A simple list of the include () hierarchy for the files that started creating the page will suffice.

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

Thanks.

+4
source share
5 answers

Sounds like you need to go through Xdebug . The most common IDE support, such as Netbeans and PHPStorm .

Resources:

In both of the above IDEs, you can CTRL + click the / method function and it will take you to the line in the file where it is defined. You can also track the use of both functions and variables.

Trace code is built into xdebug. Here is 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] 
+4
source

Check debug_backtrace - it should always be available even on production servers.

+2
source

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.

+1
source

phptrace is a terrific and easy tool to track the execution of PHP code, you can try it.

+1
source

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

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

See How to determine where a function is defined?

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

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

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

 var_dump(get_included_files()); 

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

 var_dump(get_defined_functions()); 

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

 $defined_functions = get_defined_functions(); var_dump($defined_functions["user"]); 
0
source

Source: https://habr.com/ru/post/1369389/


All Articles