PHPackages                             drewlabs/curl-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. drewlabs/curl-client

ActiveLibrary[HTTP &amp; Networking](/categories/http)

drewlabs/curl-client
====================

Provides a PHP class around PHP curl object and Psr18 client based on the curl library

v0.4.2(2mo ago)01.3k9MITPHPPHP &gt;=7.2CI passing

Since Nov 20Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/azandrew-sidoine/drewlabs-curl-client)[ Packagist](https://packagist.org/packages/drewlabs/curl-client)[ RSS](/packages/drewlabs-curl-client/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (21)Used By (9)

cURL Client
===========

[](#curl-client)

This project tends to implements an Object oriented PHP cURL client and provides a PSR18 implementation based on the cURL client object.

Installation
------------

[](#installation)

Recommended way to install the library is by using PHP package manager `composer` running the command below:

> composer require drewlabs/curl-client

Usage
-----

[](#usage)

The library comes with 2 cURL client, the 1st being an object oriented cURL class and PSR18 compatible client based on PHP cURL library.

### OOP cURL client

[](#oop-curl-client)

To create a new instance of the client, use the class constructor:

```
use Drewlabs\Curl\Client;

// Creates an instance of the cURL client
$client = new Client();
```

This will create a new client instance and initialize a new curl session. Developpers can pass a base url to the client instance to define the host server url:

```
use Drewlabs\Curl\Client;

// Creates an instance of the cURL client
$client = new Client('http://127.0.0.1:8000');

/ Passing request options to the cURL client
$client = new Client([
    'base_url' => 'http://127.0.0.1:5000',
    'headers' => [
        'Content-Type' => 'application/json',
    ],
    'cookies' => [
        'clientid' => '...',
        'clientsecret' => '...'
    ]
]);

// Create request client with a base URL
$client = new Client('http://127.0.0.1:5000');
```

#### Curl Options

[](#curl-options)

cURL options allow developpers to customize cURL request sent to the application server. Using `Client::setOption()` or `Client::setOptions()` for array like options, developpers can customize cURL requests being sent to the server.

```
use Drewlabs\Curl\Client;

// Creates an instance of the cURL client
$client = new Client(/* Parameters */);

$client->setOption(\CURLOPT_RETURNTRANSFER, false);
$client->setOption(\CURLOPT_WRITE, function($curl, $write) {
    // Listener for response output from the curl session
});
```

In order to pass cURL options as array, we use the `setOptions()` array method:

```
use Drewlabs\Curl\Client;

// Creates an instance of the cURL client
$client = new Client(/* Parameters */);

$client->setOptions([
    \CURLOPT_CUSTOMREQUEST  => 'POST',
    \CURLOPT_URL            => 'http://127.0.0.1:300/api/posts',
    \CURLOPT_RETURNTRANSFER => true,
    \CURLOPT_HEADER         => false,
    \CURLOPT_CONNECTTIMEOUT => 150,
]);
```

#### Sending cURL request

[](#sending-curl-request)

The client provides developpers with `Client::send()` method to send HTTP request to server:

```
use Drewlabs\Curl\Client;

// Creates an instance of the cURL client
$client = new Client(/* Parameters */);

// ... Use pre-configure cURL options
$client->send();

// Passing request options
$client->send([
    'headers' => [
        'Content-Type' => 'application/json'
    ],
    'body' => [
        'title' => 'Hello World'
    ]
]);

// To specify the request url when sending the request
$client->send('GET', 'http://127.0.0.1:3000/api/posts');

// or simply a path
$client->send(null, '/api/posts');

// To override or provide the request method
$client->send('POST', '/api/posts');
```

Sometimes you may have constructed the curl request and wish to simply execute the curl request. To do so the client mimic the curl `exec()` method by providing `Client::exec()` method for sending request to server.

```
use Drewlabs\Curl\Client;

// Creates an instance of the cURL client
$client = new Client(/* Parameters */);

$client->setRequestMethod('POST');
$client->setRequestUri('http://127.0.0.1:5000/api/posts');
$this->setOption(CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Accept: */*'
])
$client->setOption(\CURLOPT_POSTFIELDS, json_encode([/* JSON fields*/]));

// Execute the Curl request
$client->exec();
```

- Helper methods

The client comes with some helper method for basic curl HTTP options like, `CURLOPT_URL`, `\CURLOPT_SSL_VERIFYPEER`, `\CURLOPT_HTTP_VERSION` etc... Below is a brief API definition for most common use cases:

> `Client::setRequestUri(string $url)` - Set the request URI `Client::setRequestMethod(string $method)` - Set the request method `Client::setProtocolVersion(string $version)` - Set the HTTP protocol version `Client::withAutoReferer()` - Automatically set the auto referer header where it follows redirect `Client::followLocation()` - Follows any location redirect unless \\CURLOPT\_MAXREDIR is sets. `Client::maxRedirects(int $n)` - The number of redirect to be followed by the cURL client `Client::proxy($proxy, $port = null, $username = null, $password = null)` - Defines an HTTP proxy through which the request is forwarded. `Client::setUserAgent($user_agent)` - Defines the request user agent `Client::timeout(int $milliseconds)` - Timeout the request for a given milliseconds `Client::verifyHost()` - Make sure the cURL client validate host domain and SSL certificate

**Note**By default the cURL connection is closed the PHP runtime when the object is destructed. If developper which to close the curl session, or reset cURL parameters, the instance provides with `close()` and `release()` method for each specific case:

```
use Drewlabs\Curl\Client;

// Creates an instance of the cURL client
$client = new Client(/* Parameters */);

// Sending the cURL request
$client->send();

// Closing the cURL session
$client->close();

// or reset cURL resources
$client->release();
```

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance86

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~71 days

Recently: every ~251 days

Total

18

Last Release

66d ago

PHP version history (2 changes)v0.1.0PHP &gt;=7.0

v0.4.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/48c4973d500c7f4233d5ceacab51a57208d5fb60b0f95ae60264cf92380d0534?d=identicon)[azandrew-sidoine](/maintainers/azandrew-sidoine)

---

Top Contributors

[![azandrew-sidoine](https://avatars.githubusercontent.com/u/23530515?v=4)](https://github.com/azandrew-sidoine "azandrew-sidoine (44 commits)")

---

Tags

httpcurl

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/drewlabs-curl-client/health.svg)

```
[![Health](https://phpackages.com/badges/drewlabs-curl-client/health.svg)](https://phpackages.com/packages/drewlabs-curl-client)
```

###  Alternatives

[rmccue/requests

A HTTP library written in PHP, for human beings.

3.6k34.5M258](/packages/rmccue-requests)[nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

1.8k17.2M267](/packages/nategood-httpful)[mashape/unirest-php

Unirest PHP

1.3k9.7M161](/packages/mashape-unirest-php)[php-http/curl-client

PSR-18 and HTTPlug Async client with cURL

48247.0M384](/packages/php-http-curl-client)[smi2/phpclickhouse

PHP ClickHouse Client

83510.1M71](/packages/smi2-phpclickhouse)[pear/http_request2

Provides an easy way to perform HTTP requests.

764.2M48](/packages/pear-http-request2)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
