1

Ok, this may be a dumb question but here goes. I noticed something the other day when I was playing around with different HTML to PDF converters in PHP. One I tried (dompdf) took forever to run on my HTML. Eventually it ran out of memory and ended but while it was still running, none of my other PHP scripts were responsive at all. It was almost as if that one request was blocking the entire Webserver.

Now I'm assuming either that can't be right or I should be setting something somewhere to control that behaviour. Can someone please clue me in?

3
  • dompdf is pretty touchy - make sure you have valid html and try to keep nesting (Especially tables) to a minimum Commented Jan 10, 2009 at 8:56
  • Also there's a bug in the latest PHP (5.2.8) that can make apache segfault in dompdf: bugs.php.net/bug.php?id=44182 Commented Jan 10, 2009 at 8:58
  • I had a few errors in my HTML but I fixed them and I now run it through HTML Tidy to fix errors (it validates with 0 errors after Tidy according to the W3C validator) and dompdf still chokes on it. I'm currently looking into html2ps/html2pdf as an alternative. Commented Jan 10, 2009 at 8:58

3 Answers 3

7

did you had open sessions for each of the scripts?:) they might reuse the same sesion and that blocks until the session is freed by the last request...so they basically wait for each other to complete(in your case the long-running pdf generator). This only applies if you use the same browser.

Tip, not sure why you want html to pdf, but you may take a look at FOP http://xmlgraphics.apache.org/fop/ to generate PDF's. I'm using it and works great..and fast:) It does have its quirks though.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm constructing a document from HTML fragments so HTML is it. XML (FO) is no good to me. I didn't realize session access blocked though. I think that's the problem. I think I assumed they worked like Java sessions (always dangerous to assume such things).
2

It could be that all the scripts you tried are running in the same application pool. (At least, that's what it's called in IIS.)

However, another explanation is that some browsers will queue requests over a single connection. This has caused me some confusion in the past. If your web browser is waiting for a response from yourdomain.com/script1.php and you open another window or tab to yourdomain.com/script2.php that request won't be sent until the first request receives a reply making it seem like your entire web server is hanging. An easy way to test if this is what's going on try two requests on two separate browsers.

Comments

0

It sounds like the server is simply being overwhelmed and under too much load to complete the requests. Converting an HTML file to a PDF is a pretty complex process, as the PHP script has to effectively provide the same functionality as a web browser and render the HTML using PDF drawing functions.

I would suggest you either split the HTML into separate, smaller files or run the script as a scheduled task directly through PHP independent of the server.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.