Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to search a huge text file for data?

Status
Not open for further replies.

pcxgamer

Technical User
Oct 23, 2002
5
US
I have been trying for days to get this to work but obviously PHP's filesystem is not one of my fortes.

The large text file I want to 'search' is the website's access log file which is quite huge.

So far I have tried:
Code:
<?php

//  I hope to isolate all instances of visits by search engine spiders
//  for example: googlebot / zyborg / slurp / etc
$fd = fopen( 'access.log', 'r' );
while( !feof($fd) )
{
  $buffer = fgets( $fd, 4096 );
  if( strstr(strtolower($buffer), 'googlebot') )
  {
    echo $buffer.&quot;<br />\n&quot;;
  }
}

fclose ($fd);

?>


Up to this point, I am already stuck; with even 1 day's worth of logs, this piece of code will time-out.

If you run the Apache Web Server on your win32 PC, you can find the access log (and view the sample data) file usually at:

Code:
c:\program files\apache group\apache\logs\access.log

unless, you've changed this path in httpd.conf....
 
Is the file opened ok? As it is now, you aren't doing any error checking whatsoever. I'd change the open line to
Code:
$fd = fopen('/path/to/access_log', 'r') or die(&quot;Couldn't open the file.&quot;);
//Daniel
 
Ok, I'm helping a friend with this problem so let me past on this info and I'll let you know what happens. Thanks
 
OK I checked it out and the file is opening ok but I looks like its timing out. The log file that its tring to open and serach is 47MB.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top