All Projects → php-curl-class → Php Curl Class

php-curl-class / Php Curl Class

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

Programming Languages

PHP
23972 projects - #3 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to Php Curl Class

Httpie
As easy as /aitch-tee-tee-pie/ 🥧 Modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins & more. https://twitter.com/httpie
Stars: ✭ 53,052 (+1727.49%)
Mutual labels:  api, api-client, json, http-client, curl, client
Unifi Api Client
A PHP API client class to interact with Ubiquiti's UniFi Controller API
Stars: ✭ 602 (-79.26%)
Mutual labels:  api, api-client, curl, class, client
Webapiclient
An open source project based on the HttpClient. You only need to define the c# interface and modify the related features to invoke the client library of the remote http interface asynchronously.
Stars: ✭ 1,618 (-44.26%)
Mutual labels:  restful, json, xml, client
Requester
Powerful, modern HTTP/REST client built on top of the Requests library
Stars: ✭ 273 (-90.6%)
Mutual labels:  api, http-client, curl, requests
Insomnia
The open-source, cross-platform API client for GraphQL, REST, and gRPC.
Stars: ✭ 18,969 (+553.43%)
Mutual labels:  api, api-client, http-client, curl
curly.hpp
Simple cURL C++17 wrapper
Stars: ✭ 48 (-98.35%)
Mutual labels:  curl, http-client, requests
Countries States Cities Database
🌍 World countries, states, regions, provinces, cities, towns in JSON, SQL, XML, PLIST, YAML, and CSV. All Countries, States, Cities with ISO2, ISO3, Country Code, Phone Code, Capital, Native Language, Timezones, Latitude, Longitude, Region, Subregion, Flag Emoji, and Currency. #countries #states #cities
Stars: ✭ 1,130 (-61.07%)
Mutual labels:  api, json, xml
RESTEasy
REST API calls made easier
Stars: ✭ 12 (-99.59%)
Mutual labels:  http-client, api-client, requests
httoop
HTTOOP - a fully object oriented HTTP protocol library written in python
Stars: ✭ 15 (-99.48%)
Mutual labels:  restful, http-client, http-proxy
Generator Http Fake Backend
Yeoman generator for building a fake backend by providing the content of JSON files or JavaScript objects through configurable routes.
Stars: ✭ 49 (-98.31%)
Mutual labels:  api, restful, json
Jokeapi
A REST API that serves uniformly and well formatted jokes in JSON, XML, YAML or plain text format that also offers a great variety of filtering methods
Stars: ✭ 71 (-97.55%)
Mutual labels:  api, json, xml
Scobot
SCORM API for Content. JavaScript library, QUnit tests and examples.
Stars: ✭ 128 (-95.59%)
Mutual labels:  api, json, xml
Http Prompt
An interactive command-line HTTP and API testing client built on top of HTTPie featuring autocomplete, syntax highlighting, and more. https://twitter.com/httpie
Stars: ✭ 8,329 (+186.91%)
Mutual labels:  api, json, http-client
Json Api Dart
JSON:API client for Dart/Flutter
Stars: ✭ 53 (-98.17%)
Mutual labels:  api, json, http-client
Igdb
Go client for the Internet Game Database API
Stars: ✭ 65 (-97.76%)
Mutual labels:  api, api-client, client
Flask Restx
Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
Stars: ✭ 1,050 (-63.83%)
Mutual labels:  api, restful, json
Flickr Sdk
Almost certainly the best Flickr API client in the world for node and the browser
Stars: ✭ 104 (-96.42%)
Mutual labels:  api, json, client
Flask Restplus
Fully featured framework for fast, easy and documented API development with Flask
Stars: ✭ 2,585 (-10.95%)
Mutual labels:  api, restful, json
Autoserver
Create a full-featured REST/GraphQL API from a configuration file
Stars: ✭ 188 (-93.52%)
Mutual labels:  api, json, framework
Horaires Ratp Api
Webservice pour les horaires et trafic RATP en temps réel
Stars: ✭ 232 (-92.01%)
Mutual labels:  api, json, xml

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, simply:

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

For latest commit version:

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

Requirements

