Is there any way to know how many times the function has been called?

Asked

Viewed 266 times

1

I wonder if in PHP there is any way to find out how many times a certain function has been called.

I speak natively as I would also like to do this check for native functions.

Example:

 var_dump($_POST); 

 var_dump($_GET);

 get_function_called_number('var_dump'); // int(2)

To satistazer only to the requirements of the question, I will already demonstrate in the question that I know how to do this for functions that I created.

Thus:

function call_me()
{
    static $count = 0;
    $count++;

    var_dump($count);
}

call_me(); // imprime int(1)

call_me(); // imprime int(2)

But I would like a solution to know about the native functions.

  • 2

    I never saw it, but it would be of great use! D

  • In fact, all you want is a profiler (see Xdebug + kcachegrind): http://xdebug.org/docs/profiler

1 answer

0

There is a native function called debug_backtrace()

With the result returned by this function, you can get the information you need.

Otherwise, you would have to create a custom control. Such control is feasible only with the use of OOP.

An example of control is identifying calls within an autoloader. However, this does not control native functions. To control them you would have to create aliases and avoid calling them directly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.