cURL class for PHP

Installs: 3 159 297

Dependents: 237

Suggesters: 2

Security: 0

Stars: 310

Watchers: 13

Forks: 117

Open Issues: 17

2.3.3 2021-11-30 20:19 UTC


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

Maintainability Test Coverage Total Downloads

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. Build and start the docker image (in tests/server) docker build . -t curlserver start docker run -p 1234:80 curlserver
  5. Run the unit tests ./vendor/bin/phpunit tests