简体   繁体   English

如何查找PHP应用程序中调用过函数的次数和位置?

[英]How can I find how many times, and where, a function has been called in a PHP application?

I have a large PHP application that has been maintained by multiple teams for over a decade, and as such, the app has been through several update iterations as PHP has evolved over the years. 我有一个大型的PHP应用程序,已经由多个团队维护了十多年,因此,随着这些年来PHP的发展,该应用程序已经经历了几次更新迭代。

I know I can call get_defined_functions() which will give me a list of all internal php functions as well as user defined functions, which is very helpful. 我知道我可以调用get_defined_functions(),这会给我所有内部php函数以及用户定义函数的列表,这非常有帮助。

The problem is I don't know how to see how often, or where, each function is being used. 问题是我不知道如何查看每个函数的使用频率或频率。

Ultimately, I would like to have a function that works like get_defined_functions but goes a step farther in not only showing the defined function but also showing how many times it has been used as well as in what file I can find it. 最终,我希望有一个功能类似于get_defined_functions的功能,但不仅要显示已定义的函数,还要显示已使用了多少次以及可以在哪个文件中找到它,这更进一步。 (The search needs to be application wide, meaning I point it at the top level directory and it finds each occurrence through the 1000s of files that make up the application.) (搜索需要在整个应用程序范围内进行,这意味着我将其指向顶级目录,并通过构成该应用程序的1000多个文件来查找每次出现的情况。)

How can I do this? 我怎样才能做到这一点? Just want to make sure a solution doesn't already exist, either programmatically or through a tool, before I dive into writing a lot of complicated code to search through these files. 在我开始编写大量复杂的代码来搜索这些文件之前,只想确保以编程方式或通过工具都不存在解决方案。

It sounds like you need something that records every function invocation and then analyze call statistics. 听起来您需要一些东西来记录每个函数调用,然后分析调用统计信息。

Xdebug can do the first, yet it will slow down your application significantly, and then you can supply generated cachegring files to the Webgring or KCacheGrind to see what's going on. Xdebug可以先做,但是会大大降低您的应用程序的速度,然后您可以将生成的cachegring文件提供给Webgring或KCacheGrind,以查看发生了什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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