Skip to content

Instantly share code, notes, and snippets.

@mtdowling
Created September 9, 2015 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mtdowling/bafd8011a7a641974601 to your computer and use it in GitHub Desktop.
Save mtdowling/bafd8011a7a641974601 to your computer and use it in GitHub Desktop.
React, Guzzle, and AWS SDK for PHP integration
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use React\EventLoop\Factory;
use WyriHaximus\React\GuzzlePsr7\HttpClientAdapter;
$loop = Factory::create();
$reactHandler = new HttpClientAdapter($loop);
$handlerStack = HandlerStack::create($reactHandler);
$guzzleClient = new Client(['handler' => $handlerStack]);
$guzzleClient->getAsync('http://google.com/')->then(function ($response) {
var_export($response);
});
/*
// Use React with the AWS SDK
use Aws\Handler\GuzzleV6\GuzzleHandler;
$awsHandler = new GuzzleHandler($guzzleClient);
$sdk = new Aws\Sdk(['http_handler' => $awsHandler]);
$s3 = $sdk->createS3(['version' => 'latest', 'region' => 'us-east-1']);
$s3->getObjectAsync(['Bucket' => 't1234', 'Key' => 'test'])
->then(
function ($result) { echo $result; },
function ($reason) { echo $reason; }
);
*/
$loop->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment