javascript - PHP Mailer,在发送电子邮件时阻止整个服务器执行
问题描述
首先,我看到了这个问题:发送邮件而不阻止“执行”
但是,我需要知道为什么 PHP 不是一个多线程进程,但如果两个人同时尝试连接就没有问题。
我实际上是通过 Ajax 调用来调用邮件脚本:
$.ajax({
url: 'sendMailTemplate.php',
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function (data) {}
...
我对 PHP 邮件程序的问题是,当我发送电子邮件时,如果这需要 10 秒,那么在 10 秒内我无法使用我网站的任何功能(并且网站对每个人来说都关闭了 10 秒)。我应该尝试使用 cron 作业吗?有没有关于 PHP 邮件程序 + cron 作业的教程?除了 cron 工作之外,最好的方法是什么?
解决方案
Should I try to use cron jobs ?
Yes
Is there any tutorial for PHP mailer + cron jobs ?
I tried my own logic by using multiple reference :
Below logic execute like queue and also sending time base on your cronjob & you hrly mailing limit.
- Mailing : when you click on send email that time you have store all emails into
"temp_table"
of your database with their"to,cc,bcc,suject,body"
columns. - Write cron job for hrly(your time) basic which will execute in certain time span.
- In cron script you have to write code which will take emails (set query limit to take no of records) from
"temp_tables"
& send to the recipient. After success full sending, delete those mails from"temp_table"
of you database.
Whats the best way other than cron jobs ?
You have contact to your service provider to increase hrly mailing limit, increase your server speed, php.ini : change loading time (this option not works every time), refer different language like python
推荐阅读
- lighting - Mac 上的 UE5 流明照明
- input - 游戏中的关键停止
- json - 如何以角度显示动态json数据?
- javascript - 被 CORS 阻止:预检响应中的 Access-Control-Allow-Headers 不允许请求标头字段授权
- c# - 使用 Github Action 验证 .editorconfig 文件
- javascript - 为什么按钮区域没有按我的预期工作?
- javascript - JavaScript 中对象的浅拷贝和深拷贝
- discord - Discord Bot 静音 CMD 崩溃
- android - android studio 不断停止 - Android Studio
- javascript - 无法在javascript nodejs express中将数据从字符串解析为html