首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >phpword/src/PhpWord/Shared/ZipArchive.php中允许的内存大小问题

phpword/src/PhpWord/Shared/ZipArchive.php中允许的内存大小问题
EN

Stack Overflow用户
提问于 2020-06-22 18:56:59
回答 1查看 398关注 0票数 0

我试图使用TemplateProcessor (在laravel 7中的phpword)从定义的模板创建一个文档,但是我得到了这个错误:

代码语言:javascript
复制
FastCGI sent in stderr: "PHP message: PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in ****/vendor/phpoffice/phpword/src/PhpWord/Shared/ZipArchive.php on line 131 PHP message: PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in Unknown on line 0"

当我设置ini_set(' memory _ limit ','-1');或者在我的php.ini中提高内存限制时,我得到:Maximum execution time of 30 seconds exceeded我可以提高最大执行时间,但仍然得到相同的错误。对此错误负责的函数为:

代码语言:javascript
复制
public function open($filename, $flags = null)
{
    $result = true;
    $this->filename = $filename;
    $this->tempDir = Settings::getTempDir(); // the 131 line who responsable for the error 

    if (!$this->usePclzip) {
        $zip = new ZipArchive();
        $result = $zip->open($this->filename, $flags);

        // Scrutizer will report the property numFiles does not exist
        // See https://github.com/scrutinizer-ci/php-analyzer/issues/190
        $this->numFiles = $zip->numFiles;
    } else {
        $zip = new \PclZip($this->filename);
        $zipContent = $zip->listContent();
        $this->numFiles = is_array($zipContent) ? count($zipContent) : 0;
    }
    $this->zip = $zip;

    return $result;
}

php -v

代码语言:javascript
复制
    PHP 7.4.7 (cli) (built: Jun 12 2020 07:48:26) ( NTS )

我找遍了所有地方,但我没有找到任何解决这个问题的方法。提前感谢

EN

回答 1

Stack Overflow用户

发布于 2020-06-23 20:36:13

我找到了这个问题的解决方案,在phpword的设置中用pclzip替换了zipArchive:

代码语言:javascript
复制
Path to setting : .../vendor/phpoffice/phpword/src/PhpWord/Settings.php

更改此设置:

代码语言:javascript
复制
    private static $zipClass = self::ZIPARCHIVE;

通过以下方式:

代码语言:javascript
复制
    private static $zipClass = self::PCLZIP;

我在0.16.0和0.17.0版本中测试了它,它像魔术一样工作:)

PS :也许你必须安装pclzip才能打开它。Pclzip installation

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62512857

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档