PHPackages                             eypsilon/manycurler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. eypsilon/manycurler

ActiveLibrary[HTTP &amp; Networking](/categories/http)

eypsilon/manycurler
===================

Many/Curler | Another one CURLs the dust

v1.0.4(3y ago)43MITPHPPHP &gt;=8.0CI passing

Since Jul 26Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/eypsilon/curler)[ Packagist](https://packagist.org/packages/eypsilon/manycurler)[ RSS](/packages/eypsilon-manycurler/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)DependenciesVersions (5)Used By (0)

MANY/CURLER | Another one CURLs the dust
========================================

[](#manycurler--another-one-curls-the-dust)

This class is written to simplify the use of CURL in PHP using chained methods and more rememberable names.

I needed a simple way to explore the Shopware API (v6.\*) via http and the Bearer token authentication scheme, but haven't found, what i was looking for to do it, so i ended up with this one. It does nothing new at all, nothing exciting, just simple Requests to URLs and Endpoints like you would expect, but a bit prettier than CURL itself.

See [./public/index.php](./public/index.php) for examples or check the livedemo on [Vercel](https://curler-eypsilon.vercel.app/).

```
composer require eypsilon/curler
```

```
use Many\Http\Curler;

/**
 * @var array Simple get
 */
$c = (new Curler)->get('https://example.com/');
print $c['response'];

/**
 * @var string with Auth creds
 */
$xc = (new Curler)
    ->authAny('user', 'pass')
    ->post(
        json_encode([
            'lorem_ipsum' => 'Dolor Sit Amet',
        ])
    )
    ->responseOnly() // returns $xc['response']
    ->exec('/api/usr');
print $xc;
```

Usage
-----

[](#usage)

```
/**
 * @var array Set Configs and Defaults
 */
Curler::setConfig([
    'response_only' => false, // returns the response content as is
    'curl_trace'    => false, // track requests, (GET) Curl::getCurlTrace()
    'exceptions'    => false, // enable Exceptions
    'meta'          => false, // enable meta data
    'request_info'  => false, // [getallheaders(), $_SERVER] in 'meta'
    'curl_info'     => false, // CURL generated infos about the request in 'meta'

    // Default URL, will be prefixed to each request URL, disable with: ->disableDefaultUrl()
    'default_url'   => null,  // 'https://example.com'
    'date_format'   => 'Y-m-d H:i:s.u',

    // Convert images to valid data strings (no defaults defined)
    'image_to_data' => [], // 'image/jpeg', 'image/png', 'image/webp', 'image/gif', 'image/x-icon', 'image/svg+xml', ...

    // Send default headers (no defaults defined)
    'default_header' => [], // 'x-powered-by' => 'Many/Curler',

    // Add/overwrite CURL default options, see Curl::getOptions()
    'default_options' => [
        CURLINFO_HEADER_OUT => false,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_NONE,
        CURLOPT_URL => null,
        CURLOPT_CUSTOMREQUEST => 'GET',
        CURLOPT_HEADER => false,
        CURLOPT_HTTPHEADER => [],
        CURLOPT_POST => false,
        CURLOPT_POSTFIELDS => null, // (string) http_build_query($str)
        CURLOPT_SSL_VERIFYHOST => 2,
        CURLOPT_SSL_VERIFYPEER => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_VERBOSE => true,
        CURLOPT_AUTOREFERER => true,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_CONNECTTIMEOUT => 90,
        CURLOPT_TIMEOUT => 90,
        CURLOPT_ENCODING => 'gzip',
        CURLOPT_USERAGENT => 'Many/Curler',
    ],

    // Set a callback function, that gets fired after first curl_exec(), eg. for logging
    'default_callback' => [], // => ['print_r', true],
]);

/**
 * @var mixed Extended example with available methods
 */
$curl = (new Curler)

    ->method('post')            // Set http method, default is "get"
    ->url('http://example.com') // Set target url or path, same as ->exec(URL)

    /**
     * Misc */
    ->disableDefaultUrl()       // If default_url is setted, disable for this instance
    ->responseOnly()            // Returns CURL response content only
    ->requestInfo()             // getallheaders(), $_SERVER
    ->curlInfo()                // curl_getinfo()

    /**
     * Set CURL Options */
    ->setOpt(CURLOPT_ENCODING, 'zip')
    ->setOpt(CURLOPT_USERAGENT, 'Many/Curler')
    ->setOpt(CURLOPT_AUTOREFERER, false)

    // array alternate
    ->setOptArray([
        CURLOPT_ENCODING => 'zip',
        CURLOPT_USERAGENT => 'Many/Curler',
        CURLOPT_AUTOREFERER => false,
    ])

    /**
     * Header */
    ->header([
        'Authentication' => 'Many pw.2345',      // 'Authentication: Many pw.2345'
        'Authentication' => ['Many', 'pw.2345'], // 'Authentication: Many pw.2345'
    ])

    /**
     * HTTP Auth */
    ->httpAuth(CURLAUTH_BASIC) // protection type
    ->userPwd('user', 'pass')  // or ('user:pass')

    // CURLAUTH_ANY (.htaccess, uses basic or digest)
    ->authAny('user', 'pass')

    // CURLAUTH_BASIC
    ->authBasic('user', 'pass')

    // CURLAUTH_DIGEST
    ->authDigest('user', 'pass')

    // CURLAUTH_BEARER (?user optional, not .htaccess)
    ->authBearer('token.lr.72.m', '?user')

    /**
     * Sets CURLOPT_CUSTOMREQUEST=POST and CURLOPT_POST=true internally.
     * Arrays will be converted to strings using http_build_query() */
    ->post([
        'lorem_ipsum' => 'dolor sit amet',
    ])

    /**
     * Set postfields avoiding internally setted stuff to send data as body
     * content, eg PUT. This class uses http_build_query(), if an array is
     * given. Convert to any string format that fits your needs */
    ->postFields(
        json_encode([
            'lorem_ipsum' => 'dolor sit amet',
        ])
    )

    /**
     * Callback, run multiple callbacks through chaining in the given order.
     * Each callback will use the resulting content from the previous one. */
    ->callback('json_decode', true)             // any PHP internal function
    ->callback('curlCallback')                  // custom function

    // Custom class
    ->callback('CallbackClass::run')            // (static) class::run()
    ->callback('CallbackClass::class', 'init')  // (new class)->init() # init() could be any method
    ->callback(CallbackClass::class, 'init')    // (new class)->init()

    // Closure
    ->callback(function($response) {
        // Do stuff with $response here and
        return $response;
    })

    // Pre validated callbacks, set simple validator functions to pre-validate the content.
    // If Exceptions are enabled, throws Exceptions on fail, otherwise function gets ignored
    ->callbackIf(['\Many\Http\Curler::isJson'], 'json_decode', true)
    ->callbackIf(['\Many\Http\Curler::isJsonObj'], 'json_encode')
    ->callbackIf(['is_string'], 'json_decode')

    // Shorthands
    ->jsonDecode(true)                          // Shorty for json_decode()
    ->jsonEncode(JSON_PRETTY_PRINT)             // Shorty for json_encode()
    ->htmlChars()                               // Shorty for htmlspecialchars()
    ->htmlSpecialChars()                        // Shorty for ->htmlChars()

    /**
     * Final execs, getter */
    ->exec() // OR
    ->exec('/api/endpoint', [
        CURLOPT_USERAGENT => 'AwesomeCurler', // set any CURL option here
    ])

    /**
     * Alternate exec aliases. They all sets their name as REQUEST_METHOD
     * internally. You can use ->postFields(json_encode([])) to send content
     * additionally in the body. */
    ->delete() // OR
    ->delete('/api/endpoint', [/* ... */])

    ->get()
    ->get('/api/endpoint', [/* ... */])

    ->patch()
    ->patch('/api/endpoint', [/* ... */])

    ->put()
    ->put('/api/endpoint', [/* ... */])
```

### Loading images

[](#loading-images)

To convert images automatically to their valid string representations, set expected image types in `setConfig` (no defaults defined)

```
Curler::setConfig([
    'image_to_data' => [
        'image/jpeg',
        // 'image/png',
        // 'image/webp',
        // 'image/gif',
        // 'image/x-icon',
        // 'image/svg+xml',
        // ...
    ]
]);

$img = 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Aurora_and_sunset.jpg/200px-Aurora_and_sunset.jpg';

if ($src = (new Curler)->responseOnly()->get($img))
    printf('', $src, $img);
```

#### Exceptions

[](#exceptions)

Catch AppCallbackException. The Class sends also additional http\_header, if any errors occures.

```
use Many\Exception\AppCallbackException;

Curler::setConfig([
    'exceptions' => true,
]);

try {
    $get = (new Curler)
        ->callback('theImpossibleFunction')
        ->get('/app/endpoint');
} catch(AppCallbackException $e) {
    $failed = $e->getMessage();
}
```

#### Track requested URLs

[](#track-requested-urls)

To track CURL requests, set `curl_trace` to true, before doing any request.

```
Curler::setConfig([
    'curl_trace' => true,
]);

/** @var array Get all CURL requests with timestamps in an array */
$curlGetTrace = Curler::getCurlTrace();
```

#### Misc methods

[](#misc-methods)

```
/** @var int Get total amount of requests done so far */
$curlsTotal = Curler::getCurlCount();

/** @var array Get Config */
$curlGetConfig = Curler::getConfig();

/** @var array Get curl_setopt(), (true) all available CURL constants */
$curlGetOptions = Curler::getOptions(true);

/** @var mixed Get body content, (true) parsed to array */
$curlGetBodyContent = Curler::getBodyContent(true);

/** @var bool Check if val is JSON format */
$isJson = Curler::isJson('{}', true); // (true) strict mode

/** @var bool Check if val is valid JSON Object (is_array or is_object) */
$isJsonObj = Curler::isJsonObj([]);

/** @var string Readable Bytes */
$memUsage = Curler::readableBytes(memory_get_usage());

/** @var string Datetime with microseconds (microtime(true), $_SERVER['REQUEST_TIME_FLOAT']) */
$microDate = Curler::dateMicroSeconds(null, 'Y-m-d H:i:s.u');

/** @var string Get difference between two Dates with microseconds */
$microDateDiff = Curler::dateMicroDiff(
    Curler::dateMicroSeconds($_SERVER['REQUEST_TIME_FLOAT']), // script started (microtime(true))
    Curler::dateMicroSeconds(),                               // current microtime(true)
    '%s.%f'
);
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance43

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~75 days

Total

4

Last Release

1163d ago

PHP version history (2 changes)v1.0.1PHP &gt;=7.4

v1.0.4PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/a70df0441c2dc68c5c4d9ae414d4a0a1f4374a0f5ac36bfa8c9499a2779801b5?d=identicon)[eypsilon](/maintainers/eypsilon)

---

Top Contributors

[![eypsilon](https://avatars.githubusercontent.com/u/27016183?v=4)](https://github.com/eypsilon "eypsilon (28 commits)")

---

Tags

apicurlcurlphpphp

### Embed Badge

![Health badge](/badges/eypsilon-manycurler/health.svg)

```
[![Health](https://phpackages.com/badges/eypsilon-manycurler/health.svg)](https://phpackages.com/packages/eypsilon-manycurler)
```

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
