Skip to content

Instantly share code, notes, and snippets.

@iogi
Created January 16, 2010 02:44
Show Gist options
  • Save iogi/278613 to your computer and use it in GitHub Desktop.
Save iogi/278613 to your computer and use it in GitHub Desktop.
<?php
require 'Services/Amazon/SQS/Queue.php';
define('AMAZON_ACCESS_KEY', your access key);
define('AMAZON_SECRET_ACCESSKEY', your secret access key);
// queueのURIを指定
define('QUEUE_URL', 'http://queue.amazonaws.com/508403871985/test-queue');
$sqs = new Services_Amazon_SQS_Queue(QUEUE_URL, AMAZON_ACCESS_KEY, AMAZON_SECRET_ACCESSKEY);
while(1) {
// 1件だけ取得
list($item) = $sqs->receive(1);
if (empty($item)) {
echo 'queue is empty!', PHP_EOL;
sleep(10);
continue;
}
echo 'item body is ', $item['body'], PHP_EOL;
// ここで時間のかかる作業をやる
$sqs->delete($item['handle']);
echo 'item delete.', PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment