简体   繁体   English

浏览服务器上的应用程序时,如何记录访问哪些PHP文件和/或功能?

[英]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. 但是,即使只是文件也很棒。

听起来好像您在寻找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.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.

相关问题 我可以从服务器发送可通过浏览器扩展程序访问的cookie吗? - Can I send a cookie from my server which can be accessed by a browser extension? 设置一个可以在我的手机上访问的php服务器 - Set up a php server that can be accessed on my phone 我的应用程序中哪些文件使Mysql查询日志条目变慢 - Which Files In My Application that Make Slow Mysql Query Log Entries 使用php浏览网络服务器上的文件 - Browsing the files on a webserver with php 在我的服务器上哪里可以找到 php-fpm.log 和 php-fpm.conf? - Where can I find php-fpm.log and php-fpm.conf on my server? 我可以使用 php myadmin 登录到我的 sql 服务器,但无法使用 php 登录 - I can log into my sql server using php myadmin, but cant login using php 如何使用PHP备份服务器文件将文件从服务器上传到Google云存储到Google服务器? - How can I upload files to google cloud storage from my server to google's server using PHP to backup my server files? 通过浏览器访问时,PHP无法从本地从其他服务器下载文件 - PHP can't download files from another server locally when accessed with browser 如何通过查看文件访问base.php函数? - How can I reach base.php functions via my view files? 使用php浏览本地目录和文件 - Browsing local directories and files with php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM