Jon Cantwell
Stuff & Things. Mostly devtricks slides for synacor.
(So, basically, exactly what we use cURL for in web development most of the time.)
Guzzle manages persistent connections,
abstracts out the HTTP transport layer,
integrates with pretty much any underlying method of sending HTTP requests over the wire.
No more fiddling with cURL options, yay!
$client = new GuzzleHttp\Client();
$response = $client->get('http://guzzlephp.org');
$res = $client->get('https://api.github.com/user',
['auth' => ['user', 'pass']]);
echo $res->getStatusCode();
// "200"
echo $res->getHeader('content-type');
// 'application/json; charset=utf8'
echo $res->getBody();
// {"type":"User"...'
var_export($res->json());
// Outputs the JSON decoded data
// Send an asynchronous request.
$req = $client->createRequest('GET', 'http://httpbin.org',
['future' => true]);
$client->send($req)->then(function ($response) {
echo 'I completed! ' . $response;
});
Guzzle has:
Requirements: PHP 5.4
:(
(but you might be okay?)
Best installed using composer:
composer require guzzlehttp/guzzle
Extensive documentation available online at:
By Jon Cantwell