doubeng9567
2016-01-12 16:45 阅读 22
已采纳

致命错误:尝试备份数据库时,允许的内存大小为33554432字节(尝试分配91字节)错误

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.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    doujian4752 doujian4752 2016-01-12 16:53

    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
    
    点赞 评论 复制链接分享
  • du8794 du8794 2016-01-12 16:53

    Database may be too large?

    "Due to the limited execution time and memory available to PHP, backing up very large databases may not be possible. If your database is very large you might need to backup directly from your SQL server via the command line, or have your server admin do it for you if you do not have root privileges."

    http://www.codeigniter.com/user_guide/database/utilities.html

    Edit: As @E_p states, you're running out of memory, but my answer is probably the most likely cause of the error...

    Edit 2:

    As noted in another answer, I would strongly caution you to not use set your memory usage to unlimited ini_set('memory_limit', '-1');, especially if you're on a shared server.

    点赞 评论 复制链接分享

相关推荐