LoginSignup
3
3

More than 5 years have passed since last update.

AWS SDK for PHP v3 with ReactPHP

Posted at

ReactPHP + AWS SDK for PHP v3

composer.json

{
    "require": {
        "react/react": "0.4.*",
        "aws/aws-sdk-php": "~3.0@dev",
        "wyrihaximus/react-guzzle-ring": "dev-master"
    }
}

Example

use React\EventLoop;
use Aws\DynamoDb\DynamoDbClient;
use WyriHaximus\React\RingPHP\HttpClientAdapter;

$loop  = EventLoop\Factory::create();

$ddbClient = DynamoDbClient::factory([
    'region'  => 'ap-northeast-1',
    'version' => 'latest',
    'key'     =>  '<your aws key>',
    'secret'  =>  '<your aws secret>'
    'ringphp_handler' => new HttpClientAdapter($loop)
]);

/** @var \Aws\Common\FutureResult $ddbResult */
$ddbResult = $ddbClient->putItem([
    'TableName' => 'table_name',
    'Item' => [
        'id'          => [ 'S' => $id ],
        'createdTime' => [ 'N' => (string)$createdTime ],
    ],
    '@future' => true
]);

$dbbResult->then(
    function ($result) {
        /** @var Aws\Common\Result $result **/
        echo 'done';
    },
    function (\Exception $e) {
        echo 'fail';
    }
);

$loop->run();
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3