简体   繁体   English

dompdf内存问题

[英]dompdf memory issues

I'm using DOMPDF to generate about 500 reports from one script. 我正在使用DOMPDF从一个脚本生成大约500个报告。 It's running out of memory after about 10-15 PDFs have been generated. 在生成大约10-15个PDF之后,内存不足。

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. 在调试中,它看起来每次加载到字体加载时加载8M,但这似乎应该用字体缓存代码处理。

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. 我想发布一个简单的代码片段,但大部分内容被抽象为多个层,所以它不仅仅是一个简单的复制/粘贴。

If you're using dompdf 0.6 beta, the memory error is the result of an infinite loop that dompdf enters when rendering tables. 如果您使用的是dompdf 0.6 beta,则内存错误是dompdf在呈现表时进入的无限循环的结果。 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=34

http://code.google.com/p/dompdf/issues/detail?id=91 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) (您看到的错误是pdf PHP致命错误:允许的内存大小为268435456字节已用尽)

First if this is for anything remotely commercial just get Prince XML . 首先,如果这是远程商业的任何东西,只需获得Prince XML It's substantially better and faster than any other HTML to PDF solution (and I've looked at them all). 它比任何其他HTML到PDF解决方案都要好得多,也要快得多(而且我已经看过它们了)。 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. 如果从命令行运行,则外部循环类似于shell脚本,它将为每个报告启动一个进程。 If it's run from the Web fork a process for each script if you're on an OS that can do that. 如果你在一个能够做到这一点的操作系统上运行每个脚本,那么它是从Web fork运行的。

Take a look at Convert HTML + CSS to PDF with PHP? 看看使用PHP将HTML + CSS转换为PDF? .

As indicated by cletus, the quickest solution for you with DOMPDF is probably going to be rendering each report in a separate process. 如cletus所示,使用DOMPDF的最快解决方案可能是在单独的过程中呈现每个报告。 You can write a master script that calls a child script (using exec) which performs the actual rendering. 您可以编写一个主脚本来调用执行实际呈现的子脚本(使用exec)。 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. 正如您在DOMPDF支持小组的讨论中所看到的,它似乎确实有可能提供一点性能提升。

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. 我不相信在单个脚本中针对多个实例的DOMPDF和底层CPDF渲染引擎有很多优化。 So the font is probably being loaded into memory each time, even though it could use a static variable to cache that data. 因此,每次都可能将字体加载到内存中,即使它可以使用静态变量来缓存该数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM