# Stop a large PDF report from timing out

**URL:** <https://discourse.cakephp.org/t/stop-a-large-pdf-report-from-timing-out/630>\
**Category:** Need Help\
**Created:** [June 26, 2016, 3:25am UTC](https://discourse.cakephp.org/t/stop-a-large-pdf-report-from-timing-out/630 "2016-06-26T03:25:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bgrinter](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/bgrinter/32/1381_2.png) [@bgrinter](https://discourse.cakephp.org/u/bgrinter)\
**Post date:** [June 26, 2016, 3:25am UTC](https://discourse.cakephp.org/t/stop-a-large-pdf-report-from-timing-out/630/1 "2016-06-26T03:25:35Z")

</div>

We’ve written an app for tracking the membership of a volunteer youth group. One of the reports is a “parent permission form” for the kids to get signed to attend outside events - rather than fill it out each time it pulls at the information from the database for the parents to read and sign. It uses CakePDF and the dompdf engine.

The report exports fine for a single member or a small number, but if I try to run the report for a whole group (say 30 members) the report times out.

I’m looking for ideas on how to get around this, for example running the report in a batch etc. Has anyone had a similar problem before?

---

<div class="post-metadata">

**Author:** ![bgrinter](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/bgrinter/32/1381_2.png) [@bgrinter](https://discourse.cakephp.org/u/bgrinter)\
**Post date:** [June 26, 2016, 8:54am UTC](https://discourse.cakephp.org/t/stop-a-large-pdf-report-from-timing-out/630/3 "2016-06-26T08:54:16Z")

</div>

Actually think I’ve worked it out myself, I’ve written out each individual report to the filesystem using cakePdf-\>write rather than render with PDF view, and then created a function to ZIP, download and clean up

```
public function zipDownloads($files = array(), $zipFile = NULL) {

	$zip = new ZipArchive();
	if ( $zip->open($zipFile, ZipArchive::CREATE) !== TRUE) {
	exit("message");
	}
	foreach($files as $file){
	    $zip->addFile($file, basename($file));
	}
	$zip->close();

	foreach($files as $file){
	    unlink($file);
	}

	header('Content-Type: application/zip');
	header('Content-disposition: attachment; filename='.basename($zipFile));
	header('Content-Length: ' . filesize($zipFile));
	$fileStatus = readfile($zipFile);

	if ($fileStatus){
	    unlink($zipFile);
	    return true;
	} else {
	    return false;		    
	}
    
    
}
```

---

<div class="post-metadata">

**Author:** ![dakota](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dakota/32/1421_2.png) [@dakota](https://discourse.cakephp.org/u/dakota)\
**Post date:** [June 27, 2016, 6:59am UTC](https://discourse.cakephp.org/t/stop-a-large-pdf-report-from-timing-out/630/4 "2016-06-27T06:59:04Z")

</div>

One suggestion I have is to use Wkhtmltopdf instead of DomPDF. It is orders of magnitude faster!

---

<div class="post-metadata">

**Author:** ![bgrinter](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/bgrinter/32/1381_2.png) [@bgrinter](https://discourse.cakephp.org/u/bgrinter)\
**Post date:** [June 27, 2016, 10:35am UTC](https://discourse.cakephp.org/t/stop-a-large-pdf-report-from-timing-out/630/5 "2016-06-27T10:35:26Z")

</div>

@dakota Thanks for the suggestion.

Potentially this report is 130+ pages and takes some time to generate and comes in at 5mb!

The solution I ended up with seems to meet the needs for now, it creates multiple separate files zips and downloads. Will look at Wkhtmltopdf for the future though

---

<div class="post-metadata">

**Author:** ![tariquesani](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/tariquesani/32/126_2.png) [@tariquesani](https://discourse.cakephp.org/u/tariquesani)\
**Post date:** [June 30, 2016, 6:13am UTC](https://discourse.cakephp.org/t/stop-a-large-pdf-report-from-timing-out/630/6 "2016-06-30T06:13:15Z")

</div>

The ideal solution would be hand over the task of PDF generation to a queue system like Gearman or RabbitMQ. When the report is created you can have an email sent or something.

Here is a link to get you started with Gearman [http://www.lornajane.net/posts/2011/using-gearman-from-php](http://www.lornajane.net/posts/2011/using-gearman-from-php), once you understand the concepts you can search for Gearman CakePHP plugin to help you out.
