带有Guzzle的MultiCurl的Amazon AWS PHP SDK? [英] Amazon AWS PHP SDK with Guzzle's MultiCurl?

查看:137
本文介绍了带有Guzzle的MultiCurl的Amazon AWS PHP SDK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Amazon的适用于PHP的AWS开发工具包执行一些相当繁琐的查询。

最有效的方法是使用 PHP的MultiCurl 。似乎 Guzzle已经具有功能

I need to perform some fairly heavy queries with Amazon's AWS SDK for PHP.
The most efficient way would be to use PHP's MultiCurl. It seems that Guzzle already has functionality for MultiCurl built in.

使用AWS开发工具包提供的标准方法会自动使用MultiCurl还是我必须直接指定其用途?例如。调用 $ sns-> Publish() 30次。

Does using the standard methods provided by the AWS SDK automatically use MultiCurl or do I have to specify it's usage directly? E.g. calling $sns->Publish() 30 times.

谢谢!

推荐答案

并行请求在SDK中的工作方式与在普通Guzzle中完全相同,并且确实利用了MultiCurl。例如,您可以执行以下操作:

Parallel requests work exactly the same in the SDK as in plain Guzzle and do take advantage of MultiCurl. For example, you could do something like this:

$message = 'Hello, world!';
$publishCommands = array();
foreach ($topicArns as $topicArn) {
    $publishCommands[] = $sns->getCommand('Publish', array(
        'TopicArn' => $topicArn,
        'Message'  => $message,
    ));
}

try {
    $successfulCommands = $sns->execute($publishCommands);
    $failedCommands = array();
} catch (\Guzzle\Service\Exception\CommandTransferException $e) {
    $successfulCommands = $e->getSuccessfulCommands();
    $failedCommands = $e->getFailedCommands();
}

foreach ($failedCommands as $failedCommand) { /* Handle any errors */ }

$messageIds = array();
foreach ($successfulCommands as $successfulCommand) {
    $messageIds[] = $successfulCommand->getResult()->get('MessageId');
}

// Also Licensed under version 2.0 of the Apache License.

适用于PHP的AWS开发工具包用户指南包含有关以这种方式使用命令对象的更多信息。

The AWS SDK for PHP User Guide has more information about working with command objects in this way.

这篇关于带有Guzzle的MultiCurl的Amazon AWS PHP SDK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