FPDF Fatal error: Allowed memory size of 33554432 bytes exhausted (PHP)

妖精的绣舞 提交于 2019-12-11 00:24:10

问题


This is a often discussed issue but so far no solution seems to fit for my problem. I'm generating a pdf with $pdf = new FPDF(); . This works fine. But now I want to have a footer with the page number. After trying a lot of things I found out, that if you want to set a footer, you need to create an instance with $pdf = new yourPDFclassName(); (which extends the parent FDF class).

Running the whole thing again I receive the error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 77 bytes) in /..blabla/yourPDFclassName.php on line 16

Does anyone have an idea why this error occurs when I call the child class? I mean it works with the parent class... And btw, 77 bytes are much smaller than the 33554432 bytes ... hmm

class REPORTSPDF extends FPDF { .... }

16: $pdf = new REPORTSPDF();

The line 16 is in the constructor of REPORTSPDF. There are no other lines before line 16. It just crashes when $pdf = new REPORTSPDF() is called.

Without the Footer function I have the same error. The weird thing is that when I change line 16 to

$pdf = new FPDF();

everything works fine (with the exception that I don't have a footer).


回答1:


sounds like you have an infinite loop in you code. try to do a simple hello-world-test ans see what happens and check all loop in your code.




回答2:


Increase memory limit

There are 3 ways to increase memory limit

  • using config file

    Change memory limit in php.ini

    memory_limit = 32M

  • using PHP

    ini_set('memory_limit','32M');

  • using htaccess

    php_value memory_limit 32M

Methods in different server

Shared Hosting

php_value memory_limit 32M

Dedicated or VPS Optimized

ssh -lroot domain.com

locate php.ini

vi /usr/local/php/etc/php.ini

edit to 

memory_limit=32M;

save file

httpd restart

/sbin/service httpd restart



回答3:


The error message means that, while attempting to allocate an additional 77 bytes, the memory limit of 33554432 bytes was exceeded.

There are only two ways around this: either optimize the code in your subclass so you don't need as much memory, or increase your memory limit in php.ini (or using equivalent methods for manipulating with the PHP configuration).




回答4:


Change your memory_limit.

try,

ini_set('memory_limit','128M');



回答5:


I've not used it myself, but the FPDF2File extension to FPDF is an attempt to build the PDF page by page to disk rather than purely in memory



来源:https://stackoverflow.com/questions/3804315/fpdf-fatal-error-allowed-memory-size-of-33554432-bytes-exhausted-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!