php-curl-class is a free, open source api development & testing project written in PHP and released under Unlicense. It has 3,297 GitHub stars, 801 forks and 0 open issues, and was last pushed 6 hours ago. On this registry it ranks #64 of 103 tracked projects in API Development & Testing, with 5 head-to-head comparisons available.

What is php-curl-class?

What it is

PHP Curl Class is a PHP library for sending HTTP requests and integrating with web APIs. It lives in the PHP ecosystem and presents cURL work through a class-based interface for request methods, response handling, and configuration. The project is published under the Unlicense, has 3296 stars, 801 forks, and a repository age of 13 years.

The concrete problem it solves is the repetitive plumbing of HTTP calls in PHP applications. Developers need to make GET, POST, PUT, PATCH, and DELETE requests, attach authentication, headers, cookies, and query parameters, follow redirects, inspect response headers, and download files. PHP Curl Class gives a focused tool for these tasks without requiring each project to write its own cURL wrapper.

Key capabilities

  • It sends GET, POST, PUT, PATCH, and DELETE requests through a Curl class, including query parameters and request bodies.
  • It sets basic authentication, user agent, referrer, custom headers, and cookies before a request is made.
  • It exposes request headers, response headers, response data, error state, error message, and a diagnose method for failed calls.
  • It supports redirect following with setFollowLocation, and can download files to a local path.
  • It can submit file data through PATCH examples that use a CURLFile object, and its topics include api-client, http-client, http-proxy, and JSON.

Who uses it and how

  • PHP application developers use it to call external web APIs from server-side code, including login submissions and user profile updates.
  • API integration and debugging work uses it to attach authentication, set custom headers, send request bodies, inspect response headers, and diagnose failed calls.
  • File transfer workflows use it to download files or send file data through PATCH requests.

Getting started

The README says to install the package with composer require php-curl-class/php-curl-class, or to use the latest commit version with composer require php-curl-class/php-curl-class @dev. It requires PHP 8.5, 8.4, 8.3, 8.2, 8.1, or 8.0.

When to use it — and when not to

Use PHP Curl Class when a PHP project needs a cURL wrapper for API calls, login submissions, file downloads, and request inspection. The provided facts do not list a paid product it replaces, and the README mentions no hosted option, so users install it as a Composer dependency and run it inside their own PHP application. The supported PHP versions begin at 8.0, and the contributor count is not shown.

project readme (upstream, from github) — read inline

PHP Curl Class: HTTP requests made easy

PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs.

PHP Curl Class screencast



⚙️ Installation

To install PHP Curl Class, run the following command:

composer require php-curl-class/php-curl-class

To install the latest commit version:

composer require php-curl-class/php-curl-class @dev

Installation instructions to use the composer command can be found on https://github.com/composer/composer.

📋 Requirements

PHP Curl Class works with PHP versions 8.5, 8.4, 8.3, 8.2, 8.1, and 8.0.

🚀 Quick Start and Examples

More examples are available under /examples.

require __DIR__ . '/vendor/autoload.php';

use Curl\Curl;

$curl = new Curl();
$curl->get('https://www.example.com/');

if ($curl->error) {
    echo 'Error: ' . $curl->errorMessage . "\n";
    $curl->diagnose();
} else {
    echo 'Response:' . "\n";
    var_dump($curl->response);
}
// https://www.example.com/search?q=keyword
$curl = new Curl();
$curl->get('https://www.example.com/search', [
    'q' => 'keyword',
]);
$curl = new Curl();
$curl->post('https://www.example.com/login/', [
    'username' => 'myusername',
    'password' => 'mypassword',
]);
$curl = new Curl();
$curl->setBasicAuthentication('username', 'password');
$curl->setUserAgent('MyUserAgent/0.0.1 (+https://www.example.com/bot.html)');
$curl->setReferrer('https://www.example.com/url?url=https%3A%2F%2Fwww.example.com%2F');
$curl->setHeader('X-Requested-With', 'XMLHttpRequest');
$curl->setCookie('key', 'value');
$curl->get('https://www.example.com/');

if ($curl->error) {
    echo 'Error: ' . $curl->errorMessage . "\n";
} else {
    echo 'Response:' . "\n";
    var_dump($curl->response);
}

