2

My php script creates PDF on fly, the data comes from mysql db table it works fine till 30 records but more than that it says

I am dompdf from http://code.google.com/p/dompdf/

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 56214 bytes) in F:\xampp\htdocs\wiseworker\dompdf\lib\class.pdf.php on line 3043 

however I have used ini_set("memory_limit","96550M"); and also set in php.ini

; Maximum amount of memory a script may consume (5120MB) ; http://php.net/memory-limit memory_limit = 96550M 

I also increase query execution time

if( !ini_get('safe_mode') ){ set_time_limit(0); } 

but it just limited around 45bytes to 65bytes and what will happen if mysql table contain hundreds of records?

5
  • how about trying to unset any possible extra variables that you could be using, or something like that? Commented Jan 12, 2012 at 4:44
  • As @StasM said, you probably not setting correct php.ini file.Run phpinfo() and check real value of memory_limit and location of php.ini file.If run script inside webserver, restart/reload it. Commented Jan 16, 2012 at 6:03
  • Try echo ini_get('memory_limit'); to make sure that your memory limit is set correctly. Commented Jan 16, 2012 at 6:12
  • 1
    @ All I tested (restart apache) more than one times after setting memory_limit = 94G and it shows exactly 94G but still says Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 57971 bytes) in F:\xampp\htdocs\wiseworker\dompdf\lib\class.pdf.php on line 2739 Commented Jan 16, 2012 at 7:32
  • 1
    Ok thanks to all I just need to set memory_limit = 94G in dompdf class and now it is creating large pdf but after some minutes browser says "The connection was reset - The connection to the server was reset while the page was loading. etc...." although I increase the execution time up to 3600 sec //ini_set('max_execution_time', 3600) Commented Jan 16, 2012 at 9:09

4 Answers 4

12

use the following on the top of your page:

 ini_set('max_execution_time', 3000); ini_set('memory_limit','16M'); 

This setting is valid for your current script only.

Sign up to request clarification or add additional context in comments.

Comments

3

45 bytes is not the limit - 33554432 is the limit, which is 32M. 45 bytes is just a block that PHP tried to allocate and failed (which is not very useful since it could be anything). Check that you are actually editing correct php.ini and it actually is reflected in your phpinfo(). 96550M btw is 94G of memory - do you really have that much? Try to unset objects you are not using and also try to run gc cycle via gc_collect_cycles (see: http://www.php.net/manual/en/function.gc-collect-cycles.php ) manually.

1 Comment

My script does not have irreverent script or variables and objects.. If I am making any mistake while understanding you than please explain with example if possible.
0

Ok thanks to all I just need to set memory_limit = 94G in dompdf class and now it is creating large pdf but after some minutes browser says "The connection was reset - The connection to the server was reset while the page was loading. etc...." although I increase the execution time up to 3600 sec //ini_set('max_execution_time', 3600)

Comments

0

go through below code. update code and comment as per your requirement

<?php echo '<h1>System Configuration</h1>'; echo '<br>'; //PHP SETUP: all time in seconds //ini_set('max_execution_time', 18000); // set your max execution time that you require for current script //ini_set('memory_limit',' 2048M'); // set memory limit that you require for current script //ini_set("max_input_time", '5000'); //ini_set('default_socket_timeout', '5000'); //@set_time_limit(0); //DATABASE SETUP: all time in seconds //ini_set('mysql.connect_timeout', '5000'); $ini_path = php_ini_loaded_file(); $ini_max_time = ini_get('max_execution_time'); $ini_memory = ini_get('memory_limit'); ?> <div class="hdr">Current Server</div> <label>Web Server : </label> <?php echo $_SERVER['SERVER_SOFTWARE']; ?><br/> <label>Operating System : </label><?php echo PHP_OS ?><br/> <label>PHP Version : </label><?php echo phpversion(); ?><br/> <label>PHP INI Path : </label><?php echo empty($ini_path ) ? 'Unable to detect loaded php.ini file' : $ini_path; ?><br/> <label>PHP SAPI : </label><?php echo php_sapi_name(); ?><br/> <label>PHP ZIP Archive : </label> <?php echo class_exists('ZipArchive') ? 'Is Installed' : 'Not Installed'; ?> <br/> <label>PHP max_execution_time:</label> <?php echo $ini_max_time === false ? 'unable to find' : $ini_max_time; ?><br/> <label>PHP memory_limit : </label> <?php echo empty($ini_memory) ? 'unable to find' : $ini_memory; ?><br/> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.