CentOS 5.9 64bit
PHP 5.3.3
PHP 5.3.3
■クイックスタート
1. AWS SDK for php for composer をダウンロードする
以下の記事を参考に事前にcomposerをインストールしてください
http://kakakikikeke.blogspot.jp/2013/12/phpcomposer.html
touch composer.json
vim composer.json
composer install
以下のようになれば完了です(デバッグログにデフォルトで色付けされているのがいいです)
2. アクセスキーとシークレットキーの取得
https://portal.aws.amazon.com/gp/aws/securityCredentials
アクセスしawsのアカウントでログインします
取得したアクセスキー、シークレットキーは後で使いますので大切に補完しておいてください
3. サンプル実行ファイルを作成する
touch sample_sqs.php
vim sample_sqs.php
以下を貼り付けてください
リージョンはus-west-2(Oregon)にしていますので適宜変更して問題ございません
key と secret を取得したアクセスキーとシークレットキーで設定してください
基本的に結果は連想配列で返ってくるようなので、中身をvar_dumpメソッドで確認しながら目的のデータを取得する感じになるかと思います
php sample_sqs.php
とするとkaka_queue002に「test message !」というメッセージが送信され受信もされます
以下の記事を参考に事前にcomposerをインストールしてください
http://kakakikikeke.blogspot.jp/2013/12/phpcomposer.html
touch composer.json
vim composer.json
{
"require": {
"aws/aws-sdk-php": "2.*"
}
}
composer install
以下のようになれば完了です(デバッグログにデフォルトで色付けされているのがいいです)
WARNING: channel "pear.php.net" has updated its protocols, use "pear channel-update pear.php.net" to update
Loading composer repositories with package information
Installing dependencies (including require-dev)
- Installing symfony/event-dispatcher (v2.4.0)
Downloading: 100%
- Installing guzzle/guzzle (v3.7.4)
Downloading: 100%
- Installing aws/aws-sdk-php (2.4.11)
Downloading: 100%
symfony/event-dispatcher suggests installing symfony/dependency-injection ()
symfony/event-dispatcher suggests installing symfony/http-kernel ()
aws/aws-sdk-php suggests installing doctrine/cache (Adds support for caching of credentials and responses)
aws/aws-sdk-php suggests installing ext-apc (Allows service description opcode caching, request and response caching, and credentials caching)
aws/aws-sdk-php suggests installing monolog/monolog (Adds support for logging HTTP requests and responses)
aws/aws-sdk-php suggests installing symfony/yaml (Eases the ability to write manifests for creating jobs in AWS Import/Export)
Writing lock file
2. アクセスキーとシークレットキーの取得
https://portal.aws.amazon.com/gp/aws/securityCredentials
アクセスしawsのアカウントでログインします
取得したアクセスキー、シークレットキーは後で使いますので大切に補完しておいてください
3. サンプル実行ファイルを作成する
touch sample_sqs.php
vim sample_sqs.php
以下を貼り付けてください
<?php
require 'vendor/autoload.php';
use Aws\Sqs\SqsClient;
$client = SqsClient::factory(array(
'key' => 'your access key',
'secret' => 'your secret access key',
'region' => 'us-west-2'
));
echo 'ListQueues' . "\r\n";
$result0 = $client->listQueues(array(
'QueueNamePrefix' => 'string',
));
$result0->get('QueueUrls');
var_dump($result0);
$result1 = $client->createQueue(array(
'QueueName' => 'kaka_queue002',
'Attributes' => array(
'VisibilityTimeout' => '300',
),
));
$queueUrl = $result1->get('QueueUrl');
echo $queueUrl . "\r\n";
$result2 = $client->sendMessage(array(
'QueueUrl' => $queueUrl,
'MessageBody' => 'test message !',
'DelaySeconds' => 0,
));
echo 'ReceiveMessage' . "\r\n";
$result3 = $client->receiveMessage(array(
'QueueUrl' => $queueUrl,
'MaxNumberOfMessages' => 10,
'WaitTimeSeconds' => 20,
));
$body = $result3['Messages'];
echo $body[0]['Body']. "\r\n";
#var_dump($result3);
echo 'OK';
?>
リージョンはus-west-2(Oregon)にしていますので適宜変更して問題ございません
key と secret を取得したアクセスキーとシークレットキーで設定してください
基本的に結果は連想配列で返ってくるようなので、中身をvar_dumpメソッドで確認しながら目的のデータを取得する感じになるかと思います
php sample_sqs.php
とするとkaka_queue002に「test message !」というメッセージが送信され受信もされます
■参考
0 件のコメント:
コメントを投稿