This package for PHP provide a class to check the URL HTTP response without downloading the HTTP content in response.
This reduces the bandwidth and the response time.
Hey folks,
Do you like this package? Do you find it useful and it fits well in your project?
I am glad to help you, and I would be so grateful if you considered supporting my work.
You can even choose 😃:
- You can sponsor me 😎 with a monthly subscription.
- You can buy me a coffee ☕ or a pizza 🍕 just for this package.
- You can plant trees 🌴. By using this link we will both receive 30 trees for free and the planet (and me) will thank you.
- You can "Star ⭐" this repository (it's free 😉).
You can install the package via composer:
composer require lemaur/php-url-checker
The class Lemaur\UrlChecker\UrlChecker
provides a static method check
where accepts the URL to check as first parameter
and the user agent string as a second parameter.
Here you can see how to use it 👇
use Lemaur\UrlChecker\UrlChecker;
$response = UrlChecker::check(
url: 'https://google.com',
userAgent: 'MyApp/1.0 (UrlChecker)',
connectTimeout: 5,
timeout: 10,
);
// \Lemaur\UrlChecker\DataTransferObject\CheckData
$response->statusCode;
// (int) 200
$response->reasonPhrase;
// (string) 'OK'
$response->headers:
// (array) ['Date' => ['Sun, 24 Mar 2024 09:06:08 GMT']]
That class also provides another method to help you write unit tests.
It mocks the response to prevents any external network call. It accepts an array of GuzzleHttp\Psr7\Response
.
UrlChecker::fake([
new \GuzzleHttp\Psr7\Response(200),
]);
$response = UrlChecker::check('https://dummy-url.com');
$response->statusCode;
// (int) 200
composer test
Please see CHANGELOG for more information what has changed recently.
Please review our security policy on how to report security vulnerabilities.
This package has been inspired by Chris White's blog post.
The MIT License (MIT). Please see License File for more information.