简体   繁体   中英

can I log which PHP files and/or functions are accessed while browsing an application on my server?

So I have a php application with lots of different files, the code is a bit of a mess.

What I want to do is install the application on my server, use it briefly, try to cover all functionality clicking here and there, and then get a log somehow that says 'these php files were used' or 'these functions were accessed'.

I don't care about function arguments, time needed, how many times each thing was called etc etc.

I just want to see if there are functions or at least whole files that are never called - so they are dead.

I know that 1) it could be possibly done by editing each file and writing something out when it is called or included 2) there may be static tools that try to follow all code paths etc.

I'm not interested in the above - i need just something, probably a php module/debugger I'm not sure, that logs which files are requested/included/run by php. If specific functions can be traced too, even better. But even just files would be awesome.

听起来好像您在寻找xdebug之类的调试器,特别是此功能和此功能跟踪

This is just to get a list of files that are in use. A debugger would be required to do a profiling of your project. Also reference this answer to a similar question.

The list of included files will be saved to a text file.

In your php.ini, set up auto_prepend_file to point to a file that contains the following.

<?php

function shutdown_file_output()
{
    file_put_contents( 'included_files.txt', implode( PHP_EOL, get_included_files() );
}

register_shutdown_function('shutdown_file_output');

PHP's debug_backtrace() function can be used to get a full trace of a script's execution, including called functions and arguments. If you place a call to this function at the end of your script and log the output to a file or files then that should accomplish what you're looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM