Skip to content

viirre/urlchecker

Repository files navigation

urlchecker

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 = '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

Testing

$ phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

License

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

About

Checks status of a URL

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages