PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs
PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs
PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs.
To install PHP Curl Class, run the following command:
composer require php-curl-class/php-curl-classTo install the latest commit version:
composer require php-curl-class/php-curl-class @devInstallation instructions to use the composer command can be found on https://github.com/composer/composer.
PHP Curl Class works with PHP versions 8.5, 8.4, 8.3, 8.2, 8.1, and 8.0.
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');…More examples are available under /examples.
…See SECURITY for security considerations.
See TROUBLESHOOTING for help troubleshooting.
See TESTING for testing information.
No open issues yet, or sync has not completed.