使用PHP SDK sendEmail中的SesClient类方法发送电子邮件目前每封电子邮件大约需要半秒钟.我正在遍历收件人数组,并ToAddresses在调用之前将message 属性设置为等于只包含收件人电子邮件地址的数组sendEmail().我想加快发送过程,但在我看来,SDK提供的PHP类每个消息都有一个请求(在我的例子中是收件人).(每条消息可能有一个连接?)
我做了一些阅读,我考虑使用该BccAddresses属性分批发送电子邮件,但我们希望To:标题设置明确,而不是只说"未公开的收件人",所以我想知道是否有人有一个更好的方法.
对于那些通过AWS和SES试图解决在持久连接上完成的并行请求问题的绊脚石,AWS SDK 2及更高版本在php中使用命令对象支持此功能.
SesClient和其他客户端可以并行执行命令.这是通过SES触发单个连接和电子邮件的常规方法:
$result = $client->sendEmail(array(
//email data
));
Run Code Online (Sandbox Code Playgroud)
客户端对象非常强大,并且继承了许多方法来执行和操作请求,例如getCommand()和execute().在找到简单的解决方案之前,需要花费数小时的时间进行挖掘!你只需要知道正确的搜索.这是一个例子:
$commands = array();
$commands[] = $sesClient->getCommand('SendEmail', array(
//email data
));
$commands[] = $sesClient->getCommand('SendEmail', array(
//email data
));
// Execute an array of command objects to do them in parallel
$sesClient->execute($commands);
// Loop over the commands, which have now all been executed
foreach ($commands as $command) {
$result = $command->getResult();
// Do something with result
}
Run Code Online (Sandbox Code Playgroud)
可以通过执行以下代码来实现错误处理:
use Guzzle\Service\Exception\CommandTransferException;
try {
$succeeded = $client->execute($commands);
} catch (CommandTransferException $e) {
$succeeded = $e->getSuccessfulCommands();
echo "Failed Commands:\n";
foreach ($e->getFailedCommands() as $failedCommand) {
echo $e->getExceptionForFailedCommand($failedCommand)->getMessage() . "\n";
}
}
Run Code Online (Sandbox Code Playgroud)
亚马逊在命令功能下的开发人员指南中记录了这些示例.
| 归档时间: |
|
| 查看次数: |
1073 次 |
| 最近记录: |