FPDF 致命错误:允许的内存大小 33554432 字节已耗尽 (PHP)

发布于 2024-09-25 09:44:00 字数 647 浏览 0 评论 0原文

这是一个经常讨论的问题,但到目前为止似乎没有解决方案适合我的问题。 我正在生成一个 pdf $pdf = new FPDF(); 。这很好用。但现在我想要一个带有页码的页脚。经过尝试很多事情后我发现,如果你想设置页脚,你需要使用 $pdf = new yourPDFclassName(); 创建一个实例(它扩展了父 FDF 类)。

再次运行整个过程,我收到错误:第 16 行 /..blabla/yourPDFclassName.php 中允许的内存大小为 33554432 字节耗尽(试图分配 77 字节)

有谁知道为什么当我打电话给孩子时会发生此错误班级?我的意思是它与父类一起工作...顺便说一句,77 字节比 33554432 字节小得多...嗯,

class REPORTSPDF extends FPDF { .... }

16: $pdf = new REPORTSPDF();

第 16 行位于 REPORTSPDF 的构造函数中。第 16 行之前没有其他行。它只是在调用 $pdf = new REPORTSPDF() 时崩溃。

如果没有页脚功能,我也会遇到同样的错误。奇怪的是,当我将第 16 行更改为

$pdf = new FPDF();

一切正常时(除了我没有页脚)。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

简单爱 2024-10-02 09:44:00

听起来你的代码中有一个无限循环。尝试做一个简单的 hello-world-test 并看看会发生什么并检查代码中的所有循环。

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.

神爱温柔 2024-10-02 09:44:00

增加内存限制

有 3 种方法可以增加内存限制

  • 使用配置文件

    更改 php.ini 中的内存限制

    memory_limit = 32M

  • 使用 PHP

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

  • 使用 htaccess

    php_value memory_limit 32M

不同服务器中的方法

共享主机

php_value memory_limit 32M

专用或 VPS 优化

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

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
苏大泽ㄣ 2024-10-02 09:44:00

该错误消息意味着,在尝试分配额外 77 字节时,超出了 33554432 字节的内存限制。

解决这个问题只有两种方法:要么优化子类中的代码,这样就不需要太多内存,要么增加 php.ini 中的内存限制(或使用等效方法来操作 PHP 配置)。

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

茶色山野 2024-10-02 09:44:00

更改您的内存限制。

尝试,

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

Change your memory_limit.

try,

ini_set('memory_limit','128M');
不羁少年 2024-10-02 09:44:00

我自己没有使用过它,但是 FPDF 的 FPDF2File 扩展是一种尝试逐页在磁盘上构建 PDF,而不是纯粹在内存中

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文