|
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 / OutputA606 - Web Application Deployment - Apache - log files and log file tools
Some other Articles
Global - Tcl, PHP, PythonThink before you sendCalling procs in Tcl and how it compares to PerlReceptionServer overloading - turns out to be feof in PHPInjection Attacks - avoiding them in your PHPPointing all the web pages in a directory at a databaseThe Rise and Rise of First Bus FaresDoes fruit and veg drag on?Easterholic
|
1889 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).
|
|