douji5523 2013-09-16 15:13
浏览 67
已采纳

带有Guzzle MultiCurl的Amazon AWS PHP SDK?

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条回答 默认 最新

  • doukong1391 2013-09-16 15:49
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)