PHP Curl Class works with PHP 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, and 8.1.

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->errorCode . ': ' . $curl->errorMessage . "\n";
} 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->errorCode . ': ' . $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');
curl_close($curl->curl);
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)
Curl::__destruct()
Curl::__get($name)
Curl::_fastDownload($url, $filename, $connections = 4) {
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::download($url, $mixed_filename)
Curl::error($callback)
Curl::exec($ch = null)
Curl::execDone()
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::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::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::setDefaultJsonDecoder()
Curl::setDefaultTimeout()
Curl::setDefaultUserAgent()
Curl::setDefaultXmlDecoder()
Curl::setDigestAuthentication($username, $password = '')
Curl::setFile($file)
Curl::setFollowLocation($follow_location = true)
Curl::setForbidReuse($forbid_reuse = true)
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::setOpts($options)
Curl::setPort($port)
Curl::setProxy($proxy, $port = null, $username = null, $password = null)
Curl::setProxyAuth($auth)
Curl::setProxyTunnel($tunnel = true)
Curl::setProxyType($type)
Curl::setRange($range)
Curl::setReferer($referer)
Curl::setReferrer($referrer)
Curl::setRetry($mixed)
Curl::setStop($callback)
Curl::setTimeout($seconds)
Curl::setUrl($url, $mixed_data = '')
Curl::setUserAgent($user_agent)
Curl::setXmlDecoder($mixed)
Curl::success($callback)
Curl::unsetHeader($key)
Curl::unsetProxy()
Curl::verbose($on = true, $output = 'STDERR')
MultiCurl::__construct($base_url = null)
MultiCurl::__destruct()
MultiCurl::addCurl(Curl $curl)
MultiCurl::addDelete($url, $query_parameters = [], $data = [])
MultiCurl::addDownload($url, $mixed_filename)
MultiCurl::addGet($url, $data = [])
MultiCurl::addHead($url, $data = [])
MultiCurl::addOptions($url, $data = [])
MultiCurl::addPatch($url, $data = [])
MultiCurl::addPost($url, $data = '', $follow_303_with_post = false)
MultiCurl::addPut($url, $data = [])
MultiCurl::addSearch($url, $data = [])
MultiCurl::beforeSend($callback)
MultiCurl::close()
MultiCurl::complete($callback)
MultiCurl::disableTimeout()
MultiCurl::error($callback)
MultiCurl::getOpt($option)
MultiCurl::removeHeader($key)
MultiCurl::setAutoReferer($auto_referer = true)
MultiCurl::setAutoReferrer($auto_referrer = true)
MultiCurl::setBasicAuthentication($username, $password = '')
MultiCurl::setConcurrency($concurrency)
MultiCurl::setConnectTimeout($seconds)
MultiCurl::setCookie($key, $value)
MultiCurl::setCookieFile($cookie_file)
MultiCurl::setCookieJar($cookie_jar)
MultiCurl::setCookieString($string)
MultiCurl::setCookies($cookies)
MultiCurl::setDigestAuthentication($username, $password = '')
MultiCurl::setFile($file)
MultiCurl::setFollowLocation($follow_location = true)
MultiCurl::setForbidReuse($forbid_reuse = true)
MultiCurl::setHeader($key, $value)
MultiCurl::setHeaders($headers)
MultiCurl::setInterface($interface)
MultiCurl::setJsonDecoder($mixed)
MultiCurl::setMaximumRedirects($maximum_redirects)
MultiCurl::setOpt($option, $value)
MultiCurl::setOpts($options)
MultiCurl::setPort($port)
MultiCurl::setProxies($proxies)
MultiCurl::setProxy($proxy, $port = null, $username = null, $password = null)
MultiCurl::setProxyAuth($auth)
MultiCurl::setProxyTunnel($tunnel = true)
MultiCurl::setProxyType($type)
MultiCurl::setRange($range)
MultiCurl::setRateLimit($rate_limit)
MultiCurl::setReferer($referer)
MultiCurl::setReferrer($referrer)
MultiCurl::setRetry($mixed)
MultiCurl::setTimeout($seconds)
MultiCurl::setUrl($url, $mixed_data = '')
MultiCurl::setUserAgent($user_agent)
MultiCurl::setXmlDecoder($mixed)
MultiCurl::start()
MultiCurl::success($callback)
MultiCurl::unsetHeader($key)
MultiCurl::unsetProxy()
MultiCurl::verbose($on = true, $output = STDERR)

Security

See SECURITY for security considerations.

Troubleshooting

See TROUBLESHOOTING for troubleshooting.

Run Tests

To run tests:

$ git clone https://github.com/php-curl-class/php-curl-class.git
$ cd php-curl-class/
$ composer update
$ ./tests/run.sh

To run select tests:

$ git clone https://github.com/php-curl-class/php-curl-class.git
$ cd php-curl-class/
$ composer update
$ ./tests/run.sh --filter=keyword

To test all PHP versions in containers:

$ git clone https://github.com/php-curl-class/php-curl-class.git
$ cd php-curl-class/
$ ./tests/test_all.sh

Contribute

  1. Check for open issues or open a new issue to start a discussion around a bug or feature.
  2. Fork the repository on GitHub to start making your changes.
  3. Write one or more tests for the new feature or that expose the bug.
  4. Make code changes to implement the feature or fix the bug.
  5. Send a pull request to get your changes merged and published.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].