PHP slow page profile in production

Is there a way to profile only slow PHP pages on a production server?

We are currently writing slow pages to a text file, but without additional information it’s hard to say why they are slow (not always slow).

I have used the Xdebug profiler before, but I really do not want to enable this on our production servers, since we will probably receive 100 requests per second. I also used the Zend Platform , but I really do not want to install it again.

+6
performance profiling php
source share
5 answers

You can modify your Apache / HTTP Server logs to record the time taken to service each request. For example, this guide . You can then collect data on the duration of each request, identify slow pages / requests, and use XDebug or WebGrind to further analyze the reasons.

Simplicity and lack of a big leak on your production server.

+3
source share

You could write timer instructions, these are parts of slow pages to narrow it down. Then, as soon as some data is created, 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 this out: http://particletree.com/features/php-quick-profiler/

It can meet your needs.

+2
source share

I would name a new library for the production server. When I debug, I like to use the * auto_prepend_file * and * auto_append_file * directives in php.ini. You can easily do as suggested above using this method and get a very accurate time for each page load.

If you are concerned only with slow download pages, measured in seconds, here is a quick and dirty solution that subtracts the server request time from the approximate end time in the file with the addition automatically. Then you can save the result in db or flat file.

e.g. 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 */ } 
0
source share

I suggest you take a look at the webgrind project . You can activate profiling for each request, which may allow you to profile data from your production server without a huge impact on performance.

I hope this helps you

0
source share

I know this is not the best solution, but ...

You can create a helper class to register each process that you have, as well as the start and end times. I know that you already do this for the whole process, but for each start and end function you can add "Profiler :: logtime ( FUNC )";

0
source share

All Articles