Batch process (+8000 pdf) help!

708 views
Skip to first unread message

Francisco Alvarez Padilla

unread,
Mar 25, 2012, 12:59:48 PM3/25/12
to dom...@googlegroups.com
  Hi i want process more 8000 pdf in one process.
The report reaches the limit and the process is broken to reach the limit of memory allocated to that process, does not exceed 2 GB Transaction.

Now try both and load_html_file load_html and both thunders. (beta2 version)

dumpdf has some method to free the occupied memory to generate the pdf?

Someone has gone something like this?

plz help

gretings

Fabien Ménager

unread,
Mar 25, 2012, 3:25:10 PM3/25/12
to dom...@googlegroups.com
Hello, dompdf does have such a method, but it's called internally each time an object is not needed anymore. This method is not used in PHP 5.3 because this version has a good garbage collector. Which version of PHP do you use ?
Do you instanciate a new DOMPDF object each time ? Are there any PDF generated ? On of the document may stop the process because it has the issue evoqued here :  http://code.google.com/p/dompdf/issues/detail?id=91 

Francisco Alvarez Padilla

unread,
Mar 25, 2012, 6:53:38 PM3/25/12
to dom...@googlegroups.com

HI thaks for the answers

For each interaction i use that

        $dompdf = new DOMPDF();
$dompdf->load_html($html);  // $dompdf->load_html_file($urlFile);
$dompdf->render();
$pdfdata=$dompdf->output();
file_put_contents("../pdf/".$fileName.".pdf", $pdfdata);
unset($html); // unset($urlFile);
unset($dompdf);

The version of php is: PHP Version 5.3.5

The server for testing ant take care that the process is done with xampp

Also start the memory 

ini_set('memory_limit', '512M');

I the log errors have this

PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 393216 bytes

Only can create 350 pdf, of 8000

any one can help me?

Thx!! Gretings.

Fabien Ménager

unread,
Mar 26, 2012, 2:07:51 AM3/26/12
to dom...@googlegroups.com
Could you write some sort of memory logging after each step :
  • before new dompdf
  • after load_html
  • after render
  • after the unsets
and write it in a log file with the current document name you are processing.
With this you would see if it is a regular memory usage growth or if a document takes all the memory because it has the problem I mentionned.

Francisco Alvarez Padilla

unread,
Mar 27, 2012, 12:45:43 AM3/27/12
to dom...@googlegroups.com
Hi

I get this results... (some)

the value for render, dont print nothing, i dont understand why.

Before: 1989976
In load_html_file: 2340144
unset: 9672328

Before: 9672904
In load_html_file: 9676976
unset: 10168088

Before: 10166272
In load_html_file: 10170376
unset: 10542760

Before: 10542728
In load_html_file: 10546768
unset: 10913328

Before: 10913504
In load_html_file: 10917672
unset: 11267656

Before: 11267640
In load_html_file: 11271680
unset: 11629376

Before: 11629632
In load_html_file: 11633672
unset: 12000672

The log File dont generate any error.

Gretings


BrianS

unread,
Mar 27, 2012, 10:38:36 PM3/27/12
to dom...@googlegroups.com
PHP does do some amount of garbage handling, but some of this just indicates that previously-used memory is no longer in use. Ideally PHP would release or reuse the memory. But that's not always the case. What we've found in the past is that the most efficient method of running DOMPDF in batch is to run each rendering in a separate PHP process via exec(). Check out the following discussion:

Francisco Alvarez Padilla

unread,
Mar 28, 2012, 12:32:11 AM3/28/12
to dom...@googlegroups.com
Hi Brian Thank so much for the anwser.

In the info for usage,exist an a example for this?

Thanks!

BrianS

unread,
Mar 28, 2012, 10:01:42 AM3/28/12
to dom...@googlegroups.com
This isn't something we've really documented (or even thoroughly researched) just yet. So unfortunately there isn't much info in the dompdf documentation. If you need any advice on how to proceed let us know.

Francisco Alvarez Padilla

unread,
Mar 28, 2012, 11:29:00 AM3/28/12
to dom...@googlegroups.com
Ups, ok, ahhh what is the better way for this?


Create a .bat file with my process, and execute with exec. This .bat process a php with dompdf


OR

Make testing executing a dompdf command line (i see a little documentation) if sucess, make the exec process. 

Thanks Brian!

Gretins

BrianS

unread,
Mar 28, 2012, 1:28:42 PM3/28/12
to dom...@googlegroups.com
You can keep your current file, but instead of something like this:

...
foreach ($htmldoc_collection as $htmldoc) {
  $dompdf = new DOMPDF();
  $dompdf->load_html($htmldoc);

  $dompdf->render();
  $pdfdata=$dompdf->output();
  file_put_contents("../pdf/".$fileName.".pdf", $pdfdata);
  unset($dompdf);
}
...

you would do something like this:

...
foreach ($htmldoc_collection as $htmldoc) {
  file_put_contents("doc.html", $htmldoc);
  exec("php pdfgen.php doc.html $filename");
  unlink("doc.html");
}
...

pdfgen.php would look something like this:

$htmldoc = $argv[1];
$filename = $argv[2];
$dompdf = new DOMPDF();

$dompdf->load_html_file($htmldoc);
$dompdf->render();
file_put_contents($fileName, $dompdf->output());

Modify the above as necessary to get things working how you want, it may take some trial-and-error.
Reply all
Reply to author
Forward
0 new messages