Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php mpdf memory limit error

For the first time im using mpdf library and everything worked fine. I wrote a script to create pdf file which consist a table of 274 rows. When i run the script i get php memory error. I tried different scenario but i get the same memory error. Please help me to solve this error. I have listed below different scenario and its result.

php.ini = memory_limit = 256M

script = ini_set('memory_limit', '25M');

Result:
memory_get_usage() = 12.75 mb
memory_get_peak_usage() = 12.75 mb
Fatal error: Allowed memory size of 26214400 bytes exhausted
(tried to allocate 261904 bytes)
in C:\xampp\htdocs\XX\lib\pdf\mpdf\mpdf.php on line 14268

php.ini = memory_limit = 256M

script = ini_set('memory_limit', '-1');

Result:
memory_get_usage() = 12.75 mb
memory_get_peak_usage() = 12.75 mb
Fatal error: Out of memory (allocated 1898971136)
(tried to allocate 261904 bytes) 
in C:\xampp\htdocs\XX\lib\pdf\mpdf\mpdf.php on line 14265
like image 378
sravis Avatar asked Mar 18 '13 13:03

sravis


2 Answers

Tables memory usage can be decreased using several options. official doc here

like image 102
flm Avatar answered Sep 17 '22 14:09

flm


mPDF uses a lot of memory on the server. If you get an error message that you have exceeded your memory limits, try the following:

It is more efficient in very long documents to process the HTML code in small chunks rather than as one large HTML string use ini_set("memory_limit","128M") or similar at the top of your script to allocate more memory generate a smaller mpdf.php file.

ini_set("memory_limit","128M"); $mpdf = new \Mpdf\Mpdf();

it working !!!

More detail: https://mpdf.github.io/troubleshooting/memory-problems.html

like image 24
Ratana Dev Avatar answered Sep 18 '22 14:09

Ratana Dev