我试图使用TemplateProcessor (在laravel 7中的phpword)从定义的模板创建一个文档,但是我得到了这个错误:
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我可以提高最大执行时间,但仍然得到相同的错误。对此错误负责的函数为:
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
PHP 7.4.7 (cli) (built: Jun 12 2020 07:48:26) ( NTS )我找遍了所有地方,但我没有找到任何解决这个问题的方法。提前感谢
发布于 2020-06-23 20:36:13
我找到了这个问题的解决方案,在phpword的设置中用pclzip替换了zipArchive:
Path to setting : .../vendor/phpoffice/phpword/src/PhpWord/Settings.php更改此设置:
private static $zipClass = self::ZIPARCHIVE;通过以下方式:
private static $zipClass = self::PCLZIP;我在0.16.0和0.17.0版本中测试了它,它像魔术一样工作:)
PS :也许你必须安装pclzip才能打开它。Pclzip installation
https://stackoverflow.com/questions/62512857
复制相似问题