Run DOMPDF more than once?

389 views
Skip to first unread message

jheske

unread,
Mar 9, 2010, 8:32:39 PM3/9/10
to dompdf
I'm trying to create a series of pdf files from html pages. In my php
script I've got a separate function that creates the DOMPDF object,
loads the html, etc. The problem is that if I try to run that more
than once it fails. I get a "The connection was reset" error in
firefox.

I did try creating the DOMPDF instance once, and then just reusing it,
but that didn't work either. The second call results in a fatal error
"Uncaught exception 'DOMPDF_Exception' with message 'No block-level
parent found..."

Does anyone know how I can call DOMPDF more than once from within a
script? Is there something I need to clear, reinitialize, etc?

I'm using version dompdf-0.5.1.

Thanks!

-jheske

BrianS

unread,
Mar 9, 2010, 11:17:43 PM3/9/10
to dompdf

The DOMPDF object definitely doesn't like to be re-used, as you have
seen. In the past I have done something similar to your current setup.
Have you tried using unset() on the DOMPDF object? This was the trick
for me.

Are you seeing any errors in your PHP error.log? What about your
Apache error.log? Typically a connection reset from an Apache server
means the child process crashed. The resources assigned to DOMPDF
might not be released with the way you currently have your script
coded. This could, perhaps, be the reason Apache is having problems
(though I haven't confirmed this to be a problem).

A way you could code your script that would definitely release
resources would be to create a separate PHP script that runs the
DOMPDF tasks. Call it using exec() and all the resources associated
with each instance would be released on each loop. See the following
discussion for reference:
http://groups.google.com/group/dompdf/browse_thread/thread/c253a52b10766a33/4211bcedbf9cf40?q=

Paul Waring

unread,
Mar 10, 2010, 4:18:01 AM3/10/10
to dom...@googlegroups.com
BrianS wrote:
> A way you could code your script that would definitely release
> resources would be to create a separate PHP script that runs the
> DOMPDF tasks. Call it using exec() and all the resources associated
> with each instance would be released on each loop. See the following
> discussion for reference:
> http://groups.google.com/group/dompdf/browse_thread/thread/c253a52b10766a33/4211bcedbf9cf40?q=

One thing which isn't mentioned in that discussion and is worth pointing
out is that you will need to be *extremely* careful about passing
arguments to exec, especially if they come from user input. In my script
all the information comes from a pre-populated database table, so I know
what the data is.

Also, if you are on a virtual hosting platform, the exec function might
(and should in my opinion) be disabled.

Paul

--
Paul Waring
http://www.pwaring.com

Paul Waring

unread,
Mar 11, 2010, 8:49:16 AM3/11/10
to dom...@googlegroups.com
jheske wrote:
> In my original tests I did try doing unset($dompdf) after each use,
> but I get that FF error. I do not see anything helpful in the php or
> apache error logs.

What do you see in the logs? Information which appears unhelpful at
first can still sometimes help track down what the problem is.

> I''ve tried to run my script using exec() but with no luck. I just
> haven't been able to figure out how to use exec to call a PHP script.
> I'm testing in Windows XP. Here's my exec() command:
>
> exec ("c:\\program files\\php\\php.exe mydompdf.php",$retval);
>
> mydompdf.php is just a simple test script that doesn't take any params
> but creates a canned pdf file from some sample html text.
> Unfortunately, the test pdf doesn't get created and exec() doesn't
> return anything ($retval is an empty array), so I have no idea what my
> error is.

What happens if you try running the script on the command line, i.e.
without using exec?

Reply all
Reply to author
Forward
0 new messages