Many\Curler

another one curls the dust

/8/80/Andaman.jpg/250px-Andaman.jpg /2/21/Aurora_and_sunset.jpg/250px-Aurora_and_sunset.jpg

Some requests

Array
(
    [curler_info] => Loads the content of a JSON file and executes some callback functions in a row (7 to be specific)
    [curler] => Array
        (
            [url] => https://raw.githubusercontent.com/eypsilon/Curler/master/www.example.json
            [http_code] => 200
            [status] => ok
            [method] => GET
            [content_type] => text/plain; charset=utf-8
            [meta] => Array
                (
                    [duration] => 0.027787923812866
                    [size] => 783 B
                    [timestamp] => 2026-07-30 16:13:34.030100
                    [url] => https://raw.githubusercontent.com/eypsilon/Curler/master/www.example.json
                    [method] => GET
                )

            [error] => 
            [response] => {
    "Many": "App",
    "example": "json file",
    "custom_callback": [
        "custom_callback done, 16:13:34.029900"
    ],
    "callback_two": [
        "callback_two done, 16:13:34.030000"
    ],
    "callback_three": [
        "callback_three done, 16:13:34.030000"
    ],
    "callback_class_run": [
        "callback_class_run done, 16:13:34.030000"
    ],
    "callback_class_init": [
        "callback_class_init done, 16:13:34.030000"
    ],
    "closure_callback": [
        "closure_callback done, 16:13:34.030000"
    ],
    "done_too": [
        "done_too done, 16:13:34.030100"
    ]
}
        )

    [load_urls_info] => Loads a handful of URLs and truncates the response
    [load_urls] => Array
        (
            [0] => Array
                (
                    [url] => http://example.com/
                    [status] => 200
                    [response] => <!doctype html>… 2026-07-30 16:13:34.040900
                )

            [1] => Array
                (
                    [url] => https://raw.githubusercontent.com/eypsilon/browser-reload/master/LICENSE
                    [status] => 200
                    [response] => The MIT License (MIT… 2026-07-30 16:13:34.069900
                )

            [2] => Array
                (
                    [url] => https://github.com/eypsilon/MycroBench
                    [status] => 200
                    [response] => <!DOCTYPE html>… 2026-07-30 16:13:34.113500
                )

        )

    [loaded_images_info] => The images displayed above, the responses are truncated
    [loaded_images] => Array
        (
            [0] => Array
                (
                    [response] => data:image/jpeg;base64,/9j/2wBDAAQD …
                    [http_code] => 200
                    [type] => image/jpeg
                    [meta] => Array
                        (
                            [duration] => 0.03636908531189
                            [size] => 12.83 KB
                            [timestamp] => 2026-07-30 16:13:34.152400
                            [url] => https://upload.wikimedia.org/wikipedia/commons/thumb/8/80/Andaman.jpg/250px-Andaman.jpg
                            [method] => GET
                        )

                )

            [1] => Array
                (
                    [response] => data:image/jpeg;base64,/9j/4QCGRXhp …
                    [http_code] => 200
                    [type] => image/jpeg
                    [meta] => Array
                        (
                            [duration] => 0.035094976425171
                            [size] => 10.75 KB
                            [timestamp] => 2026-07-30 16:13:34.190000
                            [url] => https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Aurora_and_sunset.jpg/250px-Aurora_and_sunset.jpg
                            [method] => GET
                        )

                )

        )

    [getCurlCount] => 6
    [getCurlTrace] => Array
        (
            [0] => [GET] 200 https://raw.githubusercontent.com/eypsilon/Curler/master/www.example.json (0.0278)
            [1] => [GET] 200 http://example.com/ (0.0084)
            [2] => [GET] 200 https://raw.githubusercontent.com/eypsilon/browser-reload/master/LICENSE (0.0288)
            [3] => [GET] 200 https://github.com/eypsilon/MycroBench (0.0381)
            [4] => [GET] 200 https://upload.wikimedia.org/wikipedia/commons/thumb/8/80/Andaman.jpg/250px-Andaman.jpg (0.0364)
            [5] => [GET] 200 https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Aurora_and_sunset.jpg/250px-Aurora_and_sunset.jpg (0.0351)
        )

    [getConfig] => Array
        (
            [default_url] => https://upload.wikimedia.org/wikipedia/commons/thumb
            [default_headers] => Array
                (
                    [x-app-curler] => Many/Curler
                    [Content-Type] => application/json
                )

            [default_options] => Array
                (
                    [10018] => AwesomeUser
                    [10102] => gzip, deflate
                )

            [enable_exceptions] => 1
            [enable_meta] => 1
            [enable_history] => 1
            [date_format] => Y-m-d H:i:s.u
            [image_to_data] => Array
                (
                    [0] => image/jpeg
                )

            [retry_attempts] => 0
            [retry_delay_ms] => 100
            [retry_on_status] => Array
                (
                    [0] => 429
                    [1] => 500
                    [2] => 502
                    [3] => 503
                    [4] => 504
                )

        )

    [getOptions] => Array
        (
            [84] => 4
            [10002] => 
            [10036] => GET
            [42] => 
            [10023] => Array
                (
                    [0] => x-app-curler: Many/Curler
                    [1] => Content-Type: application/json
                )

            [2] => 
            [47] => 
            [10015] => 
            [81] => 2
            [64] => 1
            [19913] => 1
            [41] => 
            [58] => 1
            [52] => 1
            [68] => 10
            [78] => 30
            [13] => 60
            [10102] => gzip, deflate
            [10018] => AwesomeUser
        )

)

Responder/Receiver Example

<?php

/**
 * Example Receiver / Responder
 */

/**
 * Curler Responder, let's say 'https://example.com/restricted/' is .htaccess protected and returns
 */

use Many\Http\Curler;

$rspns = [
    'auth_type' => $_SERVER['AUTH_TYPE'] ?? 'error',
    'header' => getallheaders(),
    'body' => file_get_contents('php://input'),
    'c_types' => [
        'json' => 'application/json',
    ]
];

$setType = $rspns['c_types'][$_GET['c_type'] ?? null] ?? null;
$cType = $setType ?? $_SERVER['CONTENT_TYPE'] ?? 'text/html';

/** Set Content-Type header auto, if requested one is listed in 'c_types' */
if ($setType)
    header(sprintf('Content-Type: %s; charset: %s', $cType, $_GET['charset'] ?? 'UTF-8'));

/** Parse received body content */
if (ctype_print($rspns['body']))
    parse_str($rspns['body'], $rspns['body_parsed']);

exit('application/json' == $cType
    ? json_encode($rspns, JSON_PRETTY_PRINT)
    : print_r($rspns, true)
);



/**
 * Curler Receiver, access the .htaccess protected ressources
 */

$curler = (new Curler)
    ->authAny('many', '123456') // auto ->authBasic() or ->authDigest()
    ->postFields([
        'lorem_ipsum' => 'Dolor Sit Amet',
    ])
    ->jsonDecode()
    ->exec('https://example.com/restricted/'); // ?c_type=json &charset=UTF-8

printf('<pre>%s<hr /><b>body</b><br />%s</pre>'
    , print_r($curler, true)
    , $curler['response']->body ?? 'body is not an object'
);

Check current file


start: 16:13:34.001900
end:   16:13:34.192100
diff:  0.1902
mem:   432.72 KB
peak:  1.59 MB