如何在基于Laravel的应用程序中处理大量PDF生成并通过电子邮件发送它们

问题描述:

I'm just curious how would you handle a scenario where a lot of PDF's has to be generated on the server and be send to the user by email. You're not able to temper with the PDF because it needs to be 100% secure or close to that number.

For example the PDF contains the order you just made in a webshop, proof of purchase or something like that.

The application will have a lot of concurrent users. For this question I will use Laravel as a base platform for the web application.

I had the idea of running a cron job at night that will generate all this PDF's at once and send per e-mail.

What is considered best practise in this scenario?

我只是好奇你将如何处理必须在服务器上生成大量PDF的场景 通过电子邮件发送给用户。 您无法使用PDF进行调整,因为它需要100%安全或接近该数字。 p>

例如,PDF包含您刚在网店中制作的订单,证明 购买或类似的东西。 p>

该应用程序将有很多并发用户。 对于这个问题,我将使用Laravel作为Web应用程序的基础平台。 p>

我有一个想法是在晚上运行一个cron作业,它将立即生成所有这些PDF并按发送 -邮件。 p>

在这种情况下,最佳做法是什么? p> div>

For example the PDF contains the order you just made in a webshop, proof of purchase or something like that.

Given that these will presumably occur throughout the day, a queue may be a better solution than a cron. Every time someone does an action that'd require a PDF, fire off a queue job. A background process will check for queued jobs and process them.

This avoids having a giant backlog, protects you in the case a cron fails, and gets PDFs out to the clients in a more timely fashion.