Allowed memory size of 134217728 bytes exhausted (tried to allocate 24 bytes)

Ido picture Ido · Mar 3, 2017 · Viewed 8.9k times · Source

I'm trying to create a Java file using a PHP script, but for some reason, whenever I run this script I get the following error on the screen:

Fatal error: Allowed memory of 134217728 bytes exhausted (tried to allocate 24 bytes) in C:\filepath\file.php on line 88

This is the code block with line 88:

$var1 = explode(".", $filenamee);
$var2 = explode(".", $folder);

$filename = "extfiles/".$var2[0]."/".$var1[0].".java";
$file = fopen($filename, "c");
$lines_array = array();
while (!feof($file)) {


    $line = fgets($file);
    array_push($lines_array, $line); // This is line 88

}

I tried to change the memory limit in php.ini from 128MB to 512MB, but that didn't work. I also tried to set memory limit on the code by using this:

ini_set('memory_limit', '512MB');

But that didn't work either.

What can I do to fix this?

Answer

Axel picture Axel · Mar 3, 2017

Please read the documentation:

Warning

If the passed file pointer is not valid you may get an infinite loop, because feof() fails to return TRUE.

Make sure your file pointer is valid, and pass "r" (= reading) for mode.