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)
Associated topics are indexed under
A606 - Web Application Deployment - Apache httpd - log files and log tools [3984] 20 minutes in to our 15 minutes of fame - (2013-01-20)
[3974] TV show appearance - how does it effect your web site? - (2013-01-13)
[3670] Reading Google Analytics results, based on the relative populations of countries - (2012-03-24)
[3554] Learning more about our web site - and learning how to learn about yours - (2011-12-17)
[3491] Who is knocking at your web site door? Are you well set up to deal with allcomers? - (2011-10-21)
[3447] Needle in a haystack - finding the web server overload - (2011-09-18)
[3443] Getting more log information from the Apache http web server - (2011-09-16)
[3087] Making the most of critical emails - reading behind the scene - (2010-12-16)
[3027] Server logs - drawing a graph of gathered data - (2010-11-03)
[3019] Apache httpd Server Status - monitoring your server - (2010-10-28)
[3015] Logging the performance of the Apache httpd web server - (2010-10-25)
[1796] libwww-perl and Indy Library in your server logs? - (2008-09-13)
[1761] Logging Cookies with the Apache httpd web server - (2008-08-20)
[1656] Be careful of misreading server statistics - (2008-05-28)
[1598] Every link has two ends - fixing 404s at the recipient - (2008-04-02)
[1503] Web page (http) error status 405 - (2008-01-12)
[1237] What proportion of our web traffic is robots? - (2007-06-19)
[376] What brings people to my web site? - (2005-07-13)
H109 - PHP - Input / Output [3424] Divide 10000 by 17. Do you get 588.235294117647, 588.24 or 588? - Ruby and PHP - (2011-09-08)
[3159] Returning multiple values from a function call in various languages - a comparison - (2011-02-06)
[3029] PHP data sources - other web servers, large data flows, and the client (browser) - (2010-11-04)
[2964] An introduction to file handling in programs - buffering, standard in and out, and file handles - (2010-09-21)
[1442] Reading a file multiple times - file pointers - (2007-11-23)
[1113] File and URL reading in PHP - (2007-03-20)
[1096] Sample script - FTP to get a file from within PHP - (2007-03-01)
[1094] PHP fread - truncated data - (2007-02-27)
[997] Most recent file in a directory - PHP - (2006-12-18)
[709] Handling huge data files in PHP - (2006-05-04)
[653] Easy feed! - (2006-03-21)
[616] printf - a flawed but useful function - (2006-02-22)
[114] Relative or absolute milkman - (2004-11-10)
5680
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