【问题标题】:Laravel FatalErrorException: Out of memoryLaravel FatalErrorException:内存不足
【发布时间】:2018-09-17 07:08:14
【问题描述】:

我正在尝试导出我的 zip 文件,但出现错误:

Fatal Error Exception in ProjectFinding.php line 387:
Out of memory (allocated 382468096) (tried to allocate 1346263 bytes)

php.ini set memory_limit=2048M。有什么不对? 请告诉我为什么这个错误是由于代码或内存中的错误以及如何解决这个错误?

这行显示错误

 $zip->addFromString($nfile[1], file_get_contents($file));

【问题讨论】:

  • 更改ini文件后是否重启/重新加载PHP/Apache服务?
  • 请出示您的代码,否则我们无能为力。另外,尝试输出phpinfo() 并在其中找到您的memory_limit 值以确认它是您认为的值。
  • 请分享您的代码。你必须检查内存限制。
  • 你应该检查你的代码中是否有无限循环或无限递归,我曾经遇到这些错误。

标签: javascript php html css laravel


【解决方案1】:
public function excel_exports($input, $p_id) {
        $find = new Project();
        $tmp_name = time();
        $path = storage_path("files/" . $p_id);
        if (!is_dir($path)) {
            umask(0);
            mkdir($path, 0777, true);
            chmod($path, 0777);
        }

        $project = new Project();
        $prodata = $project->getById($p_id);
        $zipfile = $prodata->id.'.zip';
        $excelname = $prodata->id;
        $data = $findingObj->getAll($p_id);
        $colspan = 1;
        foreach ($data as $row) {
            $this->_saveDocumentsFiles($row);
            $doc_cc = 0;
            foreach ($row->document as $doc) {
                $doc_cc = $doc_cc + $doc->doc_files->count();
            }
            if ($doc_cc > $colspan) {
                $colspan = $doc_cc;
            }
        }
        Excel::create($excelname, function($excel) use ($data, $colspan) {
            $excel->sheet('projectfinding', function($sheet) use ($data, $colspan) {
                $sheet->loadView('admin.project.finding.excel_file_exports')->with(["targetRow" => 5, "targetCol" => "A", "targetView" => "admin.project.finding.excel_pdf", 'data' => $data, 'colspan' => $colspan]);
            });
        })->save('xls', $path, false);
        $source = storage_path('files');
        $this->zip($source, $zipfile);
        header("Content-type: application/zip");
        header("Content-Disposition: attachment; filename=$zipfile");
        readfile($zipfile);
        unlink(public_path($zipfile));
        $rmpath = storage_path("files/" . $p_id);
        $this->_rrmdir($rmpath);
        return true;
    }

in this code i simply change p_id with id it will show error in $path and $rmpath

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-07
    • 2021-02-15
    • 2018-04-07
    • 2021-09-25
    • 2020-01-08
    • 2015-08-15
    • 1970-01-01
    相关资源
    最近更新 更多