Search code examples
phpprofiling

Simple PHP Profiler for a live site?


I've a live website, where i want to have an option like PHP profiler which executes only on request (i.e when adding a param to the url like ?_profiler=on).

I know that running complete profiler on a live site is damn ugly thing, but i would like to check which functions are taking time while executing.

Just i need is whenever a function inside a class (action) is called, i need to register the start time and end time when the function completed and calculate the total time it took.

I'm looking for a simple PHP profiler such that i can include the base library class and just initiate the profiler instance in the controller, in turn which will look automatically for every function call inside the action and update the time taken.

Did anybody knows such kind of PHP profilers? Please help to find out or can anybody give me an idea how that can be done?


Solution

  • I use XDebug profiler with following options in php.ini (or php.d/xdebug.ini):

    xdebug.profiler_enable=0
    xdebug.profiler_enable_trigger=1
    

    It means that the profiler is disable by default but when you add "?XDEBUG_PROFILER" to your get query (eg. site.com/page?XDEBUG_PROFILE) then xdebug starts profiling and creates appropraite log files. You can specify place where they will be placed with xdebug.profiler_output_dir option.

    Then you can use some web frontend app to parse xdebug log files. The nice one is:

    http://code.google.com/p/webgrind/

    You need install it on your web server. It's basing on xdebug.profiler_output_dir option and automatically gets logs files.