composer require sunrise/http-client-curl
composer require sunrise/http-factory
use Sunrise\Http\Client\Curl\Client;
use Sunrise\Http\Factory\RequestFactory;
use Sunrise\Http\Factory\ResponseFactory;
$client = new Client(new ResponseFactory());
$request = (new RequestFactory)->createRequest('GET', 'http://php.net/');
$response = $client->sendRequest($request);
echo $response->getStatusCode(), PHP_EOL;
$client = new Client(new ResponseFactory(), [
\CURLOPT_AUTOREFERER => true,
\CURLOPT_FOLLOWLOCATION => true,
]);
$requests = [
(new RequestFactory)->createRequest('GET', 'http://php.net/'),
(new RequestFactory)->createRequest('GET', 'http://php.net/'),
];
$client = new Client(new ResponseFactory());
$responses = $client->sendRequests(...$request);
foreach ($responses as $i => $response) {
// note that you can get the response's request by its index...
echo sprintf('%s => %d', $requests[$i]->getUri(), $response->getStatusCode()), PHP_EOL;
}
composer test