-2

How do I identify which PHP files are causing load when the script is executing a main.php file and the said file calls 100s of .php files.

My server administrator says that he cannot identify the .php files causing load as its a single php file which is running. And this file makes further calls to other php files.

So he see only one php file which is the main.php file.

So i am stuck, need help from the experts like you!

EM-Creations
  • 4,195
  • 4
  • 40
  • 56
  • What about a counter in the main.php file, just echo the microtime after each include, and you have your solution. – Green Black Feb 05 '13 at 17:03
  • 1
    dupe: http://stackoverflow.com/questions/21133/simplest-way-to-profile-a-php-script Look at those up vote numbers ;) – ficuscr Feb 05 '13 at 17:03
  • Take a look here: http://stackoverflow.com/questions/535020/tracking-the-script-execution-time-in-php Have good solutions. – Guerra Feb 05 '13 at 17:06

3 Answers3

2

Add this code before some of your code executes:

$start_time = microtime(TRUE);

Then add this after the code has executed:

$stop_time = microtime(TRUE);

The value for how long that part of your code took will be:

$time = $stop_time - $start_time;

Then write that $time variable to a log that you can view to figure out how long different parts of your specific code is taking.

2

Use a profiler tool.

There are several good ones, but the most common one to use is built into xDebug.

Install xDebug, set the config options to do profiling, and run your program.

This will create a profiler trace file, which you can load into a tool like KCacheGrind to see what parts of your program are taking the most time to run.

Full instructions as well as downloads are available from the xDebug site.

SDC
  • 14,192
  • 2
  • 35
  • 48
1

What you want to do is Profiling

You can do this easily using Xdebug extension. The doc is here http://www.xdebug.org/docs/profiler

You will have a nice table with all your functions and their execution time/memory usage.

Pierre Inglebert
  • 3,858
  • 1
  • 18
  • 22