Training, Open Source computer languages

PerlPythonMySQLTclRubyC & C++LuaJavaTomcatPHPhttpdLinux

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Server overloading - turns out to be feof in PHP

From the manual page on feof:

Warning - If passed file pointer is not valid you may get an infinite loop, because EOF fails to return TRUE.

From a script on our server:

while (1) {
  $nlines ++;
  $line = fgets($fh,1024);
  if (feof($fh)) break;


OOps! ... the file that's being analysed is our spam log, which is hard coded into the page that draws an email graph. And the slight (!) problem with the code above is that now that we have separated our email server from our web server, there is no such file.

Our new web server has been running fine ... except ... that occasionally and inexplicably, it has "maxed out" for a few minutes. And it was very hard to find (across many thousand pages!) what was happening. In the end, a top report showed me that we had one or two httpd threads grabbing all the cpu resource at 'event' time ... and a Perl script run against the log file to report only on the slowly served pages:

open (FH,"access_log");
$osid = 0;
while (<FH>) {
  $l++;
  ($h, $m, $s) = /(\d\d):(\d\d):(\d\d)/;
  $sid =$s + 60*$m + 3600 * $h;
  if ($osid) {
    $moved = $sid - $osid;
    if ($moved < -10) {
      print "$l ";
      print;
    }
  }
  $osid = $sid;
}


gave me the clue. (Isn't Perl a marvellous tool - even when helping debug PHP!)
(written 2008-09-01 02:31:00)

 
Associated topics are indexed under
H109 - PHP - Input / Output
A606 - Web Application Deployment - Apache - log files and log file tools

Back to
Injection Attacks - avoiding them in your PHP
Previous and next
or
Horse's mouth home
Forward to
Reception
Some other Articles
Global - Tcl, PHP, Python
Think before you send
Calling procs in Tcl and how it compares to Perl
Reception
Server overloading - turns out to be feof in PHP
Injection Attacks - avoiding them in your PHP
Pointing all the web pages in a directory at a database
The Rise and Rise of First Bus Fares
Does fruit and veg drag on?
Easterholic
1891 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

© WELL HOUSE CONSULTANTS LTD., 2008: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 0800 043 8225 or 01225 708225 • FAX: 0845 8382 405 or 01225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho