cURL class for PHP

Installs: 1 543 071

Dependents: 206

Suggesters: 2

Security: 0

Stars: 272

Watchers: 12

Forks: 103

Open Issues: 13

2.3.0 2020-03-19 20:07 UTC


This library provides an object-oriented wrapper of the PHP cURL extension.

If you have questions or problems with installation or usage create an Issue.


In order to install this library via composer run the following command in the console:

composer require curl/curl

or add the package manually to your composer.json file in the require section:

"curl/curl": "^2.0"

Usage examples

$curl = new Curl\Curl();
$curl = new Curl\Curl();
$curl->get('', array(
    'q' => 'keyword',
$curl = new Curl\Curl();
$curl->post('', array(
    'username' => 'myusername',
    'password' => 'mypassword',
$curl = new Curl\Curl();
$curl->setBasicAuthentication('username', 'password');
$curl->setHeader('X-Requested-With', 'XMLHttpRequest');
$curl->setCookie('key', 'value');

if ($curl->error) {
    echo $curl->error_code;
else {
    echo $curl->response;

$curl = new Curl\Curl();
$curl = new Curl\Curl();
$curl->put('', array(
    'first_name' => 'Zach',
    'last_name' => 'Borboa',
$curl = new Curl\Curl();
$curl->patch('', array(
    'image' => '@path/to/file.jpg',
$curl = new Curl\Curl();
$curl->delete('', array(
    'id' => '1234',
// Example access to curl object.
curl_set_opt($curl->curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1');
// Example of downloading a file or any other content
$curl = new Curl\Curl();
// open the file where the request response should be written
$file_handle = fopen($target_file, 'w+');
// pass it to the curl resource
$curl->setOpt(CURLOPT_FILE, $file_handle);
// do any type of request
// disable writing to file
$curl->setOpt(CURLOPT_FILE, null);
// close the file for writing


In order to test the library:

  1. Create a fork
  2. Clone the fork to your machine
  3. Install the depencies composer install
  4. Run the unit tests ./vendor/bin/phpunit tests