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

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

bensquire/curl
==============

A simple PHP curl wrapper.

02871PHP

Since Nov 3Pushed 11y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)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/shuber/curl.git`

Usage
-----

[](#usage)

### Initialization

[](#initialization)

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

```
require_once 'curl.php';
$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

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 63.6% 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.

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

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