6
5
How can i find out what PHP scripts take longest to load in Apache?
6
5
How can i find out what PHP scripts take longest to load in Apache?
7
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"
This 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.
0
I am using this command to identify what is taking too long to respond:
$ w3m http://localhost/server-status | tee | grep "GET\|HEAD\|POST" | awk '{if ($6>15) print}'
0
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.
0
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.
0
Y Slow is one the way to find out performance of page load speed.
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 – 2010-02-09T23:47:00.937
0
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...)
2Chris, maybe you could list a handful of "decent" free reporting tools that work on apache logs? – pbr – 2010-01-09T03:22:34.267
Chainsaw by Apache is the first that comes to mind. – Chris Nava – 2010-01-11T15:42:12.943