Amazon AWS PHP SDK with Guzzle's MultiCurl?

佐手、 提交于 2019-12-12 01:14:54

问题


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.

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.

Thanks!


回答1:


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.

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



来源:https://stackoverflow.com/questions/18831481/amazon-aws-php-sdk-with-guzzles-multicurl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!