lemaur / php-url-checker
Check the url response status code and reason phrase.
Fund package maintenance!
lemaur
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.8
Requires (Dev)
- ergebnis/composer-normalize: ^2.42
- laravel/pint: ^1.0
- pestphp/pest: ^2.20
- pestphp/pest-plugin-type-coverage: ^2.8
- phpstan/phpstan: ^1.10
- rector/rector: ^1.0
- roave/security-advisories: dev-latest
README
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.
Support Me
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 😉).
Installation
You can install the package via composer:
composer require lemaur/php-url-checker
Usage
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
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Security Vulnerability
Please review our security policy on how to report security vulnerabilities.
Credits
This package has been inspired by Chris White's blog post.
License
The MIT License (MIT). Please see License File for more information.