PHPackages                             samuraee/easycurl - 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. samuraee/easycurl

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

samuraee/easycurl
=================

Super easy and flexible wrapper class for PHP cURL extension

v1.0.1(5y ago)39.0k↓48%3MITPHPPHP &gt;=7.0

Since Feb 24Pushed 5y ago1 watchersCompare

[ Source](https://github.com/samuraee/EasyCurl)[ Packagist](https://packagist.org/packages/samuraee/easycurl)[ Docs](https://github.com/samuraee/EasyCurl)[ RSS](/packages/samuraee-easycurl/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)DependenciesVersions (3)Used By (3)

EasyCurl
========

[](#easycurl)

Super easy and flexible wrapper class for PHP 7.0+ cURL extension

See [php.net/curl](http://php.net/curl) for more information about the libcurl extension for PHP.

It's a fairly simple library, so if you want something more powerful take a look at [Guzzle](https://github.com/guzzle/guzzle).

Install
-------

[](#install)

### via Composer (recommended)

[](#via-composer-recommended)

`composer require samuraee/easycurl '~1.0'`

### via download

[](#via-download)

Just grab the [latest release](https://github.com/samuraee/EasyCurl/releases).

Usage
-----

[](#usage)

### Initialization

[](#initialization)

```
try {
    $curl = new \Samuraee\EasyCurl();
} catch (Exception $e) {
    echo $e->getMessage();
}
```

### Performing request

[](#performing-request)

The EasyCurl object supports 5 types of requests: HEAD, GET, POST, PUT, and DELETE. You must specify an url to request and optionally specify an associative array or query string of variables to send along with it.

```
$response = $curl->head($url, $params);
$response = $curl->get($url, $params);
$response = $curl->post($url, $params);
$response = $curl->put($url, $params);
$response = $curl->delete($url, $params);
```

To use a custom request methods, you can call the `request` method:

```
$response = $curl->request($url, 'ANY_CUSTOM_REQUEST_TYPE', $params);
```

Examples:

```
$response = $curl->get('google.com?q=test');

$response = $curl->get('google.com?q=test', array('some_variable' => 'some_value'));
// EasyCurl will append '&some_variable=some_value' to the url

$response = $curl->post('test.com/posts', array('title' => 'Test', 'body' => 'This is a test'));
```

All requests return response body as is or throw a EasyCurlException if an error occurred.

### Performing POST/PUT request with raw payload

[](#performing-postput-request-with-raw-payload)

Some times you need to send not encoded POST params, but a raw JSON or other raw data format.

```
$response = $curl->rawPost($url, $jsonData);
$response = $curl->rawPut($url, 'raw random data');
```

Note that data is sending as as, without any URL-encoding manipulation. Keep that in mind.

You might also need to change the content type header for those types of request:

```
$curl->addHeader('Content-Type', 'text/plain');
// or
$curl->addHeader('Content-Type', 'application/json');
// and then
$response = $curl->rawPost($url, $jsonData);
```

It depends on API server-side you are working with.

### Getting additional information about request sent

[](#getting-additional-information-about-request-sent)

```
$info = $curl->getTransferInfo();
```

This will give you associative array with following keys:

- `url` - Last effective URL
- `content_type` - Content-Type: of downloaded object, NULL indicates server did not send valid Content-Type: header
- `http_code` - Last received HTTP code
- `header_size` - Total size of all headers received
- `request_size` - Total size of issued requests, currently only for HTTP requests
- `filetime` - Remote time of the retrieved document, if -1 is returned the time of the document is unknown
- `ssl_verify_result` - Result of SSL certification verification requested by setting CURLOPT\_SSL\_VERIFYPEER
- `redirect_count` - Number of redirects it went through if CURLOPT\_FOLLOWLOCATION was set
- `total_time` - Total transaction time in seconds for last transfer
- `namelookup_time` - Time in seconds until name resolving was complete
- `connect_time` - Time in seconds it took to establish the connection
- `pretransfer_time` - Time in seconds from start until just before file transfer begins
- `size_upload` - Total number of bytes uploaded
- `size_download` - Total number of bytes downloaded
- `speed_download` - Average download speed
- `speed_upload` - Average upload speed
- `download_content_length` - content-length of download, read from Content-Length: field
- `upload_content_length` - Specified size of upload
- `starttransfer_time` - Time in seconds until the first byte is about to be transferred
- `redirect_time` - Time in seconds of all redirection steps before final transaction was started
- `certinfo` - There is official description for this field yet
- `request_header` - The request string sent. For this to work, add the CURLINFO\_HEADER\_OUT option

You can also easily fetch any single piece of this array:

```
$httpCode = $curl->getTransferInfo('http_code');
```

### Cookie sessions

[](#cookie-sessions)

To maintain a session across requests and cookies support you must set file's name where cookies to store:

```
$curl->setCookieFile('some_file_name.txt');
```

This file must be writable or the EasyCurlException will be thrown.

### Basic configuration options

[](#basic-configuration-options)

You can easily set the referer, user-agent, timeout and whether or not follow redirects:

```
$curl->setReferer('http://google.com');
$curl->setUserAgent('some user agent string');
$curl->setTimeout(15); // seconds
$curl->setFollowRedirects(true); // to follow redirects
```

### HTTP Basic Authentication

[](#http-basic-authentication)

You can set a username and password for use in HTTP basic auth:

```
$curl->setAuthType();
$curl->setAuthCredentials('username', 'password');
```

### Setting custom headers

[](#setting-custom-headers)

You can set custom headers to send with the request:

```
$curl->addHeader('Host', '98.52.78.243');
$curl->addHeader('Some-Custom-Header', 'Some Custom Value');
```

Or use a single array:

```
$curl->addHeader(array('Host'=>'98.52.78.243', 'Some-Custom-Header'=>'Some Custom Value'));
```

### Setting custom cURL options

[](#setting-custom-curl-options)

You can set/override any cURL option (see the [curl\_setopt documentation](http://www.php.net/manual/en/function.curl-setopt.php) for a list of them):

```
$curl->addOption(CURLOPT_AUTOREFERER, true);
```

Contributing
------------

[](#contributing)

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity49

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 ~36 days

Total

2

Last Release

1873d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9299d1f63e54a717d0b785253adc636f90c3b460ae9bd24bfc1505ef5f90f1ec?d=identicon)[tartan](/maintainers/tartan)

---

Top Contributors

[![samuraee](https://avatars.githubusercontent.com/u/502961?v=4)](https://github.com/samuraee "samuraee (2 commits)")

---

Tags

httphelpercurlhttp clientutil

### Embed Badge

![Health badge](/badges/samuraee-easycurl/health.svg)

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

###  Alternatives

[smi2/phpclickhouse

PHP ClickHouse Client

84310.1M71](/packages/smi2-phpclickhouse)[aplus/http-client

Aplus Framework HTTP Client Library

2161.6M1](/packages/aplus-http-client)[svyatov/curlwrapper

Flexible wrapper class for PHP cURL extension

5596.6k3](/packages/svyatov-curlwrapper)[zoonman/pixabay-php-api

PixabayClient is a PHP HTTP client library to access Pixabay's API

3354.7k](/packages/zoonman-pixabay-php-api)[phpgt/fetch

Asynchronous HTTP client with promises.

3724.0k3](/packages/phpgt-fetch)[kelvinzer0/curl-impersonate-php

Curl-Impersonate-PHP - Library to execute HTTP requests using cURL in PHP with the ability to impersonate the behavior of major browsers (Chrome, Firefox, Safari, and Microsoft Edge).

2246.1k2](/packages/kelvinzer0-curl-impersonate-php)

PHPackages © 2026

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