Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 91 bytes) error while trying to backup database
13,393
You need to increase your script memory by using this:
ini_set('memory_limit', '-1');
You need to use this line at the top of file.
By increasing memory_limit your script will take unlimited memory usage of server.
If you have access on php.ini file than you can increase limit from php.ini file otherwise you need to add this line.
Side note:
If you think unlimited memory will be effected on other areas than you can set custom value as:
ini_set('memory_limit', '512M'); //increase size as you need
Related videos on Youtube
Author by
Sazzad-Ul Islam
Updated on September 23, 2022Comments
-
Sazzad-Ul Islam over 1 year
I got Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 91 bytes) error while trying to backup database on online rest server using Codeigniter dbutil backup() function.
Here is my code:
$this->load->dbutil(); $backup =& $this->dbutil->backup(); $this->load->helper('file'); write_file('./uploads/db/mybackup.gz', $backup);
I can't find out where I am doing wrong.
-
MonkeyZeus over 8 yearsYou should look into native mysqldump rather than relying on CodeIgniter to basically fill up PHP's memory with a bunch of
$output.= 'insert into...';
and then writing the output to the disk. -
MonkeyZeus over 8 yearsIn CodeIgniter 2.1.4 at least, go to
/system/database/drivers/mysql/mysql_utility.php
and find the function_backup()
to see exactly why your memory is being exhausted. The issue is that the utility is not streaming the data to a file but it is trying to load all of the bytes into memory.
-
-
Sazzad-Ul Islam over 8 yearsMy Database file size is 6.5 MB.
-
E_p over 8 yearsThey just phrased it differently ;). Learn PHP ;).
-
E_p over 8 years@Sazzad-UlIslam Would not matter you have only 32MB of run-time memory allowed with all extras your 6.5Mb would easy go over 32Mb in memory
-
E_p over 8 yearsI would not do it. To much of a risk to get other problems.
-
devpro over 8 years@e-p yes u r right... I have updated my answer.. but I dont knw y down vote if its a solution usefull solution.
-
E_p over 8 yearsRemoved down-vote after an update. Reason for a vote was that you offered dangerous solution to a beginner without explaining risks.
-
devpro over 8 yearsThanks mate for mentioning the reason. This is really good to knw what I did wrong... thanks for correction. @e-p
-
Sazzad-Ul Islam over 8 yearsThanks. Worked like charm...:) @devpro