Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

php-curl-class

> 开发工具
Open source

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

3.3K stars0 likes2 views
WebsiteGitHub

About

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

PHP Curl Class: HTTP requests made easy

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


  • ⚙️ Installation
  • Requirements
  • Quick Start and Examples
  • Available Methods
  • Security
  • ️ Troubleshooting
  • Testing
  • Contributing

⚙️ 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.

php
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);
}
php
// https://www.example.com/search?q=keyword
$curl = new Curl();
$curl->get('https://www.example.com/search', [
    'q' => 'keyword',
]);
php
$curl = new Curl();
$curl->post('https://www.example.com/login/', [
    'username' => 'myusername',
    'password' => 'mypassword',
]);
php
$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);
php
$curl = new Curl();
$curl->setFollowLocation();
$curl->get('https://shortn.example.com/bHbVsP');
php
$curl = new Curl();
$curl->put('https://api.example.com/user/', [
    'first_name' => 'Zach',
    'last_name' => 'Borboa',
]);
php
$curl = new Curl();
$curl->patch('https://api.example.com/profile/', [
    'image' => '@path/to/file.jpg',
]);
php
$curl = new Curl();
$curl->patch('https://api.example.com/profile/', [
    'image' => new CURLFile('path/to/file.jpg'),
]);
php
$curl = new Curl();
$curl->delete('https://api.example.com/user/', [
    'id' => '1234',
]);
php
// 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');
php
// 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
php
// Manual clean up.
$curl->close();
php
// 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.

Available Methods

…

Security

See SECURITY for security considerations.

️ Troubleshooting

See TROUBLESHOOTING for help troubleshooting.

Testing

See TESTING for testing information.

Contributing

  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.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPapiapi-clientclassclient

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具