I had a couple of reports recently about web pages from our site being a little slow to load, and my independent spy tells me that they're not bad, but not the world's fastest either. And a little thought lead me to conclude that could be because of the various PHP scripting elements included at the front of each page.
How should I investigate this? I have added in a whole array of
microtime(); captures at strategic points in the included code ... like
$timer[14] = microtime();
and I have added a labelling array too:
$tabo[14] = "Starting top of page preps";
And I have added an extra page in which uses the included code, producing an elapsed time analysis - loop code like
foreach (array_keys($timer) as $subs) {
list($ins,$outs) = explode(" ",$timer[$subs]);
# Normalise to second to retain accuracy
if ($oldout == 0) $oldout = $outs;
$elt = ($outs-$oldout) + $ins;
# Format time difference
$newelt = sprintf("%.4f",$elt - $oldelt);
$oldelt = $elt;
print "$elt<br>";
}
Suddenly ... from a black hole which holds the server response for around a second, a series of timings is revealed which gives the "game" away as to where it's worth looking at the efficiency. You can see how my test page runs
here and compare it one I did during testing that started like this:
0 0.34967100 1212773196 .
1 0.34970500 1212773196 (0.0000) initialised page script.
2 0.35110600 1212773196 (0.0014) processed whcstd.
3 0.35263500 1212773196 (0.0015) processed webhelpers2.
4 0.23460400 1212773198 (1.8820) processed login.
5 0.23563200 1212773198 (0.0010) processed hotel.
6 0.23650700 1212773198 (0.0009) processed booking.
7 0.23667900 1212773198 (0.0002) recovered booking session.
8 0.23894900 1212773198 (0.0023) set up courses and calendars.
9 0.23900200 1212773198 (0.0001) 4 layer - preprocessor for special cases.
10 0.23907100 1212773198 (0.0001) 4 layer - finish previous page.
11 0.23945500 1212773198 (0.0004) 4 layer - prepare next page.
12 0.24002300 1212773198 (0.0006) 4 layer - Fill in page variables into template.
14 0.24747000 1212773198 (0.0074) Starting top of page preps.
15 0.24776500 1212773198 (0.0003) Connected to database and handled 'navigation on'.
16 0.59276600 1212773198 (0.3450) DDA preference, country, languages handled.
17 0.59296500 1212773198 (0.0002) Identifying browser string.
18 0.41007200 1212773200 (1.8171) Throttling back systems doing a denial of service.
19 0.41257100 1212773200 (0.0025) Recent history database tidied.
20 0.10485400 1212773201 (0.6923) 'See Also' links evaluated.
21 0.21190500 1212773201 (0.1071) User Comments handled.
22 0.21242300 1212773201 (0.0005) Course Price table loaded.
23 0.21324600 1212773201 (0.0008) User's language preference logged.
24 0.21483800 1212773201 (0.0016) Country identified and output tailored.
25 0.21498100 1212773201 (0.0001) Side image and world zone set.
26 0.21500600 1212773201 (0.0000) Top image and data mine set up for Google arrivals.
27 0.21505800 1212773201 (0.0001) Back links calculated.
28 0.21510800 1212773201 (0.0000) Amazon referrals handled.
29 0.21544600 1212773201 (0.0003) Changes to user preferences saved.
(written 2008-06-06, updated 2008-06-07)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
H312 - PHP - Tips and Techniques [789] Hot answers in PHP - (2006-07-02)
[917] Syntax checking in PHP - (2006-11-07)
[1010] Dates, times, clickable diarys in PHP - (2006-12-28)
[1270] PHP Standalone - keyboard to screen - (2007-07-18)
[1649] Easy conversion - image formats, currencies and distances - (2008-05-21)
[1684] Two PHP include files to make easy web site indexing and navigation - (2008-06-21)
[1958] PHP - Parse error: syntax error, unexpected $end ... - (2008-12-23)
[1983] Keeping PHP code in database and running it - (2009-01-09)
[2025] Injection Attack if register_globals in on - PHP - (2009-02-04)
[2274] PHP preg functions - examples and comparision - (2009-07-08)
[2478] How did I do THAT? - (2009-10-26)
[2981] How to set up short and meaningfull alternative URLs - (2010-10-02)
[4074] A comment on comments in PHP - (2013-04-28)
[4310] Problem ... I want to print a series of numbered forms - (2014-10-05)
[4319] PHP - some quick fixes if scripts have issues, and how to use our support - (2014-11-19)
[4426] FileMaker Day to Unix Time conversion - (2015-02-15)
[4621] The power of scripting - (2016-01-12)
H114 - Sourcing, installing and configuring PHP [192] Current MySQL and PHP paths and upgrades - (2005-01-28)
[316] Development Environments - (2005-05-19)
[481] PHP upgrade - traps to watch - (2005-10-31)
[934] Clustering, load balancing, mod_rewrite and mod_proxy - (2006-11-21)
[1688] cannot restore segment prot after reloc message - PHP / httpd - (2008-06-26)
[1731] Apache httpd, MySQL, PHP - installation procedure - (2008-08-01)
[1768] What is built in to this httpd and PHP? - (2008-08-23)
[1936] Quick Summary - PHP installation - (2008-12-12)
[2317] How to make a Risotto (PHP build style) - (2009-08-02)
[2433] Controlling, supressing, enabling PHP error messages - (2009-10-02)
[2589] Your PHP code does not work? Here is where to start looking. - (2010-01-18)
[2646] Compile but do not run PHP - syntax check only - (2010-02-22)
[3132] Virtual Hosting with Apache http server - an overall scheme, and avoiding common pitfalls - (2011-01-14)
[3635] Parse error: parse error, unexpected T_STRING on brand new web site - why? - (2012-03-03)
[3955] Building up from a small PHP setup to an enterprise one - (2012-12-16)
[4437] Adding a PHP build option, rotating an image based on camera data, and a new look at thumbnails in PHP - (2015-02-22)
Some other Articles
Compiling C programs with gcc - an overviewDynamic Memory Allocation in CWhat are Unions (C programming)Talk on TransWilts train service to Green PartyChecking server performance for PHP generated pagesSlow boot and terminal start on Linux boxesFactory method example - PerlExample of OO in PerlPython in an afternoon - a lecture for experienced programmersWestonbirt Arboretum Postcode