Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Health Laravel Package

spatie/laravel-health

Monitor your Laravel app’s health by registering checks (disk space, etc.) with warning/fail thresholds. Get notified via mail or Slack when checks degrade, and extend with custom checks for proactive alerting.

View on GitHub
Deep Wiki
Context7

title: Ping weight: 15

This check will send a request to a given URL. It will report a failure when that URL doesn't respond with a successful response code within a second.

This check relies on cache.

Usage

Here's how you can register the check.

use Spatie\Health\Facades\Health;
use Spatie\Health\Checks\Checks\PingCheck;

Health::checks([
    PingCheck::new()->url('https://example.com'),
]);

Customizing the timeout

You can use timeout() to set the maximum number of seconds the HTTP request should run for before the PingCheck fails.

use Spatie\Health\Facades\Health;
use Spatie\Health\Checks\Checks\PingCheck;

Health::checks([
    PingCheck::new()->url('https://example.com')->timeout(2),
]);

If you need more precise control, you can use timeoutMs() to set the timeout in milliseconds.

use Spatie\Health\Facades\Health;
use Spatie\Health\Checks\Checks\PingCheck;

Health::checks([
    PingCheck::new()->url('https://example.com')->timeoutMs(500),
]);

Customizing the name

You can use name() to change the title of the PingCheck. This is useful when you have multiple PingChecks and you want to distinguish them from each other easily.

use Spatie\Health\Facades\Health;
use Spatie\Health\Checks\Checks\PingCheck;

Health::checks([
    PingCheck::new()->url('https://example.com')->name('Example'),
    PingCheck::new()->url('https://spatie.be')->name('Spatie'),
]);

Customizing the retry times

You can use retryTimes() to set the number of times to retry the PingCheck before failing.

use Spatie\Health\Facades\Health;
use Spatie\Health\Checks\Checks\PingCheck;

Health::checks([
    PingCheck::new()->url('https://example.com')->retryTimes(3),
]);

Fail after minutes

By default, the check will immediately report a failure when the URL is unreachable. You can use failAfterMinutes() to delay the failure status. When this option is set, the check will first report a warning status when the URL becomes unreachable. Only if the URL remains unreachable for the specified number of minutes, the check will transition to a failed status.

This is useful to avoid false alarms caused by temporary network issues or brief service interruptions.

use Spatie\Health\Facades\Health;
use Spatie\Health\Checks\Checks\PingCheck;

Health::checks([
    PingCheck::new()
        ->url('https://example.com')
        ->failAfterMinutes(5),
]);

In this example, the check will return a warning for the first 5 minutes of unreachability, and only after that will it report a failure.

Customize the cache store

The failAfterMinutes feature relies on cache to work. It will write a timestamp of the first failure into the cache that will be verified on subsequent checks. You can use useCacheStore() to specify a different cache store.

use Spatie\Health\Facades\Health;
use Spatie\Health\Checks\Checks\PingCheck;

Health::checks([
    PingCheck::new()
        ->url('https://example.com')
        ->failAfterMinutes(5)
        ->useCacheStore('your-custom-store-name'),
]);

Optionally, you can use cacheKeyPrefix() to customize the prefix used for the cache key. The default prefix is health:checks:ping.

PingCheck::new()
    ->url('https://example.com')
    ->failAfterMinutes(5)
    ->cacheKeyPrefix('my-app:health:ping'),
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport