Created
January 20, 2014 01:35
-
-
Save zaru/8513554 to your computer and use it in GitHub Desktop.
AWS SDK ver1を使って、AWS SQSを利用するサンプルスクリプト。実際の運用に使うには、キューメッセージを受け取る側をデーモン化したり工夫する必要あり。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require_once('/Vendor/aws_sdk/sdk.class.php'); | |
| $sqs = new AmazonSQS(); | |
| $region = AmazonSQS::REGION_APAC_NE1; | |
| $sqs->set_region($region); | |
| $queueName = 'キュー名'; | |
| $queueURL = $sqs->create_queue($queueName)->body->CreateQueueResult->QueueUrl; | |
| while (true) { | |
| $data = $sqs->receive_message($queueURL); | |
| if ($data->isOK()) { | |
| if (isset($data->body->ReceiveMessageResult->Message)) { | |
| $msgData = $data->body->ReceiveMessageResult->Message; | |
| $msg = $msgData->Body; | |
| echo $msg . "\n"; | |
| // 削除 | |
| $handle = (string)$msgData->ReceiptHandle; | |
| $sqs->delete_message($queueURL, $handle); | |
| } else { | |
| sleep(1); | |
| } | |
| } else { | |
| echo $data->body->Error->Message . "\n"; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require_once ('Vendor/aws_sdk/sdk.class.php'); | |
| $sqs = new AmazonSQS(); | |
| $region = AmazonSQS::REGION_APAC_NE1; | |
| $sqs->set_region($region); | |
| $queueName = 'キュー名'; | |
| $queueURL = $sqs->create_queue($queueName)->body->CreateQueueResult->QueueUrl; | |
| $data = $sqs->send_message($queueURL, '値' . time()); | |
| if ($data->isOK()) { | |
| echo 'OK'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment