php mpdf memory limit error
Asked Answered
P

4

14

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
Pugilist answered 18/3, 2013 at 13:52 Comment(6)
ini_set('memory_limit', -1); var_dump(ini_get('memory_limit')); Confirm your changes are being set.Garbage
@Mike B It outputs this = string(2) "-1"Pugilist
So something else is setting the memory limit back to 25.Garbage
Any idea to rectify this? :-(Pugilist
Can you isolate the problematic HTML part? For example, does it help to slim it down, or to remove style sheets, etc? Does it help if you run it through DOMDocument (loadXhtml + saveHtml) to fix nesting issues? Can you isolate the code causing the memory issues within mpdf?Responsive
Avoid using BORDERS in mpdf, it may lessen the memory being eat up.Tanh
M
5

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

Maricamarice answered 7/8, 2013 at 8:40 Comment(3)
Buddy, I really need your answer, but the link you posted is down. Can you edit your answer pasting the appropiate info?Overrule
Specifically, try $mpdf->packTableData = true; or $mpdf->packTableData = true; (from the link, in case it gets broken in the future). Otherwise, go through the compress.php script included in mpdf.Mirabelle
A good answer has the lion's share of the advice hard pasted into the answer. Stackoverfow isn't trying to be a traffic controller, it means to hold the knowledge right here (for as long as it shall live; 'til death do us part)Hebdomadary
U
2

Have you tried to see the phpinfo() output in order to see if the memory_limit value you're setting is changing? try to put that function at the top of your index.php file and see if the ini_set('memory_limit', '256M'); it's taking effect.

Regards!

Unchain answered 8/8, 2015 at 3:51 Comment(0)
D
2

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

Deprived answered 15/6, 2018 at 2:25 Comment(1)
This should be an accepted answer.Unconscious
P
0

I've found out of sync (</table>) tags can cause memory issues (and speed); cleaning up the HTML going into mPDF solved it.

Polyptych answered 9/12, 2014 at 23:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.