sunrise / http-client-curl
Simple HTTP cURL client for PHP 7.1+ based on PSR-18
Installs: 4 791
Dependents: 1
Suggesters: 0
Security: 0
Stars: 17
Watchers: 4
Forks: 2
Open Issues: 6
Requires
- php: ^7.1|^8.0
- ext-curl: *
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- phpunit/phpunit: 7.5.20|9.5.0
- sunrise/coding-standard: 1.0.0
- sunrise/http-factory: 2.0.0
Provides
- dev-master
- v1.4.6
- v1.4.5
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.0
- v1.2.0
- v1.1.0
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-renovate/phpunit-phpunit-11.x
- dev-renovate/phpunit-phpunit-9.x
- dev-renovate/psr-http-message-2.x
- dev-renovate/sunrise-http-factory-2.x
- dev-release/v1.4.5
- dev-release/v1.4.4
- dev-release/v1.4.3
- dev-release/v1.4.1
- dev-release/v1.4.0
- dev-release/v1.3.0
This package is auto-updated.
Last update: 2024-12-21 06:30:42 UTC
README
Installation
composer require sunrise/http-client-curl
QuickStart
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;
cURL options
$client = new Client(new ResponseFactory(), [ \CURLOPT_AUTOREFERER => true, \CURLOPT_FOLLOWLOCATION => true, ]);
Parallel execution of multiple requests
$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; }
Test run
composer test