This package let's you check the status of a URL to easily check if it's "online" or not. Uses PSR 1/2. It uses Guzzle for communicating with the URLs.
Via Composer
$ composer require viirre/urlchecker
require_once 'vendor/autoload.php';
$url = 'https://www.google.com';
$checker = new \Viirre\UrlChecker\Checker();
$status = $checker->check($url);
if ($status->isRespondingOk()) {
echo "Url {$url} is responding ok, woho!";
} elseif ($status->isRespondingButNotOk()) {
echo "Url {$url} is responding, but with status code: " . $status->getStatusCode() . " and reason for not a 200: " . $status->getReason();
} elseif ($status->isNotResponding()) {
echo "Url {$url} is NOT responding ok, fail reason: " . $status->getReason();
}
There are plenty of stuff to check about the connection, to get how long the connection took, use:
$timeInSeconds = $status->getTimeInSeconds();
$timeInMilliSeconds = $status->getTimeInMilliSeconds();
And if you want to drill down further, you can access the underlying GuzzleHttp\Message\Response object to access all it's info, eg:
$response = $status->getResponse();
// Get protocol info from the response
$protocol = $response->getProtocolVersion();
Checkout the Guzzle Response class with all the available functions at Guzzles API
$ phpunit
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.