[英]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. 因此,我有一个包含许多不同文件的php应用程序,代码有些混乱。
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'. 我要做的是在服务器上安装该应用程序,短暂使用它,尝试覆盖此处单击的所有功能,然后以某种方式获取一条日志,显示“已使用这些php文件”或“已访问这些功能”。
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. 我知道1)可以通过编辑每个文件并在调用或包含该文件时写一些东西来完成2)可能有静态工具尝试遵循所有代码路径等。
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. 我对以上内容不感兴趣-我只需要一些东西,可能是php模块/调试器,我不确定,该日志记录了php请求/包含/运行的文件。 If specific functions can be traced too, even better. 如果也可以追踪特定功能,那就更好了。 But even just files would be awesome. 但是,即使只是文件也很棒。
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.ini中,设置auto_prepend_file指向包含以下内容的文件。
<?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. PHP的debug_backtrace()函数可用于获取脚本执行的完整跟踪,包括调用的函数和参数。 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. 如果您在脚本末尾调用此函数,并将输出记录到一个或多个文件中,则应该可以满足您的要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.