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

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

veqryn/curl
===========

PHP Wrapper for Curl

v2.0.0(11y ago)231.6k↓34.6%1MITPHPPHP &gt;=5.3.0CI failing

Since Jun 2Pushed 11y ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (4)Used By (0)

curl
====

[](#curl)

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

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

[](#installation)

Click the `download` link above or `git clone git@github.com:veqryn/curl.git`

To install into your project, add these lines to your composer.json:

```
"require": {
    "veqryn/curl": "*"
}

```

Usage
-----

[](#usage)

### Initialization

[](#initialization)

Simply require and initialize the `Curl` class like so:

```
require_once('vendor/autoload.php');

use veqryn\Curl\Curl;
use veqryn\Curl\CurlResponse;
use veqryn\Curl\CurlException;

// ...

$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:

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

```

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 throw a CurlException 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 [phpunit](https://phpunit.de/). Simply run phpunit in the 'test' directory. Example on linux (assuming php is on your path):

```
cd /test
../vendor/bin/phpunit

```

Contact
-------

[](#contact)

Problems, comments, and suggestions all welcome:  and/or VEQRYN \[at\] hotmail dot com

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

3

Last Release

4182d ago

Major Versions

v1.1.0 → v2.0.02014-12-05

### Community

Maintainers

![](https://www.gravatar.com/avatar/232a342e039abc0420fae50d3d8c2ab7d69fcfc3370d11863020dc5ffda93d5d?d=identicon)[veqryn](/maintainers/veqryn)

---

Top Contributors

[![shuber](https://avatars.githubusercontent.com/u/2419?v=4)](https://github.com/shuber "shuber (14 commits)")[![veqryn](https://avatars.githubusercontent.com/u/1897829?v=4)](https://github.com/veqryn "veqryn (7 commits)")[![weppos](https://avatars.githubusercontent.com/u/5387?v=4)](https://github.com/weppos "weppos (7 commits)")[![hamstar](https://avatars.githubusercontent.com/u/141157?v=4)](https://github.com/hamstar "hamstar (4 commits)")[![KendallHopkins](https://avatars.githubusercontent.com/u/72923?v=4)](https://github.com/KendallHopkins "KendallHopkins (3 commits)")[![xsist10](https://avatars.githubusercontent.com/u/415488?v=4)](https://github.com/xsist10 "xsist10 (2 commits)")[![Josiah](https://avatars.githubusercontent.com/u/77621?v=4)](https://github.com/Josiah "Josiah (1 commits)")[![bjeavons](https://avatars.githubusercontent.com/u/94468?v=4)](https://github.com/bjeavons "bjeavons (1 commits)")

---

Tags

phpcurlwrapperbotspiderscraper

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[shuber/curl

PHP Wrapper for Curl

311.1M2](/packages/shuber-curl)[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)[khr/php-mcurl-client

wrap curl client (http client) for PHP 5.3; using php multi curl, parallel request and write asynchronous code

71219.8k6](/packages/khr-php-mcurl-client)

PHPackages © 2026

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