Many\Curler

another one curls the dust

/8/80/Andaman.jpg/200px-Andaman.jpg /2/21/Aurora_and_sunset.jpg/200px-Aurora_and_sunset.jpg /9/93/Sunset_at_Egipura%2C_Bangalore.jpg/200px-Sunset_at_Egipura%2C_Bangalore.jpg /3/3e/After_The_Storm_(3594761019).jpg/200px-After_The_Storm_(3594761019).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] => disabled
            [error] => 
            [response] => {
    "Many": "App",
    "example": "json file",
    "custom_callback": [
        "custom_callback done, 22:38:44.3551"
    ],
    "callback_two": [
        "callback_two done, 22:38:44.3551"
    ],
    "callback_three": [
        "callback_three done, 22:38:44.3551"
    ],
    "callback_class_run": [
        "callback_class_run done, 22:38:44.3551"
    ],
    "callback_class_init": [
        "callback_class_init done, 22:38:44.3551",
        "callback_class_init done, 22:38:44.3551"
    ],
    "closure_callback": [
        "closure_callback done, 22:38:44.3552"
    ],
    "done_too": [
        "done_too done, 22:38:44.3552"
    ]
}
        )

    [load_urls_info] => Loads a handful of URLs and truncates the response
    [load_urls] => Array
        (
            [0] => Array
                (
                    [url] => http://example.com/
                    [http_code] => 200
                    [status] => ok
                    [method] => GET
                    [content_type] => text/html; charset=UTF-8
                    [meta] => disabled
                    [error] => 
                    [response] => <!doctype html>… 2024-11-20 22:38:44.3552
                )

            [1] => Array
                (
                    [url] => https://raw.githubusercontent.com/eypsilon/browser-reload/master/LICENSE
                    [http_code] => 200
                    [status] => ok
                    [method] => GET
                    [content_type] => text/plain; charset=utf-8
                    [meta] => disabled
                    [error] => 
                    [response] => The MIT License (MIT… 2024-11-20 22:38:44.3638
                )

            [2] => Array
                (
                    [url] => https://github.com/eypsilon/MycroBench
                    [http_code] => 200
                    [status] => ok
                    [method] => GET
                    [content_type] => text/html; charset=utf-8
                    [meta] => disabled
                    [error] => 
                    [response] => <!DOCTYPE html>… 2024-11-20 22:38:44.3857
                )

        )

    [loaded_images_info] => The images displayed above, the responses are truncated
    [loaded_images] => Array
        (
            [0] => Array
                (
                    [url] => https://upload.wikimedia.org/wikipedia/commons/thumb/8/80/Andaman.jpg/200px-Andaman.jpg
                    [http_code] => 200
                    [status] => ok
                    [method] => GET
                    [content_type] => image/jpeg
                    [meta] => Array
                        (
                            [scheme] => HTTPS
                            [size] => 6.81 KB
                            [datetime] => 2024-11-20 22:38:44.4552
                        )

                    [error] => 
                    [response] => data:image/jpeg;base64,/9j/2wBDAAQD …
                )

            [1] => Array
                (
                    [url] => https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Aurora_and_sunset.jpg/200px-Aurora_and_sunset.jpg
                    [http_code] => 200
                    [status] => ok
                    [method] => GET
                    [content_type] => image/jpeg
                    [meta] => Array
                        (
                            [scheme] => HTTPS
                            [size] => 4.32 KB
                            [datetime] => 2024-11-20 22:38:44.4781
                        )

                    [error] => 
                    [response] => data:image/jpeg;base64,/9j/4AAQSkZJ …
                )

            [2] => Array
                (
                    [url] => https://upload.wikimedia.org/wikipedia/commons/thumb/9/93/Sunset_at_Egipura%2C_Bangalore.jpg/200px-Sunset_at_Egipura%2C_Bangalore.jpg
                    [http_code] => 200
                    [status] => ok
                    [method] => GET
                    [content_type] => image/jpeg
                    [meta] => Array
                        (
                            [scheme] => HTTPS
                            [size] => 10.23 KB
                            [datetime] => 2024-11-20 22:38:44.5053
                        )

                    [error] => 
                    [response] => data:image/jpeg;base64,/9j/2wBDAAQD …
                )

            [3] => Array
                (
                    [url] => https://upload.wikimedia.org/wikipedia/commons/thumb/3/3e/After_The_Storm_(3594761019).jpg/200px-After_The_Storm_(3594761019).jpg
                    [http_code] => 200
                    [status] => ok
                    [method] => GET
                    [content_type] => image/jpeg
                    [meta] => Array
                        (
                            [scheme] => HTTPS
                            [size] => 8.52 KB
                            [datetime] => 2024-11-20 22:38:44.5380
                        )

                    [error] => 
                    [response] => data:image/jpeg;base64,/9j/4AAQSkZJ …
                )

        )

    [getCurlCount] => 8
    [getCurlTrace] => Array
        (
            [01__2024-11-20 22:38:44.3535] => GET 200 https://raw.githubusercontent.com/eypsilon/Curler/master/www.example.json
            [02__2024-11-20 22:38:44.3637] => GET 200 http://example.com/
            [03__2024-11-20 22:38:44.3840] => GET 200 https://raw.githubusercontent.com/eypsilon/browser-reload/master/LICENSE
            [04__2024-11-20 22:38:44.4188] => GET 200 https://github.com/eypsilon/MycroBench
            [05__2024-11-20 22:38:44.4553] => GET 200 {replaced_url} …/8/80/Andaman.jpg/200px-Andaman.jpg
            [06__2024-11-20 22:38:44.4781] => GET 200 {replaced_url} …/2/21/Aurora_and_sunset.jpg/200px-Aurora_and_sunset.jpg
            [07__2024-11-20 22:38:44.5053] => GET 200 {replaced_url} …/9/93/Sunset_at_Egipura%2C_Bangalore.jpg/200px-Sunset_at_Egipura%2C_Bangalore.jpg
            [08__2024-11-20 22:38:44.5381] => GET 200 {replaced_url} …/3/3e/After_The_Storm_(3594761019).jpg/200px-After_The_Storm_(3594761019).jpg
        )

    [getConfig] => Array
        (
            [response_only] => 
            [curl_trace] => 1
            [exceptions] => 1
            [meta] => 1
            [request_info] => 
            [curl_info] => 
            [default_url] => https://upload.wikimedia.org/wikipedia/commons/thumb
            [date_format] => Y-m-d H:i:s.u
            [image_to_data] => Array
                (
                    [0] => image/jpeg
                )

            [default_header] => Array
                (
                    [x-app-curler] => Many/Curler
                    [Content-Type] => application/json
                )

            [default_options] => Array
                (
                    [10018] => AwesomeUser
                )

            [default_callback] => Array
                (
                )

        )

    [getOptions] => Array
        (
            [CURLOPT_HTTP_VERSION] => 0
            [CURLOPT_URL] => 
            [CURLOPT_CUSTOMREQUEST] => GET
            [CURLOPT_HEADER] => 
            [CURLOPT_HTTPHEADER] => Array
                (
                    [0] => x-app-curler: Many/Curler
                    [1] => Content-Type: application/json
                )

            [2] => 
            [CURLOPT_POST] => 
            [CURLOPT_POSTFIELDS] => 
            [CURLOPT_SSL_VERIFYHOST] => 2
            [CURLOPT_SSL_VERIFYPEER] => 1
            [CURLOPT_RETURNTRANSFER] => 1
            [CURLOPT_VERBOSE] => 1
            [CURLOPT_AUTOREFERER] => 1
            [CURLOPT_FOLLOWLOCATION] => 1
            [CURLOPT_MAXREDIRS] => 10
            [CURLOPT_CONNECTTIMEOUT] => 90
            [CURLOPT_TIMEOUT] => 90
            [CURLOPT_ACCEPT_ENCODING] => gzip
            [CURLOPT_USERAGENT] => AwesomeUser
        )

)

Responder/Receiver Example

<?php

/**
 * 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($rspnsJSON_PRETTY_PRINT)
    : 
print_r($rspnstrue)
);



/**
 * 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($curlertrue)
    , 
$curler['response']->body ?? 'body is not an object'
);

Check current file


start: 22:38:44.3312
end:   22:38:44.5406
diff:  0.2094
mem:   420.93 KB
peak:  1.7 MB