buzzvssymfony-http
Buzz is a lightweight PHP library for issuing HTTP requests. It is built on top of the PHP curl extension and is designed to be easy to use and flexible.
While buzz isn't as feature rich as other clients it still supports http2 and is relatively easy to use.
Symfony-http is a PHP library that provides a set of classes for working with HTTP requests and responses. It is part of the Symfony CMS framework, but can also be used independently.
Highlights
http2uses-curl
Example Use
use Buzz\Client\Curl;
use Buzz\Message\Request;
use Buzz\Message\Response;
$client = new Curl();
// GET request
$request = new Request('GET', 'http://httpbin.org/get');
$response = new Response();
$client->send($request, $response);
echo $response->getContent();
//POST request
$request = new Request('POST', '/api/resource', 'http://example.com');
$request->setContent(json_encode(['name' => 'John Doe']));
// we can also add headers or cookies:
$request->addHeader('Content-Type: application/json');
$request->addHeader('Cookie: name=foobar');
$response = new Response();
$client->send($request, $response);
echo $response->getContent();
// Buzz also supports http2 (see the 2.0 parameter)
$response = $client->sendRequest(
new Request('GET', 'https://http2.golang.org/serverpush', [], null, '2.0')
);
<?php
use Symfony\Component\HttpClient\HttpClient;
// create a client object:
$client = HttpClient::create();
// sent GET request
$response = $client->request('GET', 'https://httpbin.org/get');
// or POST request
$response = $client->request('POST', 'https://httpbin.org/post', [
'headers' => [
'Content-Type' => 'application/json',
],
'json' => [
'name' => 'John Doe',
'email' => 'john.doe@example.com',
],
]);
// print response data:
$statusCode = $response->getStatusCode();
$content = $response->getContent();
echo "Status Code: $statusCode\n";
echo "Content: $content\n";