Forgive me if this is a noob question but I am at something of a loss. I've only just started working with php (installed in on my local pc along with an apache webserver on good friday in fact) and ive been trying to write a small script to search through some specific text files and return the result of the search as html. If worked fine on my local setup but when I upload it to my website to run I get the following error:
Fatal error: Allowed memory size of 20971520 bytes exhausted (tried to allocate 20387808 bytes)
Now this seems to occur within the folloiwing code segment:
Code: Select all
if($counter=="0") {
$lines = file('./file1.txt');
}
elseif ($counter=="1") {
$lines = file('./file2.txt');
}
else
{
$lines = file('./file3.txt');
}I reckon 60Mb is too high however (and in any case I plan on adding more files as I get my head around this - so i guess that limit will have to go through the roof). I'm guessing that for every instance of the file () function memory is being allocated, and more memory is then allocated to store the contents in the array $lines?
Currently file1.txt is 9mb, file2.txt is 20mb, and file3.txt is 8mb. The error occurs when its processing the 20mb file2.txt.
Any suggestions would be much appreciated thanks, bearing in mind i am trying to load the contents of the file into an array .