开发者

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

开发者 https://www.devze.com 2023-01-17 23:29 出处:网络
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 numbe

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 t开发者_StackOverflow中文版he 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).


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.


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


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).


Change your memory_limit.

try,

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消