views:

28

answers:

2

Is there a way of profiling only slow php pages on a production server? At the moment we're logging slow pages to a text file, but without more information it's hard to say why they're slow (not consistently slow).

I've used XDEBUG profiler before, but I really don't want to enable this on our production servers as we are likely to get 100's of requests per second. I've also used Zend Platform, but don't really want to install that again.

Thanks

A: 

You could write timer statements are parts of the slow pages to narrow it down. Then once some data is built up, rinse and repeat.

define('START_TIME', microtime(true));
function timer() {
    static $last;
    $time_since_start = microtime(true) - START_TIME;
    $time_since_last = microtime(true) - $last;
    // Do something with $time vars
    $last = microtime(true);
}

Also check out this: http://particletree.com/features/php-quick-profiler/

It might suit your needs

Petah
PQP looks nice and pretty, but it doesn't really give me the detail I was after. Thanks anyway.
Noodles
A: 

I'd be leery of of a whole new library for a production server. When I'm debugging I like to use the *auto_prepend_file* and *auto_append_file* directives in php.ini. You could easily do as suggested above with this method and get a very exact time for each page load.

If you are worried about only slow load pages measured in seconds, here is a quick and dirty solution that subtracts the server request time from approximate finish time in an auto-appended file. You can then store the result in a db or flat file.

eg in php.in

auto_append_file = [location]/my_timer.php

my_timer.php

define('TRIGGER_TIME_LOG','3'); // Minimum number of timer seconds to log page load 

$time = time() - $_SERVER['REQUEST_TIME']; // Page load time

if($time >= TRIGGER_TIME_LOG)
{
  /*
   * DO LOGGING TO DB OR FLAT FILE HERE
   */
}
DrPerdix
As I said we're already logging slow pages, I just need more detail (like which functions are slow).
Noodles
Sorry, I misunderstood.
DrPerdix