Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profile slow PHP pages in production

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 the 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 I don't really want to install that again.

like image 471
Noodles Avatar asked Oct 28 '10 03:10

Noodles


2 Answers

You might alter your Apache/HTTP Server logs to record the time spent serving each request. Follow this guide for example. Then you can gather data for how long each request takes, identify the slow pages/requests and use XDebug or WebGrind to further analyse the causes.

Easy, and no great drain on your production server.

like image 59
Ghostpsalm Avatar answered Oct 14 '22 02:10

Ghostpsalm


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

like image 30
Petah Avatar answered Oct 14 '22 02:10

Petah