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

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

shuber/curl
===========

PHP Wrapper for Curl

v1.0.0(13y ago)311.1M—0.6%13[4 PRs](https://github.com/hamstar/curl/pulls)2MITPHP

Since Jun 2Pushed 4y ago2 watchersCompare

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

READMEChangelogDependenciesVersions (2)Used By (2)

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

42

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity49

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity63

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

Unknown

Total

1

Last Release

5098d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5921f0047897a3542b1ef8cabfebe898ec9a4e0b0c16086f2014318234439b06?d=identicon)[hamstar](/maintainers/hamstar)

---

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)")[![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)")[![bjeavons](https://avatars.githubusercontent.com/u/94468?v=4)](https://github.com/bjeavons "bjeavons (1 commits)")[![Josiah](https://avatars.githubusercontent.com/u/77621?v=4)](https://github.com/Josiah "Josiah (1 commits)")

---

Tags

curlbotspiderscraper

### Embed Badge

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

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

###  Alternatives

[rmccue/requests

A HTTP library written in PHP, for human beings.

3.6k34.5M258](/packages/rmccue-requests)[php-http/curl-client

PSR-18 and HTTPlug Async client with cURL

48347.0M384](/packages/php-http-curl-client)[smi2/phpclickhouse

PHP ClickHouse Client

84310.1M71](/packages/smi2-phpclickhouse)[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)[crwlr/robots-txt

Robots Exclusion Standard/Protocol Parser for Web Crawling/Scraping

1125.3k1](/packages/crwlr-robots-txt)[msankhala/parsehub-php

Php wrapper classes for Parsehub REST api.

1312.4k](/packages/msankhala-parsehub-php)

PHPackages © 2026

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