PHPackages                             carlescliment/curl - 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. carlescliment/curl

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

carlescliment/curl
==================

A basic CURL wrapper for PHP.

1.0.1(12y ago)077221PHPPHP &gt;=5.3.2

Since Oct 24Pushed 12y ago1 watchersCompare

[ Source](https://github.com/carlescliment/curl)[ Packagist](https://packagist.org/packages/carlescliment/curl)[ RSS](/packages/carlescliment-curl/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (3)Used By (1)

curl
====

[](#curl)

A basic CURL wrapper for PHP (see  for more information about the libcurl extension for PHP)

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

[](#installation)

Add this line to your composer.json:

```
"require": {
    // ...
    "shuber/curl": "*"
}

```

Usage
-----

[](#usage)

### Initialization

[](#initialization)

Composer should autoload the package, so you just need to include it

```
use shuber\Curl\Curl;

$curl = new Curl;

```

### Performing a Request

[](#performing-a-request)

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

```
$response = $curl->head($url, $vars = array());
$response = $curl->get($url, $vars = array()); # The Curl object will append the array of $vars to the $url as a query string
$response = $curl->post($url, $vars = array());
$response = $curl->put($url, $vars = array());
$response = $curl->delete($url, $vars = array());

```

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

```
$response = $curl->request('YOUR_CUSTOM_REQUEST_TYPE', $url, $vars = array());

```

All of the built in request methods like `put` and `get` simply wrap the `request` method. For example, the `post` method is implemented like:

```
function post($url, $vars = array()) {
    return $this->request('POST', $url, $vars);
}

```

Examples:

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

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

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

```

All requests return a CurlResponse object (see below) or false if an error occurred. You can access the error string with the `$curl->error()` method.

### The CurlResponse Object

[](#the-curlresponse-object)

A normal CURL request will return the headers and the body in one response string. This class parses the two and places them into separate properties.

For example

```
$response = $curl->get('google.com');
echo $response->body; # A string containing everything in the response except for the headers
print_r($response->headers); # An associative array containing the response headers

```

Which would display something like

```

Google.com

Some more html...

Array
(
    [Http-Version] => 1.0
    [Status-Code] => 200
    [Status] => 200 OK
    [Cache-Control] => private
    [Content-Type] => text/html; charset=ISO-8859-1
    [Date] => Wed, 07 May 2008 21:43:48 GMT
    [Server] => gws
    [Connection] => close
)

```

The CurlResponse class defines the magic [\_\_toString()](http://php.net/__toString) method which will return the response body, so `echo $response` is the same as `echo $response->body`

### Cookie Sessions

[](#cookie-sessions)

By default, cookies will be stored in a file called `curl_cookie.txt`. You can change this file's name by setting it like this

```
$curl->cookie_file = 'some_other_filename';

```

This allows you to maintain a session across requests

### Basic Configuration Options

[](#basic-configuration-options)

You can easily set the referer or user-agent

```
$curl->referer = 'http://google.com';
$curl->user_agent = 'some user agent string';

```

You may even set these headers manually if you wish (see below)

### Setting Custom Headers

[](#setting-custom-headers)

You can set custom headers to send with the request

```
$curl->headers['Host'] = 12.345.678.90;
$curl->headers['Some-Custom-Header'] = 'Some Custom Value';

```

### Setting Custom CURL request options

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

By default, the `Curl` object will follow redirects. You can disable this by setting:

```
$curl->follow_redirects = false;

```

You can set/override many different options for CURL requests (see the [curl\_setopt documentation](http://php.net/curl_setopt) for a list of them)

```
# any of these will work
$curl->options['AUTOREFERER'] = true;
$curl->options['autoreferer'] = true;
$curl->options['CURLOPT_AUTOREFERER'] = true;
$curl->options['curlopt_autoreferer'] = true;

```

Testing
-------

[](#testing)

Uses [ztest](http://github.com/jaz303/ztest), simply download it to `path/to/curl/test/ztest` (or anywhere else in your php include\_path)

Then run `test/runner.php`

Contact
-------

[](#contact)

Problems, comments, and suggestions all welcome:

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

Total

2

Last Release

4585d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c2a85fbd3df7cb8270d08d62ca42ba012b02cad5ff2a146dcc544ca658f92689?d=identicon)[carlescliment](/maintainers/carlescliment)

---

Top Contributors

[![shuber](https://avatars.githubusercontent.com/u/2419?v=4)](https://github.com/shuber "shuber (14 commits)")[![carlescliment](https://avatars.githubusercontent.com/u/1255401?v=4)](https://github.com/carlescliment "carlescliment (8 commits)")[![weppos](https://avatars.githubusercontent.com/u/5387?v=4)](https://github.com/weppos "weppos (7 commits)")

---

Tags

phpcurl

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[stefangabos/zebra_curl

A high performance solution for making multiple HTTP requests concurrently, asynchronously from your PHP projects using cURL

21971.3k2](/packages/stefangabos-zebra-curl)[ismaeltoe/osms

PHP library wrapper of the Orange SMS API.

4540.0k](/packages/ismaeltoe-osms)

PHPackages © 2026

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