Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dompdf memory error

Status
Not open for further replies.

BiJae

Programmer
Oct 1, 2002
154
US
I'm trying to get a pdf generator on my intranet portal. They would like to see the link on all pages. I've gotten a test file up running, but when I try to feed live site information I get a memory error

browser said:
Fatal error: Allowed memory size of 25165824 bytes exhausted (tried to allocate 98304 bytes) in C:\Program Files\Apache Group\Apache2\htdocs\v1\scripts\pdf\include\inline_renderer.cls.php on line 141

The file I'm hitting with the browser is test.php
Code:
<?php
require_once("./scripts/pdf/dompdf_config.inc.php");

ini_set("memory_limit","24M");
$file = "pmap.php";

ob_start();
include($file);

$html = ob_get_clean();


$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();

$dompdf->stream("sample.pdf");

?>

The file it calls out to is pmap.php which contains a simple program to pull the devices that are in the database to be monitored. The query returns 91 rows of information

Code:
<?
set_time_limit(300);
define('ENTRYPOINT', TRUE);
require_once('./datadip/dbinfo.php');
define('APPTITLE', '');
define('PMDUMP', "
select pm.PeripheralMapID
, pm.SystemServerName, pm.SystemServerAlias
, pm.PeripheralID, pm.PhysicalControllerID
, pm.AppGatewayID, pm.PeripheralDescription
from Peripheral_Map pm
join Customer cu on (pm.CustID = cu.CustID and cu.ActiveFlag = 1)
order by pm.PeripheralMapID asc");
$pmdump = array();
$conn =	mssql_connect($strdbalias, $strdbuid, $strdbpwd) or exit('unable to connect to the database service');
mssql_select_db($eventdb, $conn) or exit("unable to select the $eventdb database");
$result = mssql_query(PMDUMP, $conn) or exit('unable to run peripheral map export query');
while ( FALSE !== ($r = mssql_fetch_row($result)) ) $pmdump[] = $r;
mssql_close($conn);
function dumphead() {
	echo "<tr>\n";
	echo "<th>Peripheral<br />Map<br />ID</th>\n";
	echo "<th>System<br />Server<br />Name</th>\n";
	echo "<th>System<br />Server<br />Alias</th>\n";
	echo "<th>Peripheral<br />ID</th>\n";
	echo "<th>Physical<br />Controller<br />ID</th>\n";
	echo "<th>Application<br />Gateway<br />ID</th>\n";
	echo "<th>Peripheral<br />Description</th>\n";
	echo "</tr>\n";
}
function dumprow( $r ) {
	echo "<tr>\n";
	foreach ($r as $k => $v ) {
		if ( is_null($v) || $v == '' ) {
			$v = '&nbsp;';
			$c = 'null';
		} else {
			$c = 'dfnd';
		}
		echo "<td class='$c'><a href='topAlerts.php'>$v</a></td>\n";
	}
	echo "</tr>\n";
}
?>
<html><head><title><?= APPTITLE ?></title><style type="text/css">
<!--
BODY   {font-family: verdana; font-size: 8pt; background-color: #fdfffc; margin: 0;}
TABLE  {font-family: verdana; margin: 0;}
TH     {font-family:sanserif; font-style:normal; font-weight:bold; font-size:12pt; color:000000; background-color:ACB6AB}
TD     {font-family: sanserif; font-style:normal; font-weight: normal; font-size:9pt; color:000000; background-color:FFFFFF }
TD.null {background-color: #ACB6AB;}
TD.dfnd {background-color: #FFFFFF;}

-->
</style></head><body><div align='center'>
<span style='font-size: 16pt; font-weight: bold;'><?= APPTITLE ?></span>
<table border='1' cellspacing='0' cellpadding='3'>
<?
if ( count($pmdump) > 0 ) {
	dumphead();
	foreach ( $pmdump as $k => $v )
		dumprow($pmdump[$k]);
} else {
	echo "<tr>\n";
	echo "<td class='null'>The devices list does not contain any valid records at this time.</td>\n";
	echo "</tr>\n";
}
?>
</table>
</div></body></html>

The pmap.php page loads in the browser fine. I've actually changed out to a few different files and received the same error, this sample is the shortest code for posting.

I am setting the memory to 24MB using ini_set in my script. The browser is actually reporting that it sees that full amount and has only allocated 98kb.. So I'm not sure how to resolve this.

Has any one come across this before? Any suggestions on resolving?

Thank you,


"If the only prayer you said in
your whole life was, 'thank you,'
that would suffice."
-- Meister Eckhart
 
time to read the manual.

php manual said:
The available options are K (for Kilobytes), M (for Megabytes) and G (for Gigabytes; available since PHP 5.1.0), these are case insensitive. Anything else assumes bytes. 1M equals one Megabyte or 1048576 bytes. 1K equals one Kilobyte or 1024 bytes. You may not use these shorthand notations outside of php.ini, instead use an integer value of bytes. See the ini_get() documentation for an example on how to convert these values.

as you are using ini_set, i.e. not php.ini, you must specify the memory limit in bytes as an integer.
 
Thank you, jpadie. I try to be a conscientious poster and read as many posts, FAQ's and manuals before I post to this site. I know that your time is valuable and I do appreciate your taking the time to respond.

I have tried setting it in both the PHP.ini file and in the script itself. I would like to point out that PHP is reading the abbreviation:

Fatal error: Allowed memory size of 25165824 bytes exhausted (tried to allocate 98304 bytes) in C:\Program Files\Apache Group\Apache2\htdocs\v1\scripts\pdf\include\inline_renderer.cls.php on line 141

PHP is reporting that the Allowed Memory Size of 25165824. This shows me that it is interpreting the abbreviation of 24M as 25165824, contrary to what the manual reports.

However, I have tried it as you suggested and am getting the same error:

Fatal error: Allowed memory size of 24000000 bytes exhausted (tried to allocate 6144 bytes) in C:\Program Files\Apache Group\Apache2\htdocs\v1\scripts\pdf\include\text_frame_reflower.cls.php(319) : runtime-created function on line 1



"If the only prayer you said in
your whole life was, 'thank you,'
that would suffice."
-- Meister Eckhart
 
no slight intended. and it does look as though you are right - php is interpreting you correctly even though it should not (according to the manual, at any rate).

however the 'problem' seems genuine in that different scripts are causing the memory-out between the two versions. so perhaps there is genuine consumption going on here. php default memory limit is now 128 MB. Can you try increasing the memory limit to this level and seeing whether you are just being caught by a true memory spike?
 
no worries,

I set the memory_limit to 132M in php.ini and restarted the apache server. Same affect.


"If the only prayer you said in
your whole life was, 'thank you,'
that would suffice."
-- Meister Eckhart
 
was it in the same script? if so i suspect that the fault is in the class itself. so your best bet is to approach the authors of the class.

one caveat: if you are adding lots of graphics to the pdf then it could simply be that you are busting the memory limit each time; and doing so genuinely. if so, the only solution is to reduce the number of graphics or significantly increase the memory allocation. for example does it work if you give the script 1GB of memory?
 
I set the memory limit to 1000M in php.ini and commented out the line in the script (as to not confuse the issue).

This particular script contains no graphics. It is a single table with 164 rows. The script is dynamically building the rows in the table when it's called. This is a small customer and the potential is that we could see much larger returns on different tables.

I ran it after changing the memory to 1000M and it opened the PDF. I'm not sure this is the most efficient way.. but it did work..


"If the only prayer you said in
your whole life was, 'thank you,'
that would suffice."
-- Meister Eckhart
 
ah. the table could explain things as the renderer does not know how to render the table until all elements of the page are passed in. browsers have the same problem. it's not the rows so much as the columns.

you can radically improve the process and memory handling by using a fixed table layout ( and setting the rules in a stylesheet or similar.

however, unfortunately dompdf does not support the css property table-layout so you are left with fixing the layout yourself by using absolute widths in the table cells.

another potential route to success for you is to use the command line interface. i understand that this has better memory mapping (or makes better/more direct use of memory paging). there is no reason why you cannot spawn the php CLI process via a GET/POST request using the system() or exec() functions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top