开发者

dompdf memory issues

开发者 https://www.devze.com 2022-12-21 14:22 出处:网络
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.

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开发者_如何学JAVA 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.


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)


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?.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消