$fh = fopen('data.txt');
while ($line = fgets($fh)) {
preg_match(...,$line); ...
}
fclose($fh);
far as i know this chunks the text file on a per line basis. if not
fopen('data.txt',4096); chunks its
On Jan 7, 1:10 pm, Michael <[email protected]> wrote:
> Now that I have the other problem fixed I want to revisit the issue of large
> file handling -
>
> This is the code (placed within an array loop) -
> ----------------------------------
> // Determine MIME type:
> $mt=MIME_Type::autoDetect("$filename");
>
> // If suitable MIME type open, read and process:
> if (substr($mt,0,4) == "text") {
>
> // read the file:
> $content = file_get_contents($filename,FILE_TEXT);
>
> // extract the information:
> preg_match_all($pattern,$content,$matches);
>
> // add it to our array:
> foreach($matches[0] as $m) $results[] = $m;
>
> // unset the temporary array:
> unset($matches);
>
> // count valid file(s) scanned:
> $pv = $pv + 1;
>
> }; // end the MIME type statement
>
> ------------------------------------
> What is happening is that when I try and read a 1.9Gb text file, it fails,
> with the following error message:
> Scanning files:
> Fatal error: Allowed memory size of 805306368 bytes exhausted (tried to
> allocate 2023554020 bytes) in /www/scan.php on line 124
>
> Now the fix is probably pretty straight forward - does anyone have any idea
> please?
>
> Thanks in anticipation,
>
> Michael
--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]
-~----------~----~----~----~------~----~------~--~---