viirre / urlchecker
Simple utility package to check the status of a URL (status code, response time etc).
Installs: 2 809
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=7.0
- guzzlehttp/guzzle: ~6.0
Requires (Dev)
- phpunit/phpunit: 6.*
This package is auto-updated.
Last update: 2024-10-27 23:03:02 UTC
README
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.