Php CodeIgniter Zip类:允许的内存耗尽
我在CodeIgniter工作。我正在尝试下载由CodeIgniter的zip类创建的zip文件,我遇到以下错误:Php CodeIgniter Zip类:允许的内存耗尽,php,codeigniter,memory,zip,Php,Codeigniter,Memory,Zip,我在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) {
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);
}
}
请任何人帮我解决这个错误,谢谢你的帮助 通过以下方式更改内存限制
ini_集('memory_limit','-1')代码>覆盖默认值
或者如果你担心的话,试试看
在启用这两行之后。
它开始工作了
; 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中增加允许的PHP内存?感谢您的回复。代码所需的内存量超过了您在环境中分配的可用内存量。正如@D.Kasipovic所说的,你需要增加你的记忆限制,或者优化查询和循环,使其不需要太多内存。如果php.ini中的memory\u limit变量更改为-1,效果/缺点是什么?如果php.ini中的memory\u limit变量更改为-1,效果/缺点是什么?您告诉服务器只使用它想要的所有内存。这是正确的吗?请任何人帮我解决这个错误!当我将该值更改为“-1”时,我得到以下错误:连接被重置,与服务器的连接在页面加载时被重置。