I've noticed recently that the response speed of this website hasn't been as brisk as I would have liked, and thought that the cause was a steady growth in the amount of code we run behind the scenes on each page - elements I particularly felt were culprits were identifying visitors to a country by their IP addresses, and the background booking system which I hope will be live within the next few months. Plans for these next few days included a couple of hours to look at each of these areas of concern and see if I could save a few cycles here and there, add in some caches, etc.
But then I have noticed that the occasional page that wasn't going through these areas was also running a little slower, and I started to investigate. The host we're using is a shared server and I have shell login ... and a few uses of the
uptime command convinced me that all was not as it should be; there seemed always to be more work that the c.p.u. could handle, and a similar test run on an identical machine on which I look after another site did not show similar overloading. So perhaps something to have a word with my ISP about?
This is one of those cautionary Christmas tales!. One last check before I wrote an "oy - what's going on" type email to the ISP ... I added in a series of 30 calls to PHP's
microtime function splattered throughout a sample page, saved them in an array and dumped them out at the end of the page (I don't expect anyone but me saw them - I can't imagine that may people will be looking for the
printable form of the Tk course description this morning! And what did I find?
That the elements I has suspected were only taking a few milliseconds; the real culprit was a MySQL database enquiry that searched 3 million records on a non-indexed field!. Solution - short term - clean up that table that, frankly, has a lot of old crud in it. Then add an index!!
And a 2 reminder lessons - firstly not to make assumptions, and secondly of just how useful a relatively crude tool like microtime can be!
You can click on that tk course link above if you like - it'll reveal out stats at the bottom. But you shouldn't see a jump of 5 seconds between stages 15 and 16 like I did this morning!
(written 2007-12-23 13:31:07)
Associated topics are indexed under
H115 - Designing PHP-Based Solutions: Best Practice [2430] Not just a PHP program - a good web application - (2009-09-29)
[2221] Adding a newsfeed for your users to a multipage PHP application - (2009-06-06)
[2199] Improving the structure of your early PHP programs - (2009-05-25)
[1794] Refactoring - a PHP demo becomes a production page - (2008-09-12)
[1694] Defensive coding techniques in PHP? - (2008-07-02)
[1623] PHP Techniques - a workshop - (2008-04-26)
[1533] Short and sweet and sticky - PHP form input - (2008-02-06)
[1490] Software to record day to day events and keep an action list - (2007-12-31)
[1487] Efficient PHP applications - framework and example - (2007-12-28)
[1391] Ordnance Survey Grid Reference to Latitude / Longitude - (2007-10-14)
[1390] Converting from postal address to latitude / longitude - (2007-10-13)
[1389] Controlling and labelling Google maps via PHP - (2007-10-13)
[1381] Using a MySQL database to control mod_rewrite via PHP - (2007-10-06)
[1323] Easy handling of errors in PHP - (2007-08-27)
[1321] Resetting session based tests in PHP - (2007-08-26)
[1194] Drawing hands on a clock face - PHP - (2007-05-19)
[1182] Painting a masterpiece in PHP - (2007-05-10)
[1181] Good Programming practise - where to initialise variables - (2007-05-09)
[1166] Back button - ensuring order are not submitted twice (PHP) - (2007-04-28)
[1052] Learning to write secure, maintainable PHP - (2007-01-25)
[1047] Maintainable code - some positive advice - (2007-01-21)
[945] Code quality counts - (2006-11-26)
[936] Global, Superglobal, Session variables - scope and persistance in PHP - (2006-11-21)
[896] PHP - good coding practise and sticky radio buttons - (2006-10-17)
[839] Reporting on the 10 largest files or 10 top scores - (2006-08-20)
[572] Giving the researcher power over database analysis - (2006-01-22)
[563] Merging pictures using PHP and GD - (2006-01-13)
[426] Robust checking of data entered by users - (2005-08-27)
[394] A year on - should we offer certified PHP courses - (2005-07-28)
[340] Code and code maintainance efficiency - (2005-06-08)
[261] Putting a form online - (2005-03-29)
[237] Crossfertilisation, PHP to Python - (2005-03-06)
[123] Short underground journeys and a PHP book - (2004-11-19)
H117 - Security in PHP [2025] Injection Attack if register_globals in on - PHP - (2009-02-04)
[1779] Injection Attacks - avoiding them in your PHP - (2008-08-31)
[1747] Who is watching you? - (2008-08-10)
[1679] PHP - Sanitised application principles for security and useability - (2008-06-16)
[1542] Are nasty programs looking for security holes on your server? - (2008-02-17)
[1396] Using PHP to upload images / Store on MySQL database - security questions - (2007-10-19)
[1387] Error logging to file not browser in PHP - (2007-10-11)
[1086] Injection attacks - safeguard your PHP scripts - (2007-02-20)
[947] What is an SQL injection attack? - (2006-11-27)
[920] A lion in a cage - PHP - (2006-11-10)
[345] Spotting a denial of service attack - (2005-06-12)
Some other Articles
Does anyone understand Lithuanian?Copyright and theft of images, bandwidth and members.A christmas messageWhat have hotels and bananas got in common?A story about benchmarking PHPThe Christmas LetterNext course - 7th January 2008, Regular ExpressionsFSB leaves its members feeling like mushroomsSome new C programming examples - files, structs, unions etcDecisions - small ones, or big ones?