dev-main 2022-03-28 21:04 UTC

This package is not auto-updated.

Last update: 2024-05-23 00:35:32 UTC


README

Utilities related to http.

Tutorial

Install with composer:

composer require thirdplace/http:dev-main

Install manually:

wget https://git.sr.ht/~thirdplace/http/blob/main/http.php

Example usage:

<?php

try {
    $result = Thirdplace\get('https://example.com', ['timeout' => 3]);
} catch (\RuntimeException $e) {
    exit("hmm\n");
}

if ($result['code'] === 200) {
    print $result['body'];
} else {
    print "oh\n";
}

Explanation

Returns an associative array with code and body. Uses curl. Throws \RuntimeException on curl failure.

How-to

Reference

function get(string $url, array $config = []): array