Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 11 bytes) in

file_get_contents(BIG_FILE);

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 11 bytes) in


should I change a variable in php.ini
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

That depends.  How big a file are you trying to get?  Note that it has to fit in memory along with all the PHP code.
Avatar of rgb192

ASKER

46,000 kb

I am reading the skype sql file
Change 'memory_limit' in 'php.ini' from 128M to 256M.  You are probably reading the file in Ok but processing such a large file will take more memory.  You may have to restart Apache.
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The line numbers matter here.  What line of the script fails?  What is the PHP code on that line?  

I am fairly certain that the 46 megabyte file is getting processed somehow and in PHP standard (not OOP) notation, PHP often makes copies of the variables to pass the copies to the functions.  PHP arrays are also amazingly large when compared to the string data.  You might want to get familiar with memory_get_usage()
Avatar of rgb192

ASKER

Sorry about not providing code.


Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 11 bytes) in C:\wamp\www\test\readingsql.php on line 3

note: sql-file has no extension.  
Code runs on nusphere phpED ide, but not wamp

<?php
$filename = "C:/Users/Acer/AppData/Roaming/Skype/respondto/sql-file";
$lines = explode("\n", file_get_contents($filename));
foreach($lines as $l) {
   if (substr($l, 0, 13) == 'CREATE TABLE ') {
      echo $l . '<br>';
   }
}

Open in new window

Please see AntiPractice #9, in play here because you have two functions on line 3, so you cannot readily isolate the cause of the failure.

$lines = explode("\n", file_get_contents($filename));

But that aside, the cause of the failure is data proliferation caused by internal designs in PHP.  Instead of that, I recommend that you try this:

$str = file_get_contents($filename);

I expect that if your data set is 46 megabytes you will be able to get it into a string variable.

Also, I would recommend that you revisit this question.  I am sure that @JulianH meant well, but that is a technically incompetent solution and you should be using the regular expression on a string variable instead of trying to use strpos() on elements of an array.  There is sometimes a bit of "deep background" thinking involved in application design, and when I saw the sample data in that question, I knew instantly that any design using an array would run out of memory very, very soon.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

Thanks for ini change and code explaining size.