viirre/urlchecker

Simple utility package to check the status of a URL (status code, response time etc).

v0.3 2018-01-29 19:48 UTC

This package is auto-updated.

Last update: 2024-10-27 23:03:02 UTC


README

Latest Version Software License Build Status

Quality Score

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.

Install

Via Composer

$ composer require viirre/urlchecker

Usage

require_once 'vendor/autoload.php';

$url = 'http://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

Testing

$ phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.