pdf 生成和打印的长时间延迟发送电子邮件。在服务器解析脚本时放置图像?
我正在制作一个表格,您可以在其中订购快递服务。它的主要思想是生成包含验证数据的 PDF 文件,然后将其附加到电子邮件中发送给客户 + 抄送给快递公司。
问题是 pdf 生成 (TCPDF) 和电子邮件发送 (Swiftmail) 需要相当长的时间。
我想防止不耐烦的用户一遍又一遍地单击“确认”。理想的解决方案是显示一些 gif“正在加载”图像等。我研究过 jquery .load() 函数,它看起来对于这个问题来说是件好事,但是对于没有 js 的用户呢?
你能指出我正确的方向吗?
I'm working on a form in which you can order courier service. The main idea for it is to generate PDF file containing validated data and then attach it to an e-mail to client + cc for courier company.
The thing is pdf generation (TCPDF) and e-mail sending (Swiftmail) takes noticeably long.
I would like to prevent impatient user from clicking 'confirm' over and over. The ideal solution would be to show some gif 'loading' image or so. I've looked into jquery .load() function and it looks like a good thing for this problem, but what about users w/o js?
Can you point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这种情况下我会使用ajax。但如果您真正担心缺乏 JS,那么有几种方法可以在没有 JS 的情况下做到这一点。
首先,您可以在开始使用 pdf 之前向用户显示一些内容。例如,
函数flush()将强制网络服务器将数据发送到浏览器,以便在加载页面的其余部分时显示数据。然而有些浏览器会在内部缓存这个东西。有一些方法可以克服这个问题(查看 php.net 中的lush() 函数注释),但它可能会变得混乱。
另一种方法是异步处理 PDF。在这种情况下,目标脚本仅显示一条消息,表明电子邮件将很快发送。并解雇真正要发送它的脚本女巫。例如:
在此示例中,“process_pdf.php”将获得与原始脚本相同的 POST 参数。但会在后台执行,不会中断原始页面。
I would use ajax in this case. but if lack of JS is a genuine concern for you, there are couple of ways to do this without JS.
First you can display something to the user before starting to work with pdf. eg
function flush() will force the webserver to send the data to the browser, so it will be displayed while the rest of the page is loaded. However some browsers will cache this thing internally. There are ways to overcome this (check out comments in php.net for a flush() function) but it could get messy.
Another way is to process PDF asynchronously. In this case target script just displays a message that email will be send shortly. And fires the script witch actually going to send it. eg:
in this example "process_pdf.php" will get all the same POST parameters as original script. but will be executed in the background without interrupting the original page.
超过98%的用户激活了javascript。剩下的 2% 是由:
如今,Js 几乎被认为是理所当然的,它是一个 Web 标准。我想说的是,别担心,去做吧——没有其他方法可以做到这一点。不过,对于盲人来说,如果有一个
标签,其中包含诸如“操作可能需要几秒钟”之类的信息,那就太好了。
More than 98% of users have javascript activated. The remaining 2% is made by:
Js is taken mostly for granted nowadays, and it's a web standard. I'd say don't worry and go for it - there is no other way to do it. Still, for the blind, it would be nice to have a
<noscript>
tag with information such as "The operation might take some seconds".另一种方法是在后台作业中进行处理(创建 PDF 并发送电子邮件)。因此,当您的用户单击“确认”时,该后台作业将根据表单中的输入启动,并向用户显示一条消息,表明其作业正在处理,并且他或她很快就会通过电子邮件收到确认。这样,您就可以避免完全依赖 Javascript。
你可以使用类似 Beanstalkd 的东西。
Another approach would be to do the processing (creating the PDF and sending the email) in a background job. So when your uses clicks 'Confirm', this background job is started with the input from the form and the user is shown a message that his job is being processed and he or she will receive a confirmation by email shortly. This way, you avoid relying on Javascript all together.
You could use something like Beanstalkd for this.