viirre/urlchecker

一个简单的工具包,用于检查URL的状态(状态码、响应时间等)。

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

This package is auto-updated.

Last update: 2024-09-27 22:51:52 UTC


README

Latest Version Software License Build Status

Quality Score

此包允许您检查URL的状态,以便轻松地检查它是否“在线”。它使用PSR 1/2。它使用Guzzle与URL进行通信。

安装

通过Composer

$ composer require viirre/urlchecker

用法

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();
}

关于连接有许多可以检查的内容,要获取连接所需时间,请使用

$timeInSeconds = $status->getTimeInSeconds();
$timeInMilliSeconds = $status->getTimeInMilliSeconds();

如果您想进一步深入了解,您可以访问底层的GuzzleHttp\Message\Response对象以访问所有相关信息,例如

$response = $status->getResponse();

// Get protocol info from the response
$protocol = $response->getProtocolVersion();

有关Guzzle Response类及其所有可用函数的详细信息,请参阅Guzzle API

测试

$ phpunit

贡献

有关详细信息,请参阅CONTRIBUTING

鸣谢

许可

MIT许可(MIT)。有关更多信息,请参阅许可文件