AWS上传到S3与SQS - PHP语法 [英] AWS upload to S3 with SQS - PHP syntax

查看:350
本文介绍了AWS上传到S3与SQS - PHP语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用SQS

可否上传到S3使过程更加容错?

如果是这样,我有一个很难与语法,试图结合起来创建一个队列然后上传到S3。
如果我的逻辑是不正确的,我将如何设置使用系统 SQS 上传到 S3

 如果(class_exists(S3)!)require_once('S3.php');

// *这些键是随机的字符串
$ AWS_KEY =6VVWTU4JDAAKHYB1C3ZN;
$ AWS_SECRET_KEY =GMSCUD8C0QA1QLV9Y3RP2IAKDIZSCHRGKEJSXZ4F;

// AWS访问信息
如果(定义(awsAccessKey')!)定义('awsAccessKey',$ AWS_KEY);
如果(定义(awsSecretKey')!)定义('awsSecretKey',$ AWS_SECRET_KEY);
//实例化类
$ S3 =新S3(awsAccessKey,awsSecretKey);

//检查表单是否提交
如果(使用isset($ _ POST [提交])){

    // retreive后变量
    $文件名= $ _FILES ['theFile'] ['名称'];
    $ fileTempName = $ _FILES ['theFile'] ['tmp_name的值'];

    //创建一个新的水桶
    $ S3-> putBucket(mybucket,S3 :: ACL_PUBLIC_READ);




    //添加队列
    $ SQS =新AmazonSQS(阵列(钥匙=> $ AWS_KEY,秘密=> $ AWS_SECRET_KEY));
    $响应= $ sqs-> create_queue(测试专题队列');
    $ queue_url =(字符串)$响应 - >身体 - > CreateQueueResult-> QueueUrl;
    $ queue_arn ='阿尔恩:AWS:SQS:美东1:ENCQ8gqrAcXv:测试主题队列;

    // $ 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


    //我如何结合SQS和S3



    //移动文件
    如果($ S3-> putObjectFile($ fileTempName,
                                mybucket
                                MyFolder中/。 $文件名,S3 :: ACL_PUBLIC_READ,
                                阵列(),
                                $ _FILES ['theFile'] ['型'])){
        //有用
    }其他{
        // 错误
    }
}
 

解决方案

我不完全理解的容错能力,你的请求。但是,在使用S3和SQS的比例方面,还有亚马逊AWS网站谈论缩放,上下用SQS和EC2合您的基础设施,这当然包括像SQS上传到S3,并使用​​到工艺上的优秀论文告诉应用程序处理的东西。你不提你是否正在使用EC2或者如果这是感兴趣的。

下面是文章: http://aws.amazon.com/articles/1464

否则,这听起来像你的逻辑可能会混淆为SQS不是一个中间从服务器到S3,而是更多的应用程序的消息。

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
    }
}

解决方案

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.

这篇关于AWS上传到S3与SQS - PHP语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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