Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can i find out what PHP scripts take longest to load in Apache?

share|improve this question
add comment

5 Answers

There are a few ways to do this.

1: Enable mod_status on your webserver. This allows you to get an overview of how the apache server is behaving in general by browsing to /server-status/. Remember to limit access to this location:

ExtendedStatus on
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
Allow from 192.168.0.0/24
</Location>

2: Modify your LogFormat directive to add processing time. You can then associate URIs with response times:

LogFormat "%h %t \"%r\" %b sec:%T usec:%D

Will display remote ip, request date-time, request, bytes sent, seconds and microseconds.

3: For script memory size and script hit ratio, the administrative console that comes with Xcache is very good. Scripts with large class heirarchies can expand to many megs in memory.

4: Profiling your php scripts might help. If you want to focus on profiling a single script, Xdebug will certainly help. User Damien suggests a way. I would suggest logging your memory usage and also using microtime, but putting a threshold for logging onit, like so:

$THRESH = 2;

$profile = array();
$profile['start'] = microtime( true );
// stuff
$profile['end'] = microtime( true );
$profile['delta'] = $profile['end'] - $profile['start'];

if( $profile['delta'] >= $THRESH ) 
    error_log( __FILE__.": ".$profile['delta']." seconds " );

Adjusting the threshold keeps your logs a lot cleaner.

share|improve this answer
add comment

Run them with Apache JMeter.

Apache JMeter may be used to test performance both on static and dynamic resources (files, Servlets, Perl scripts, Java Objects, Data Bases and Queries, FTP Servers and more). It can be used to simulate a heavy load on a server, network or object to test its strength or to analyze overall performance under different load types. You can use it to make a graphical analysis of performance or to test your server/script/object behavior under heavy concurrent load.

share|improve this answer
add comment

Run your server logs through a report tool. A decent one should be able to tell you how long the average user takes to download each page. It should also show you min and max download time for each page and lots of other statistics.

share|improve this answer
1  
Chris, maybe you could list a handful of "decent" free reporting tools that work on apache logs? –  pbr Jan 9 '10 at 3:22
    
Chainsaw by Apache is the first that comes to mind. –  Chris Nava Jan 11 '10 at 15:42
add comment

Y Slow is one the way to find out performance of page load speed.

share|improve this answer
    
Y Slow is kind of lame, because you can only tell the page load time in the status bar and sometimes the load time doesn't even show up! You would have to manually write down all the load times. A log would be better. –  Brian T Hannan Feb 9 '10 at 23:47
add comment

Depending on your scrip(s) you can use the microtime function:

$stime = microtime();  
$stime = explode(" ",$stime);  
$stime = $stime[1] + $stime[0];  

//Some Code...

$mtime = microtime();  
$mtime = explode(" ",$mtime);  
$mtime = $mtime[1] + $mtime[0]; 

$totaltime = ($mtime - $stime);
echo $totaltime;

Put as much breaks as you need to find the faulty portion of code.
(But maybe this should have been a SO answer...)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.