var_dump($curl->requestHeaders);
var_dump($curl->responseHeaders);
$curl = new Curl();
$curl->setFollowLocation();
$curl->get('https://shortn.example.com/bHbVsP');
$curl = new Curl();
$curl->put('https://api.example.com/user/', [
    'first_name' => 'Zach',
    'last_name' => 'Borboa',
]);
$curl = new Curl();
$curl->patch('https://api.example.com/profile/', [
    'image' => '@path/to/file.jpg',
]);
$curl = new Curl();
$curl->patch('https://api.example.com/profile/', [
    'image' => new CURLFile('path/to/file.jpg'),
]);
$curl = new Curl();
$curl->delete('https://api.example.com/user/', [
    'id' => '1234',
]);
// Enable all supported encoding types and download a file.
$curl = new Curl();
$curl->setOpt(CURLOPT_ENCODING , '');
$curl->download('https://www.example.com/file.bin', '/tmp/myfile.bin');
// Case-insensitive access to headers.
$curl = new Curl();
$curl->download('https://www.example.com/image.png', '/tmp/myimage.png');
echo $curl->responseHeaders['Content-Type'] . "\n"; // image/png
echo $curl->responseHeaders['CoNTeNT-TyPE'] . "\n"; // image/png
// Manual clean up.
$curl->close();
// Example access to curl object.
curl_set_opt($curl->curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1');
require __DIR__ . '/vendor/autoload.php';

use Curl\MultiCurl;

// Requests in parallel with callback functions.
$multi_curl = new MultiCurl();

$multi_curl->success(function($instance) {
    echo 'call to "' . $instance->url . '" was successful.' . "\n";
    echo 'response:' . "\n";
    var_dump($instance->response);
});
$multi_curl->error(function($instance) {
    echo 'call to "' . $instance->url . '" was unsuccessful.' . "\n";
    echo 'error code: ' . $instance->errorCode . "\n";
    echo 'error message: ' . $instance->errorMessage . "\n";
});
$multi_curl->complete(function($instance) {
    echo 'call completed' . "\n";
});

$multi_curl->addGet('https://www.google.com/search', [
    'q' => 'hello world',
]);
$multi_curl->addGet('https://duckduckgo.com/', [
    'q' => 'hello world',
]);
$multi_curl->addGet('https://www.bing.com/search', [
    'q' => 'hello world',
]);

$multi_curl->start(); // Blocks until all items in the queue have been processed.

More examples are available under /examples.

📖 Available Methods

Curl::__construct($base_url = null, $options = [])
Curl::__destruct()
Curl::__get($name)
Curl::__isset($name)
Curl::afterSend($callback)
Curl::attemptRetry()
Curl::beforeSend($callback)
Curl::buildPostData($data)
Curl::call()
Curl::close()
Curl::complete($callback)
Curl::delete($url, $query_parameters = [], $data = [])
Curl::diagnose($return = false)
Curl::disableTimeout()
Curl::displayCurlOptionValue($option, $value = null)
Curl::download($url, $mixed_filename)
Curl::error($callback)
Curl::exec($ch = null)
Curl::execDone()
Curl::fastDownload($url, $filename, $connections = 4)
Curl::get($url, $data = [])
Curl::getAttempts()
Curl::getBeforeSendCallback()
Curl::getCompleteCallback()
Curl::getCookie($key)
Curl::getCurl()
Curl::getCurlErrorCode()
Curl::getCurlErrorMessage()
Curl::getDownloadCompleteCallback()
Curl::getDownloadFileName()
Curl::getErrorCallback()
Curl::getErrorCode()
Curl::getErrorMessage()
Curl::getFileHandle()
Curl::getHttpErrorMessage()
Curl::getHttpStatusCode()
Curl::getId()
Curl::getInfo($opt = null)
Curl::getJsonDecoder()
Curl::getOpt($option)
Curl::getOptions()
Curl::getRawResponse()
Curl::getRawResponseHeaders()
Curl::getRemainingRetries()
Curl::getRequestHeaders()
Curl::getResponse()
Curl::getResponseCookie($key)
Curl::getResponseCookies()
Curl::getResponseHeaders()
Curl::getRetries()
Curl::getRetryDecider()
Curl::getSuccessCallback()
Curl::getUrl()
Curl::getUserSetOptions()
Curl::getXmlDecoder()
Curl::head($url, $data = [])
Curl::isChildOfMultiCurl()
Curl::isCurlError()
Curl::isError()
Curl::isHttpError()
Curl::options($url, $data = [])
Curl::patch($url, $data = [])
Curl::post($url, $data = '', $follow_303_with_post = false)
Curl::progress($callback)
Curl::put($url, $data = [])
Curl::removeHeader($key)
Curl::reset()
Curl::search($url, $data = [])
Curl::setAutoReferer($auto_referer = true)
Curl::setAutoReferrer($auto_referrer = true)
Curl::setBasicAuthentication($username, $password = '')
Curl::setConnectTimeout($seconds)
Curl::setCookie($key, $value)
Curl::setCookieFile($cookie_file)
Curl::setCookieJar($cookie_jar)
Curl::setCookieString($string)
Curl::setCookies($cookies)
Curl::setDefaultDecoder($mixed = 'json')
Curl::setDefaultHeaderOut()
Curl::setDefaultJsonDecoder()
Curl::setDefaultTimeout()
Curl::setDefaultUserAgent()
Curl::setDefaultXmlDecoder()
Curl::setDelete($url, $query_parameters = [], $data = [])
Curl::setDigestAuthentication($username, $password = '')
Curl::setFile($file)
Curl::setFollowLocation($follow_location = true)
Curl::setForbidReuse($forbid_reuse = true)
Curl::setGet($url, $data = [])
Curl::setHead($url, $data = [])
Curl::setHeader($key, $value)
Curl::setHeaders($headers)
Curl::setInterface($interface)
Curl::setJsonDecoder($mixed)
Curl::setMaxFilesize($bytes)
Curl::setMaximumRedirects($maximum_redirects)
Curl::setOpt($option, $value)
Curl::setOptions($url, $data = [])
Curl::setOpts($options)
Curl::setPatch($url, $data = [])
Curl::setPort($port)
Curl::setPost($url, $data = '', $follow_303_with_post = false)
Curl::setProtocols($protocols)
Curl::setProxy($proxy, $port = null, $username = null, $password = null)

readme truncated — read the full docs on github

Frequently asked questions

Is php-curl-class free to use?

php-curl-class is open source under the Unlicense licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does php-curl-class do?

PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs

What is php-curl-class written in?

php-curl-class is primarily written in PHP. Its source is publicly available at https://github.com/php-curl-class/php-curl-class, and it has 3,297 GitHub stars.