efabrica / revolt-curl-client
Implementation of Symfony's HttpClientInterface that combines multicurl with Revolt's async EventLoop
Installs: 13 651
Dependents: 1
Suggesters: 1
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
pkg:composer/efabrica/revolt-curl-client
Requires
- php: ^8.1
- ext-curl: *
- amphp/amp: ^3.0
- amphp/sync: ^2.3
- revolt/event-loop: ^1.0
- symfony/http-client: ^6.4|^7.0
Requires (Dev)
- phpunit/phpunit: ^10.5
README
This is a fork of symfony/http-client's CurlClient that uses Revolt's async EventLoop to wait for the response instead of blocking the
main thread.
This client was created because native PHP streams that are used by amphp/http-client are slow, as our applications were hanging on
stream_select() a lot but they weren't hanging on curl_multi_select(). Reasons for this are unknown to us, but if you know,
please share your knowledge and we will place it in this README.
It uses Symfony's @internal classes, so it might break on minor Symfony versions. We will rush to fix it if it does.
Installation
composer require efabrica/revolt-curl-client
Usage
use Efabrica\RevoltCurlClient\RevoltCurlClient; $client = new RevoltCurlClient(); $f1 = async(function () use ($client) { echo "Request 1\n"; $response = $client->request('GET', 'https://httpbin.org/get?1'); $response->getContent(); echo "Request 2\n"; $response2 = $client->request('GET', 'https://httpbin.org/get?2'); $response2->getContent(); }); $f2 = async(function () use ($client) { echo "Request 3\n"; $response = $client->request('GET', 'https://httpbin.org/get?3'); $response->getContent(); echo "Request 4\n"; $response2 = $client->request('GET', 'https://httpbin.org/get?4'); $response2->getContent(); }); await([$f1, $f2]); // Outputs: // Request 1 // Request 3 // Request 2 // Request 4