dqrq93879 2012-06-18 15:02
浏览 89
已采纳

AWS使用SQS上传到S3 - PHP语法

Would uploading to S3 using SQS make the process more fault tolerant?

If so, i am having a hard time with syntax, trying to combine creating a queue then uploading to S3.
If my logic is not correct, how would i set up a system using SQS to upload to S3?

if (!class_exists('S3'))require_once('S3.php');

// *these keys are random strings
$AWS_KEY = "6VVWTU4JDAAKHYB1C3ZN";
$AWS_SECRET_KEY = "GMSCUD8C0QA1QLV9Y3RP2IAKDIZSCHRGKEJSXZ4F";

//AWS access info
if (!defined('awsAccessKey')) define('awsAccessKey', $AWS_KEY);
if (!defined('awsSecretKey')) define('awsSecretKey', $AWS_SECRET_KEY);
//instantiate the class
$s3 = new S3(awsAccessKey, awsSecretKey);

//check whether a form was submitted
if(isset($_POST['Submit'])){

    //retreive post variables
    $fileName = $_FILES['theFile']['name'];
    $fileTempName = $_FILES['theFile']['tmp_name'];

    //create a new bucket
    $s3->putBucket("mybucket", S3::ACL_PUBLIC_READ);




    //add the queue
    $sqs = new AmazonSQS(array( "key" => $AWS_KEY, "secret" => $AWS_SECRET_KEY ));
    $response = $sqs->create_queue('test-topic-queue');
    $queue_url = (string) $response->body->CreateQueueResult->QueueUrl;
    $queue_arn = 'arn:aws:sqs:us-east-1:ENCQ8gqrAcXv:test-topic-queue';

    //$queue_url . ?Action=SendMessage&MessageBody=Your%20Message%20Text?&AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE&Version=2011-10-01?&Expires=2008-02-10T12:00:00Z?&Signature=lBP67vCvGlDMBQ1do?fZxg8E8SUEXAMPLE&SignatureVersion=2&SignatureMethod=HmacSHA256


    // HOW DO I INCORPORATE SQS AND S3



    //move the file
    if ($s3->putObjectFile($fileTempName, 
                                "mybucket", 
                                "myFolder/" . $fileName, S3::ACL_PUBLIC_READ, 
                                array(), 
                                $_FILES['theFile']['type']) ) {
        //it works
    }else{
        // error
    }
}
  • 写回答

2条回答 默认 最新

  • donglu7286 2012-06-27 02:18
    关注

    I'm not exactly understanding the fault tolerance you are requesting. But in terms of using S3 and SQS for scaling, there is an excellent paper on the Amazon AWS website that talks about scaling up and down your infrastructure using SQS and EC2 together, which can of course include processes like uploading to S3 and using SQS to tell the application to process something. You don't mention whether or not you're using EC2 or if this is of interest.

    Here is the article: http://aws.amazon.com/articles/1464

    Otherwise, it sounds like your logic may be confused as SQS isn't an in-between from server to S3, but rather more for application messaging.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化