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`.

Maintainers

Package info

gitlab.com/tereta/library/curl

Homepage

Issues

pkg:composer/tereta/curl

Transparency log

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

0.0.5 2026-07-12 20:22 UTC

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-curl extension.

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. $params are appended to the query string. Returns the response body (string).
  • post(string $url, mixed $params = null) — a POST request. $params are 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();