athlon1600/php-curl-client

Simple PHP cURL Client

v1.2.0 2023-10-24 23:17 UTC

This package is auto-updated.

Last update: 2024-12-15 01:13:09 UTC


README

GitHub Workflow Status (with event) Packagist Downloads (custom server)

PHP Curl Client

A very simple curl client - less than 100 lines. Perfect for being a base class.

Installation

composer require athlon1600/php-curl-client "^1.0"

Examples

use Curl\Client;

$client = new Client();

// returns standardized Response object no matter what
$response = $client->get('https://stackoverflow.com');

// 200
$status = $response->status;

// HTML content
$body = $response->body;

// curl_error() OR null
$error = $response->error;

// CurlInfo instance
$info = $response->info;

Update: $response->info now returns an object that will have an auto-complete on your IDE.

;

Works with POST requests too:

$client->post('http://httpbin.org/post', ['username' => 'bob', 'password' => 'test']);

or you can issue a completely customized request:

$client->request('GET', 'https://www.whatismyip.com/', null, [
    'User-Agent' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X)'
], [
    CURLOPT_PROXY => '127.0.0.1:8080',
    CURLOPT_TIMEOUT => 10
]);

TODO

  • make PSR-7 and PSR-18 compatible