Ping | laravel-health | Spatie

 SPATIE

  Laravel Health
=================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-health](https://spatie.be/docs/laravel-health/v1)  Available-checks  Ping

 Version   v1

 Other versions for crawler [v1](https://spatie.be/docs/laravel-health/v1)

- [ Introduction ](https://spatie.be/docs/laravel-health/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-health/v1/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-health/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-health/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-health/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-health/v1/changelog)
- [ About us ](https://spatie.be/docs/laravel-health/v1/about-us)

Usage
-----

- [ Registering your first check ](https://spatie.be/docs/laravel-health/v1/basic-usage/registering-your-first-check)
- [ Creating custom checks ](https://spatie.be/docs/laravel-health/v1/basic-usage/creating-custom-checks)
- [ Manually running checks ](https://spatie.be/docs/laravel-health/v1/basic-usage/manually-running-checks)
- [ Conditionally running or modifying checks ](https://spatie.be/docs/laravel-health/v1/basic-usage/conditionally-running-or-modifying-checks)
- [ Endpoints ](https://spatie.be/docs/laravel-health/v1/basic-usage/endpoints)
- [ Pausing and resuming checks ](https://spatie.be/docs/laravel-health/v1/basic-usage/pausing-and-resuming-checks)
- [ Registering the same check multiple times ](https://spatie.be/docs/laravel-health/v1/basic-usage/registering-the-same-check-multiple-times)
- [ Testing ](https://spatie.be/docs/laravel-health/v1/basic-usage/testing)

Storing results
---------------

- [ General ](https://spatie.be/docs/laravel-health/v1/storing-results/general)
- [ As JSON ](https://spatie.be/docs/laravel-health/v1/storing-results/in-a-json-file)
- [ In the cache ](https://spatie.be/docs/laravel-health/v1/storing-results/in-cache)
- [ In the database ](https://spatie.be/docs/laravel-health/v1/storing-results/in-the-database)
- [ Not storing results ](https://spatie.be/docs/laravel-health/v1/storing-results/not-storing-results)

Configuring notifications
-------------------------

- [ General ](https://spatie.be/docs/laravel-health/v1/configuring-notifications/general)
- [ Via mail ](https://spatie.be/docs/laravel-health/v1/configuring-notifications/via-mail)
- [ Via Slack ](https://spatie.be/docs/laravel-health/v1/configuring-notifications/via-slack)
- [ Via Oh Dear ](https://spatie.be/docs/laravel-health/v1/configuring-notifications/via-oh-dear)

Viewing check results
---------------------

- [ General ](https://spatie.be/docs/laravel-health/v1/viewing-results/general)
- [ On a webpage ](https://spatie.be/docs/laravel-health/v1/viewing-results/on-a-webpage)
- [ On the CLI ](https://spatie.be/docs/laravel-health/v1/viewing-results/on-the-cli)
- [ As JSON ](https://spatie.be/docs/laravel-health/v1/viewing-results/as-json)

Available checks
----------------

- [ Overview ](https://spatie.be/docs/laravel-health/v1/available-checks/overview)
- [ Backups ](https://spatie.be/docs/laravel-health/v1/available-checks/backups)
- [ Application Cache ](https://spatie.be/docs/laravel-health/v1/available-checks/cache)
- [ Cached config, routes, and events ](https://spatie.be/docs/laravel-health/v1/available-checks/cached-config-routes-and-events)
- [ CPU load ](https://spatie.be/docs/laravel-health/v1/available-checks/cpu-load)
- [ DB connection ](https://spatie.be/docs/laravel-health/v1/available-checks/db-connection)
- [ DB connection count ](https://spatie.be/docs/laravel-health/v1/available-checks/db-connection-count)
- [ DB size ](https://spatie.be/docs/laravel-health/v1/available-checks/db-size-check)
- [ DB table size ](https://spatie.be/docs/laravel-health/v1/available-checks/db-table-size-check)
- [ Debug mode ](https://spatie.be/docs/laravel-health/v1/available-checks/debug-mode)
- [ Environment ](https://spatie.be/docs/laravel-health/v1/available-checks/environment)
- [ Flare error count ](https://spatie.be/docs/laravel-health/v1/available-checks/flare-error-count)
- [ Horizon ](https://spatie.be/docs/laravel-health/v1/available-checks/horizon)
- [ Meilisearch ](https://spatie.be/docs/laravel-health/v1/available-checks/meilisearch)
- [ Ping ](https://spatie.be/docs/laravel-health/v1/available-checks/ping)
- [ Queue ](https://spatie.be/docs/laravel-health/v1/available-checks/queue)
- [ Redis ](https://spatie.be/docs/laravel-health/v1/available-checks/redis)
- [ Redis memory usage ](https://spatie.be/docs/laravel-health/v1/available-checks/redis-memory-usage)
- [ Schedule ](https://spatie.be/docs/laravel-health/v1/available-checks/schedule)
- [ Security advisories ](https://spatie.be/docs/laravel-health/v1/available-checks/security-advisories)
- [ Used disk space ](https://spatie.be/docs/laravel-health/v1/available-checks/used-disk-space)

Security
--------

- [ Using Secret Token ](https://spatie.be/docs/laravel-health/v1/security/using-secret-token)

 Ping
====

###  On this page

1. [ Usage ](#content-usage)

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 `PingCheck`s 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'),
```
