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
Share:
13,393

Related videos on Youtube

Sazzad-Ul Islam
Author by

Sazzad-Ul Islam

Updated on September 23, 2022

Comments

  • Sazzad-Ul Islam
    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
      MonkeyZeus over 8 years
      You 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
      MonkeyZeus over 8 years
      In 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
    Sazzad-Ul Islam over 8 years
    My Database file size is 6.5 MB.
  • E_p
    E_p over 8 years
    They just phrased it differently ;). Learn PHP ;).
  • E_p
    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
    E_p over 8 years
    I would not do it. To much of a risk to get other problems.
  • devpro
    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
    E_p over 8 years
    Removed down-vote after an update. Reason for a vote was that you offered dangerous solution to a beginner without explaining risks.
  • devpro
    devpro over 8 years
    Thanks mate for mentioning the reason. This is really good to knw what I did wrong... thanks for correction. @e-p
  • Sazzad-Ul Islam
    Sazzad-Ul Islam over 8 years
    Thanks. Worked like charm...:) @devpro