Part 2 to the below - I have commented out the MIME type detection, and while 
it does speed the process up somewhat, it is still running too slow and still 
hits a massive slowdown after a few thousand files.
(FYI each file is about 10-20kb of text).

So there is something wrong and it isn't the MIME type detection....

-----------------------------------------
Ok. It is probably about time I posted the awlfully slow section of code for 
people to look at and state their opinions-

(Prior to this part the code has recursively scanned a directory and created 
an array with all the path / file names).

foreach ($files as $filename) {

// Determine MIME type: (This uses pear mime_type module)
$mt=MIME_Type::autoDetect("$filename");

// If suitable MIME type open, read and process: (ie: all text files)
if (substr($mt,0,4) == "text") {

// obtain filesize needed for fread():
$fs = filesize("$filename");

// open the file:
$thefile = fopen("$filename","rb");

// read the file:
$content = fread($thefile,$fs);

// extract the information: ($pattern is a previously defined PCRE regex)
preg_match_all($pattern,$content,$matches);

// add it to our array:
$results = array_merge($matches[0],$results);

// unset the temporary array:
unset($matches);

// close the file:
fclose($thefile);

// count valid file(s) scanned:
$pv = $pv + 1;

}; // end the MIME type statement

// count files(s) scanned:
$p1 = $p1 + 1;
$bar1->update($p1);

// count data scanned:
$fc = $fc + $fs;

}; // end loop:

--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to nzphpug@googlegroups.com
To unsubscribe, send email to
nzphpug+unsubscr...@googlegroups.com
-~----------~----~----~----~------~----~------~--~---

Reply via email to