http client curl
v1.4.6
composer require sunrise/http-client-curl
composer require sunrise/http-factory
use SunriseHttpClientCurlClient;
use SunriseHttpFactoryRequestFactory;
use SunriseHttpFactoryResponseFactory;
$client = new Client(new ResponseFactory());
$request = (new RequestFactory)->createRequest('GET', 'http://php.net/');
$response = $client->sendRequest($request);
echo $response->getStatusCode(), PHP_EOL;
https://www.php.net/manual/ru/curl.constants.php
$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