I am writing a batch script and get a Allowed memory size of 134217728 bytes exhausted
error.
I don't understand why the memory is filling up. I tried unsetting the $row
variable, but that didn't change a thing. Here is my code:
// ... (sql connection)
$result = mysql_query("SELECT * FROM large_table");
while ($row = mysql_fetch_array($result)) {
echo $row['id'] . PHP_EOL;
unset($row);
}
(simplified code)
Why does the memory fill up, and how can I avoid it?
Note: this is a batch script. This is normal that I have to handle data like that (go through 1 million lines).
Update: The out of memory happens around the 400 000th line, so this has got to be something in the loop? I'd like to avoid having to implement the paging if possible.
You can find the php. ini file in the public_html for your website and right-click on the file to Edit it. Look for the line defining the memory_limit variable and set the value accordingly. Then, save the changes and reload your site to see if the PHP “Allowed Memory Size of Bytes Exhausted” error has been resolved.
You can adjust the memory allocation on the fly from within a PHP file. You simply have the code ini_set('memory_limit', '128M'); (or whatever your desired allocation is). You can remove the memory limit (although machine or instance limits may still apply) by setting the value to "-1".
Allowed memory size of 1610612736 bytes exhausted ??? can someone help me this? Try prefixing your command with COMPOSER_MEMORY_LIMIT=-1 . This will remove the memory limit for the execution of the command.
Try using http://www.php.net/manual/en/function.mysql-unbuffered-query.php (mysql_unbuffered_query()) to prevent the whole table being loaded into memory, but still avoiding pagination.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With