tags:

views:

294

answers:

3

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?

+2  A: 

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.

Spencer Ruport
+1 for the second paragraph
Greg
A: 

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.

craigsrose
+3  A: 

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.

Quamis
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).
cletus