dompdf内存问题

发布于 2024-08-23 05:59:34 字数 179 浏览 14 评论 0原文

我正在使用 DOMPDF 从一个脚本生成大约 500 份报告。生成大约 10-15 个 PDF 后,内存不足。

在调试中,看起来每次加载字体时都会加载 8M,但这似乎应该用字体缓存代码来处理。

对这里出了什么问题有什么想法吗?我想发布一个简单的代码片段,但其中大部分被抽象为多层,因此它不仅仅是简单的复制/粘贴。

I'm using DOMPDF to generate about 500 reports from one script. It's running out of memory after about 10-15 PDFs have been generated.

In debugging, it looks like it's loading 8M every time it gets to the font loading stuff, but this seems like something that should be handled with the font caching code.

Any ideas of what's going wrong here? I'd like to post a simple code snippet, but most of it is abstracted into multiple layers, so it's not just a simple copy/paste.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤独陪着我 2024-08-30 05:59:34

如果您使用的是 dompdf 0.6 beta,则内存错误是 dompdf 在渲染表格时进入无限循环的结果。这是一个我无法解决的已知问题。

相关网址:

http://code.google.com/p/dompdf /issues/detail?id=34

http:// code.google.com/p/dompdf/issues/detail?id=91

(您看到的错误是 pdf PHP Fatal error: Allowed memory size of 268435456 bytes exceded)

If you're using dompdf 0.6 beta, the memory error is the result of an infinite loop that dompdf enters when rendering tables. This is a known issue that I haven't been able to resolve.

Relevant URLs:

http://code.google.com/p/dompdf/issues/detail?id=34

http://code.google.com/p/dompdf/issues/detail?id=91

(The error you see is pdf PHP Fatal error: Allowed memory size of 268435456 bytes exhausted)

演出会有结束 2024-08-30 05:59:34

首先,如果这是用于任何远程商业用途,只需获取 Prince XML。它比任何其他 HTML 到 PDF 解决方案都要更好、更快(我已经研究过所有这些解决方案)。开发人员节省的时间很快就能收回成本。

其次,最快的解决方案可能是在单独的进程中打印每个报告,以解决任何内存泄漏问题。如果从命令行运行,则外部循环应类似于 shell 脚本,它将为每个报告启动一个进程。如果它是从 Web 运行的,则为每个脚本创建一个进程(如果您使用的操作系统可以执行此操作)。

查看使用 PHP 将 HTML + CSS 转换为 PDF?

First if this is for anything remotely commercial just get Prince XML. It's substantially better and faster than any other HTML to PDF solution (and I've looked at them all). The cost will quickly be recouped in saved developer time.

Second, the quickest solution is probably to print each report in a separate process to solve any memory leak problems. If this is running from the command line have the outer loop be something like a shell script that will start a process for each report. If it's run from the Web fork a process for each script if you're on an OS that can do that.

Take a look at Convert HTML + CSS to PDF with PHP?.

束缚m 2024-08-30 05:59:34

正如 cletus 所指出的,使用 DOMPDF 最快的解决方案可能是在单独的进程中呈现每个报告。您可以编写一个主脚本来调用执行实际渲染的子脚本(使用 exec)。正如您在 DOMPDF 支持小组的此讨论中看到的,似乎确实有潜力提供一点性能提升。

如果没有某种示例来说明问题,则很难说出内存使用情况的其他情况。我不认为 DOMPDF 和底层 CPDF 渲染引擎对于单个脚本中的多个实例有太多优化。因此,即使可以使用静态变量来缓存该数据,字体也可能每次都会加载到内存中。

As indicated by cletus, the quickest solution for you with DOMPDF is probably going to be rendering each report in a separate process. You can write a master script that calls a child script (using exec) which performs the actual rendering. As you can see in this discussion on the DOMPDF support group, it does seem to have the potential to provide a bit of a boost in performance.

It's difficult to say what's going on otherwise regarding memory usage without some kind of example that demonstrates the problem. I don't believe there is much optimization of DOMPDF and the underlaying CPDF rendering engine for multiple instances in a single script. So the font is probably being loaded into memory each time, even though it could use a static variable to cache that data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文