I have Symfony framework with TWIG template engine. I am making 1000 page pdf within
我有Symfony框架和TWIG模板引擎。我正在制作1000页的pdf文件
<dynamic-page>...content in for-loop...</dynamic-page>`
However while writing onto disk with ps_facade
, it gives me memory exhausted fatal error. So is there any ways I can create this pdf by 5 pages a chunk?
然而,当使用ps_facade在磁盘上写入时,它会给我内存耗尽的致命错误。有什么方法可以把这个pdf文件分成5页?
After research I found that using template with 5 page worth of data and then write it on file should work. But in that way I won't be able to add page numbers, as page number should be 1-1000. My footer code looks like this,
经过研究,我发现使用包含5页数据的模板并将其写入文件应该是可行的。但是这样我就不能添加页码了,因为页码应该是1-1000。我的页脚代码是这样的,
<placeholders>
<footer>
<div height="30px" width="100%">
<hr/>
<div float="left">Blah Blah</div>
<div float="left" margin-left="350px"><page-info format="Page %s of %s"></div>
</div>
</footer>
</placeholders>
1 个解决方案
#1
2
You should use a messaging system for long processes like this. RabbitMQ could do the job.
您应该对这样的长进程使用消息传递系统。RabbitMQ可以完成这项工作。
- Your user requests for the pdf
- 您的用户请求pdf
- You tell him instantly that his request has been taken into account, and that he will receive an email when the job is done, or that he can come back later
- 你马上告诉他,他的要求已经考虑到了,工作完成后他会收到一封电子邮件,或者他稍后会回来
- A consumer sees the job, and launches the pdf generation (does not have to be in php).
- 使用者看到任务,并启动pdf生成(不需要使用php)。
Pros: Since the process is not run by the web version of php, it does not have the memory_limit and max_execution time limitation If the job is already running, you can tell your user so instead of launching another generation for the same pdf. And since people often refresh the page when they get impatient, this can really be a huge Pro for your server (less CPU usage).
优点:由于该进程不是由web版本的php运行的,所以如果作业已经在运行,它没有memory_limit和max_execution time限制,所以您可以告诉您的用户这样做,而不是为相同的pdf启动另一个生成。由于人们经常在不耐烦的时候刷新页面,这对您的服务器来说是一个巨大的好处(减少CPU的使用)。
Cons: You'll have to setup a messaging server and learn a few things. But is this really a Con?
缺点:您必须安装一个消息服务器并学习一些东西。但这真的是一个骗局吗?
#1
2
You should use a messaging system for long processes like this. RabbitMQ could do the job.
您应该对这样的长进程使用消息传递系统。RabbitMQ可以完成这项工作。
- Your user requests for the pdf
- 您的用户请求pdf
- You tell him instantly that his request has been taken into account, and that he will receive an email when the job is done, or that he can come back later
- 你马上告诉他,他的要求已经考虑到了,工作完成后他会收到一封电子邮件,或者他稍后会回来
- A consumer sees the job, and launches the pdf generation (does not have to be in php).
- 使用者看到任务,并启动pdf生成(不需要使用php)。
Pros: Since the process is not run by the web version of php, it does not have the memory_limit and max_execution time limitation If the job is already running, you can tell your user so instead of launching another generation for the same pdf. And since people often refresh the page when they get impatient, this can really be a huge Pro for your server (less CPU usage).
优点:由于该进程不是由web版本的php运行的,所以如果作业已经在运行,它没有memory_limit和max_execution time限制,所以您可以告诉您的用户这样做,而不是为相同的pdf启动另一个生成。由于人们经常在不耐烦的时候刷新页面,这对您的服务器来说是一个巨大的好处(减少CPU的使用)。
Cons: You'll have to setup a messaging server and learn a few things. But is this really a Con?
缺点:您必须安装一个消息服务器并学习一些东西。但这真的是一个骗局吗?