PHPackages                             webiik/curlhttpclient - 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. webiik/curlhttpclient

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

webiik/curlhttpclient
=====================

The CurlHttpClient allows to easily send HTTP request via curl.

1.0(7y ago)01042MITPHPPHP &gt;=7.2

Since Feb 28Pushed 7y ago1 watchersCompare

[ Source](https://github.com/webiik/curl-http-client)[ Packagist](https://packagist.org/packages/webiik/curlhttpclient)[ Docs](https://www.webiik.com)[ RSS](/packages/webiik-curlhttpclient/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (2)Used By (2)

[![](https://camo.githubusercontent.com/a397347ee4fb199934fee6354504f4702b89f5c22f0ce0ba94c5ff691cde545c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77656269696b2f77656269696b2e737667)](https://camo.githubusercontent.com/a397347ee4fb199934fee6354504f4702b89f5c22f0ce0ba94c5ff691cde545c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77656269696b2f77656269696b2e737667)[![](https://camo.githubusercontent.com/20f4b99a958aadb02ff273ac6428c17cf55c6b817657ed64b1c39c7f71955a0e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d302d627269676874677265656e2e737667)](https://camo.githubusercontent.com/20f4b99a958aadb02ff273ac6428c17cf55c6b817657ed64b1c39c7f71955a0e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d302d627269676874677265656e2e737667)

CurlHttpClient
==============

[](#curlhttpclient)

The CurlHttpClient allows to easily send HTTP request via cURL.

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

[](#installation)

```
composer require webiik/curlhttpclient
```

Example
-------

[](#example)

```
$chc = new \Webiik\CurlHttpClient\CurlHttpClient();

// Prepare simple GET request (CurlHttpClientReq)
$request = $chc->prepareRequest('https://www.google.com');

// Send request and receive response (CurlHttpClientRes)
$response = $chc->send($req);
```

Summary
-------

[](#summary)

- [Client](#curlhttpclient)
- [Preparing Requests](#curlhttpclientreq)
- [Processing Responses](#curlhttpclientres)

CurlHttpClient
--------------

[](#curlhttpclient-1)

CurlHttpClient prepares cURL requests represented by CurlHttpClientReq, sends cURL requests and receives cURL responses represented by CurlHttpClientRes. It allows you to send asynchronously multiple requests at once.

### prepareRequest

[](#preparerequest)

```
prepareRequest(string $url): CurlHttpClientReq
```

**prepareRequest()** creates object [CurlHttpClientReq](#curlhttpclientreq) which represents set of cURL options.

```
$request = $chc->prepareRequest('https://www.google.com');
```

### send

[](#send)

```
send(CurlHttpClientReq $req): CurlHttpClientRes
```

**send()** sends cURL request using the options defined in CurlHttpClientReq, returns [CurlHttpClientRes](#curlhttpclientres).

```
$response = $chc->send($req);
```

### sendMulti

[](#sendmulti)

```
sendMulti(array $requests): array
```

**sendMulti()** sends asynchronously multiple cURL requests at once. Once all requests are completed, it receives array of CurlHttpClientRes.

```
// Prepare multiple requests
$requests = [
    $chc->prepareRequest('https://www.google.com'),
    $chc->prepareRequest('https://duck.com'),
];

// Send asynchronously multiple requests at once
// Once all requests are completed, get their responses
$responses = $chc->sendMulti($requests);

// Iterate responses
foreach ($responses as $res) {
    /** @var \Webiik\CurlHttpClient\CurlHttpClientRes $res */
}
```

CurlHttpClientReq
-----------------

[](#curlhttpclientreq)

CurlHttpClientReq represents set of cURL options. It provides many methods to easily add most common cURL options.

### Connection settings

[](#connection-settings)

---

### url

[](#url)

```
url(string $url): CurlHttpClientReq
```

**url()** sets URL to connect to.

```
$request->url('https://www.google.com');
```

### method

[](#method)

```
method(string $method): CurlHttpClientReq
```

**method()** sets connection method e.g. GET, POST...

```
$request->method('POST');
```

### port

[](#port)

```
port(int $port): CurlHttpClientReq
```

**port()** sets port to connect to.

```
$request->port('1212');
```

### followLocation

[](#followlocation)

```
followLocation(bool $follow, int $maxRedirs = -1, bool $autoReferrer = false): CurlHttpClientReq
```

**followLocation()** sets to follow redirects.

```
$request->followLocation(true);
```

### auth

[](#auth)

```
auth(string $user, string $password, int $authMethod = CURLAUTH_ANY): CurlHttpClientReq
```

**auth()** sets authentication credentials.

```
$request->auth('user', 'password');
```

### proxy

[](#proxy)

```
proxy(string $proxyUrl, string $user = '', string $password = '', int $authMethod = CURLAUTH_BASIC): CurlHttpClientReq
```

**proxy()** set proxy to connect through.

```
$request->proxy('socks5://xxx.xxx.xxx.xxx', 'user', 'password');
```

### verifySSL

[](#verifyssl)

```
verifySSL(bool $bool): CurlHttpClientReq
```

**verifySSL()** sets to check SSL connection or not.

```
$request->verifySSL(false);
```

### connectTimeout

[](#connecttimeout)

```
connectTimeout(int $sec): CurlHttpClientReq
```

**connectTimeout()** sets cURL connection timeout. 0 - wait indefinitely.

```
$request->connectTimeout(1);
```

### executionTimeout

[](#executiontimeout)

```
executionTimeout(int $sec): CurlHttpClientReq
```

**executionTimeout()** set cURL transfer timeout. 0 - never quit during transfer.

```
$request->executionTimeout(1);
```

### lowSpeedLimit

[](#lowspeedlimit)

```
lowSpeedLimit(int $bytes, int $sec): CurlHttpClientReq
```

**lowSpeedLimit()** disconnects cURL if it's slower than **$bytes**/sec for **$sec** seconds.

```
// Disconnect when cURL connection speed is lower than 128KB for 10 seconds
$request->lowSpeedLimit(1024 * 128, 10);
```

### Data To Send

[](#data-to-send)

---

### userAgent

[](#useragent)

```
userAgent(string $agent): CurlHttpClientReq
```

**userAgent()** sets user agent HTTP header.

```
$request->userAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.3 Safari/605.1.15');
```

### referrer

[](#referrer)

```
referrer(string $url): CurlHttpClientReq
```

**referrer()** sets referrer HTTP header.

```
$request->referrer('https://www.google.com');
```

### header

[](#header)

```
header(string $header): CurlHttpClientReq
```

**header()** sets HTTP header in format e.g. 'Content-type: image/jpeg'.

```
$request->header('Content-Type: image/jpeg');
```

### headers

[](#headers)

```
headers(array $headers): CurlHttpClientReq
```

**headers()** sets array of HTTP headers in format e.g. \['Content-type: image/jpeg',...\]

```
$request->header([
    'Content-Disposition: attachment; filename="cute-cat.jpg"',
    'Content-Type: image/jpeg',
]);
```

### mimicAjax

[](#mimicajax)

```
mimicAjax(): CurlHttpClientReq
```

**mimicAjax()** sets HTTP header to mimic ajax.

```
$request->mimicAjax();
```

### cookie

[](#cookie)

```
cookie(string $name, string $val): CurlHttpClientReq
```

**cookie()** sets 'Cookie' HTTP header.

```
$request->cookie('cat', 'Tom');
```

### cookieFile

[](#cookiefile)

```
cookieFile(string $path): CurlHttpClientReq
```

**cookieFile()** sets cookie(s) from file.

```
$request->cookieFile('cookies.txt');
```

### cookieJar

[](#cookiejar)

```
cookieJar(string $path): CurlHttpClientReq
```

**cookieJar()** catches response cookie(s) to file.

```
$request->cookieJar('cookies.txt');
```

### resetCookie

[](#resetcookie)

```
resetCookie(): CurlHttpClientReq
```

**resetCookie()** sets cURL to ignore all previous cookies.

```
$request->resetCookie();
```

### postData

[](#postdata)

```
postData(array $fields, array $curlFiles = []): CurlHttpClientReq
```

**postData()** adds post data to cURL request.

```
$request->postData($_POST, $_FILES);
```

### upload

[](#upload)

```
upload(string $file, int $chunk = 8192): CurlHttpClientReq
```

**upload()** sets cURL to upload local file to remote server. **$file** is local file to be uploaded to remote server.

```
// Set address to upload to
$request = $chc->prepareRequest('ftp://yourftp.tld');

// Set auth credentials (when required)
$request->auth('user', 'password');

// Set local file to upload
$request->upload('cute-cat.jpg');

// Init uploading
$chc->send($request);
```

### uploadSpeedLimit

[](#uploadspeedlimit)

```
uploadSpeedLimit(int $bytesSec): CurlHttpClientReq
```

**uploadSpeedLimit()** sets max upload speed in bytes per second.

```
// Limit upload speed to 1 MB/s
$request->uploadSpeedLimit(1024 * 1024);
```

### Data To Receive

[](#data-to-receive)

---

### encoding

[](#encoding)

```
encoding(string $encoding): CurlHttpClientReq
```

**encoding()** sets response encoding. Supported encodings are "identity", "deflate", and "gzip".

```
$request->encoding('deflate');
```

### receiveBody

[](#receivebody)

```
receiveBody(bool $bool): CurlHttpClientReq
```

**receiveBody()** determines to receive response body or not.

```
$request->receiveBody(true);
```

### receiveHeaders

[](#receiveheaders)

```
receiveHeaders(bool $bool): CurlHttpClientReq
```

**receiveHeaders()** determines to receive response headers or not.

```
$request->receiveHeaders(true);
```

### receiveAsString

[](#receiveasstring)

```
receiveAsString(bool $bool): CurlHttpClientReq
```

**receiveAsString()** sets cURL to return cURL response as a string instead of outputting it directly.

```
$request->receiveAsString(true);
```

### downloadToServer

[](#downloadtoserver)

```
downloadToServer(string $file, int $chunk = 8192): CurlHttpClientReq
```

**downloadToServer()** sets cURL to download remote file to local server. **$file** is used as a storage of remote file.

```
// Set remote file to download
$request = $chc->prepareRequest('https://domain.tld/cute-cat.jpg');

// Set local file to download to
$request->downloadToServer('cute-cat.jpg');

// Init downloading
$chc->send($request);
```

### downloadToClient

[](#downloadtoclient)

```
downloadToClient(int $chunk = 8192): CurlHttpClientReq
```

**downloadToClient()** sets cURL to stream remote file to client.

```
// Set remote file to stream
$request = $chc->prepareRequest('https://domain.tld/cute-cat.jpg');

// Tell cURL to stream remote file to client
$request->downloadToClient();

// Set appropriate headers
header('Content-Disposition: attachment; filename="cute-cat.jpg"');
header('Content-Type: image/jpeg');

// Init streaming
$chc->send($request);
```

### downloadSpeedLimit

[](#downloadspeedlimit)

```
downloadSpeedLimit(int $bytesSec): CurlHttpClientReq
```

**downloadSpeedLimit()** sets max download speed in bytes per second.

```
// Limit download speed to 1 MB/s
$request->downloadSpeedLimit(1024 * 1024);
```

### Custom

[](#custom)

---

### verbose

[](#verbose)

```
verbose(bool $bool): CurlHttpClientReq
```

**verbose()** sets cURL to receive verbose response info.

```
$request->verbose(true);
```

### curlOption

[](#curloption)

```
curlOption(int $option, $val): CurlHttpClientReq
```

**curlOption()** sets a cURL option.

```
$request->curlOption(CURLOPT_TCP_NODELAY, 1);
```

### curlOptions

[](#curloptions)

```
curlOptions(array $options): CurlHttpClientReq
```

**curlOptions()** sets an array of cURL options.

```
$request->curlOptions([
	CURLOPT_TCP_NODELAY => 1,
	CURLOPT_FORBID_REUSE => 1,
]);
```

### progressFile

[](#progressfile)

```
progressFile(string $uniqueName, string $dir): CurlHttpClientReq
```

**progressFile()** sets a file to store download/upload progress to. Progress is stored in JSON format.

```
$request->progressFile('fu37icnj', __DIR__);
```

### progressJson

[](#progressjson)

```
progressJson(): CurlHttpClientReq
```

**progressJson()** sets cURL to print upload/download progress as a JSON (without content-type header).

```
$request->progressJson();
```

CurlHttpClientRes
-----------------

[](#curlhttpclientres)

CurlHttpClientRes represents cURL response. It provides methods to easily access most common response informations.

### header

[](#header-1)

```
header(string $name, bool $sensitive = true, bool $raw = false)
```

**header()** gets response header by header name.

**Parameters**

- **name** header name
- **sensitive** determines if header name is case sensitive
- **raw** determines to return only header value(false) or complete header(true)

```
$header = $response->header('Content-Type');
```

### headers

[](#headers-1)

```
headers(): array
```

**headers()** gets array of all response headers.

```
$headers = $response->headers();
```

### cookie

[](#cookie-1)

```
cookie(string $name, bool $sensitive = true, bool $raw = false)
```

**cookie()** gets response cookie value by cookie name.

**Parameters**

- **name** cookie name
- **sensitive** determines if cookie name is case sensitive
- **raw** determines to return only cookie value(false) or complete cookie header(true)

```
$cookie = $response->cookie('cat');
```

### cookies

[](#cookies)

```
cookies(): array
```

**cookies()** gets array of all response cookie headers.

```
$cookies = $response->cookies();
```

### cookiesAssoc

[](#cookiesassoc)

```
cookiesAssoc(): array
```

**cookiesAssoc()** gets associative array of all response cookies.

```
$cookies = $response->cookiesAssoc();
```

### body

[](#body)

```
body(): string
```

**body()** gets response body.

```
$body = $response->body();
```

### size

[](#size)

```
size(): int
```

**size()** gets response size in bytes.

```
$size = $response->size();
```

### mime

[](#mime)

```
mime(): string
```

**mime()** gets response content type.

```
$mime = $response->mime();
```

### statusCode

[](#statuscode)

```
statusCode(): int
```

**statusCode()** gets response HTTP status code.

```
$httpStatusCode = $response->statusCode();
if ($httpStatusCode == 200) {
    // Remote page responded with HTTP status OK
}
```

### errMessage

[](#errmessage)

```
errMessage(): string
```

**errMessage()** gets cURL error message.

```
$curlErrMessage = $response->errMessage();
```

### errNum

[](#errnum)

```
errNum(): int
```

**errNum()** gets cURL error number.

```
$curlErrNum = $response->errNum();
if (!$curlErrNum) {
    // Curl request is OK
}
```

### isOk

[](#isok)

```
isOk(): bool
```

**isOk()** indicates if cURL request was ok.

```
if ($response->isOk()) {
    // Curl request is OK
}
```

### info

[](#info)

```
info(): array
```

**info()** gets cURL info array.

```
$curlInfo = $response->info();
```

### requestHeaders

[](#requestheaders)

```
requestHeaders(): array
```

**requestHeaders()** gets array of all request headers.

```
$requestHeaders = $response->requestHeaders();
```

### requestCookies

[](#requestcookies)

```
requestCookies(): array
```

**requestCookies()** gets array of all request cookie headers.

```
$requestCookies = $response->requestCookies();
```

Resources
---------

[](#resources)

- [Webiik framework](https://github.com/webiik/webiik)
- [Report issue](https://github.com/webiik/components/issues)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity55

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

Unknown

Total

1

Last Release

2627d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1226362d003d186b45e7dfa44489c36af37196c6a1b476206700eaf4e9c96a5a?d=identicon)[Jiri Mihal](/maintainers/Jiri%20Mihal)

---

Top Contributors

[![Jiri-Mihal](https://avatars.githubusercontent.com/u/10408123?v=4)](https://github.com/Jiri-Mihal "Jiri-Mihal (143 commits)")

---

Tags

httpclientcurl

### Embed Badge

![Health badge](/badges/webiik-curlhttpclient/health.svg)

```
[![Health](https://phpackages.com/badges/webiik-curlhttpclient/health.svg)](https://phpackages.com/packages/webiik-curlhttpclient)
```

###  Alternatives

[swlib/saber

Swoole coroutine HTTP client

985145.0k27](/packages/swlib-saber)[aplus/http-client

Aplus Framework HTTP Client Library

2161.6M1](/packages/aplus-http-client)

PHPackages © 2026

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