tereta / curl
Tereta/Curl is a facade over cURL. For everyday tasks there is a simple facade with `get()` and `post()` methods, and for several requests at once — parallel execution powered by `curl_multi`.
Requires
- php: >=8.2
- ext-curl: *
Requires (Dev)
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.0
- squizlabs/php_codesniffer: ^3.13
This package is not auto-updated.
Last update: 2026-07-13 15:51:44 UTC
README
🌐 English | Русский | Українська
Contents
Introduction
Tereta/Curl is a facade over cURL. For everyday tasks there is a simple facade with get() and post() methods, and for several requests at once — parallel execution powered by curl_multi.
Requirements
- PHP 8.2 or newer.
- The
ext-curlextension.
Installation
composer require tereta/curl
Repository: https://gitlab.com/tereta/library/curl
Usage
The entry point is the Tereta\Curl\Client facade.
Available methods:
get(string $url, array $params = [])— a GET request.$paramsare appended to the query string. Returns the response body (string).post(string $url, mixed $params = null)— a POST request.$paramsare sent in the request body. Returns the response body (string).create()— return a client for several requests that are executed in parallel.
If the response code is anything other than 200, get() and post() throw Tereta\Curl\Exceptions\Error.
Examples
Simple requests:
use Tereta\Curl\Client;
$client = new Client();
// GET with parameters (?page=2)
$html = $client->get('https://example.com', ['page' => 2]);
// POST with a request body
$response = $client->post('https://example.com/api', ['name' => 'Alex']);
Parallel requests via create():
$service = (new Client())->create();
$first = $service->request('https://example.com/one');
$second = $service->request('https://example.com/two');
// both requests run at the same time
$service->execute();
$bodyOne = $first->getResponse()->getBody();
$bodyTwo = $second->getResponse()->getBody();