【问题标题】:CodeIgniter Zip Class: Allowed memory exhaustedCodeIgniter Zip Class:允许内存耗尽
【发布时间】:2014-04-08 12:37:45
【问题描述】:

我在 CodeIgniter 工作。我正在尝试做的是下载由 CodeIgniter 的 ZIP 类创建的 zip 文件,我收到此错误:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 30381518 bytes) in ..\system\core\Output.php on line 366

我的 PHP 代码:

foreach ($attachments as $attachment) {
        if ($attachment->type === 'file') {
            $data = @file_get_contents($uploadDirectory . $attachment->fullPath . DIRECTORY_SEPARATOR . $attachment->physicalName);
            $attachment->location = ltrim($attachment->location, '/');
            $fileName = $attachment->location ? $attachment->location . DIRECTORY_SEPARATOR . $attachment->name : $attachment->name;
            $this->zip->add_data($fileName, $data);
        }
    }

请谁能帮我解决这个错误,感谢您的帮助!

【问题讨论】:

  • 这不是错误,这是代码!你得到什么错误?
  • 在 php.ini 中增加 PHP 允许的内存?
  • 感谢您的回复。
  • 您的代码所需的内存量超过了您在环境中分配的可用内存量。正如@D.Kasipovic 所说,您需要增加内存限制,或优化您的查询和循环,使其不需要太多内存。
  • 如果 php.ini 中的 memory_limit 变量更改为 -1 会有什么影响/缺点。

标签: php codeigniter memory zip


【解决方案1】:

将 memory_limit 更改为

ini_set('memory_limit', '-1'); 覆盖默认的PHP memory limit.

或者如果担心使用,请尝试,

启用这两行之后。 它开始工作了

; Determines the size of the realpath cache to be used by PHP. This value should
; be increased on systems where PHP opens many files to reflect the quantity of
; the file operations performed.
; http://php.net/realpath-cache-size
realpath_cache_size = 16k

; Duration of time, in seconds for which to cache realpath information for a given
; file or directory. For systems with rarely changing files, consider increasing this
; value.
; http://php.net/realpath-cache-ttl
realpath_cache_ttl = 120

【讨论】:

  • 如果 php.ini 中的 memory_limit 变量改为 -1 会有什么影响/缺点
  • 你告诉服务器只使用它想要的所有内存。
  • 这是正确的吗?请谁能帮我解决这个错误!
  • 当我将值更改为“-1”时出现此错误:连接已重置 在页面加载时与服务器的连接已重置。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-02
  • 2012-08-19
  • 2020-06-25
  • 2014-04-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多