# Laravel

> Install pulse-si/laravel, add the key, and start the worker. Pulse finds your database, Redis, queue, and schedule, and alerts you when one of them has a problem.

- Section: Packages
- Availability: From the Free plan, logs on Pro and Team. PHP 8.1 or later, Laravel 10 to 13.
- URL: https://pulse-app.si/en/docs/packages/laravel

## Install

1. Install the package. Laravel discovers it automatically.
2. Add the key the Pulse app shows you to `.env`, and keep it out of version control.
3. Start the worker next to your app, like `queue:work`.

**zsh**

```bash
composer require pulse-si/laravel
echo "PULSE_KEY=pk_live_…" >> .env
php artisan pulse-app:work
```

The first report goes out 2 seconds later. For a one-off test, `php artisan pulse-app:report` sends a single report and shows what was measured. A PHP request is too short to carry a report, so nothing is sent from a web request and everything goes through this worker.

> **Why the pulse-app prefix**
>
> Commands and configuration carry this prefix so they can coexist with Laravel Pulse, Laravel’s official tool, which already has `pulse:work` and `config/pulse.php`.

## Keep the worker running

The worker follows the pace set by the API. It stops cleanly on `SIGTERM` and `SIGINT` with the `pcntl` extension. A supervisor restarts it if it stops.

### Supervisor

**pulse.conf**

```text
[program:pulse]
command=php /var/www/helio/artisan pulse-app:work
autostart=true
autorestart=true
stopwaitsecs=15
user=www-data
```

### systemd

**pulse.service**

```text
[Unit]
Description=Pulse for Helio
After=network-online.target

[Service]
WorkingDirectory=/var/www/helio
ExecStart=/usr/bin/php artisan pulse-app:work
Restart=always
User=www-data

[Install]
WantedBy=multi-user.target
```

### Docker Compose

**compose.yaml**

```yaml
services:
  pulse-app:
    image: helio-app
    command: php artisan pulse-app:work
    env_file: .env
    restart: unless-stopped
```

> **Several containers**
>
> The worker, `schedule:run` and your requests share the `storage/pulse/` folder. Mount `storage/` as a shared volume, or at least that folder. Otherwise, scheduled jobs and logs never reach the worker.

## What Pulse finds automatically

| Dependency found | What Pulse does | Name shown |
| --- | --- | --- |
| Default database connection (`pgsql`, `mysql`, `mariadb`, `sqlite`, `sqlsrv`, `oracle`, `mongodb`) | `SELECT 1`, `ping` for MongoDB | PostgreSQL, MySQL, MariaDB… |
| Redis, if it serves as the default cache, queue, session or broadcast | `PING` | Redis |
| Default queue, except `sync`, `null`, `deferred` and `background` | Reads the number of waiting jobs | `File default`, `File emails`… |
| Schedule from `routes/console.php` or the Kernel | Expression, last and next run, success | The job’s name |

Each check has 5 seconds to respond and only reads. The package writes only to `storage/pulse/`. A failing dependency, a job that crashed, or one more than 5 minutes past its scheduled run turns the app **Degraded**.

## Scheduled jobs

A job’s name is the one you give it with `->name()`, otherwise the Artisan command (`helio:renew`). Runs are recorded by `schedule:run` itself. A command that exits with a non-zero code or a closure that throws counts as a failure.

For work that doesn’t go through Laravel’s schedule (a system cron, a script), wrap it. If it fails, the failure is recorded and the error comes back to you unchanged.

**RenewSubscriptions.php**

```php
use Pulse\Laravel\Facades\Pulse;

Pulse::track('renew-subscriptions', fn () => $subscriptions->renew());
```

## Choose what is sent

The heartbeat is always sent. The rest is set in `.env`, with [the same variables](https://pulse-app.si/en/docs/packages/variables) as the other packages. For a configuration file, with an extra route to monitor:

**zsh**

```bash
php artisan vendor:publish --tag=pulse-app-config
```

**config/pulse-app.php**

```php
'http_probes' => [
    'Route /health' => 'https://helio.example/health',
],
```

This file reads `.env`, so `php artisan config:cache` stays accurate. After changing a variable, rebuild the cache or run `php artisan config:clear`. `'auto_detect' => false` turns off the dependency search.

## Logs

On Pro and Team, the package copies what your app writes to the default channel (the one in `LOG_CHANNEL`, stacks included). It adds a Monolog handler at the end of the channel. Your handlers write first, none is removed, and there’s nothing to change in `config/logging.php`. Level and channel are kept, and secrets masked.

**laravel.log**

```text
[2026-10-20 12:12:56] production.ERROR: Payment declined token=abc123
ERROR  production  Payment declined token=***
```

The handler writes each cleaned line to `storage/pulse/logs.ndjson`, 1000 lines at most, and the worker empties that file every 10 seconds, or every second when a device is viewing the app. Until Pulse confirms your plan keeps logs, nothing is written. If the worker stops, copying turns off a few minutes later.

## If nothing arrives

| Symptom | What to do |
| --- | --- |
| `PULSE_KEY is missing` | The variable isn’t loaded: check `.env`, then run `php artisan config:clear`. |
| `Pulse key refused` | The key was replaced in the app: copy the new one, then restart the worker. |
| `Pulse unreachable` | Network or firewall: the worker keeps running and sending resumes automatically. |
| No scheduled jobs | Run `schedule:run` or `schedule:work` with the same `PULSE_KEY` as the worker. |
| No logs | `schedule:run`, the queue and the web must see the same `PULSE_KEY` and the same `storage/pulse/`. |

- [PHP](https://pulse-app.si/en/docs/packages/php): The shared core, its extensions and how it works.
- [All variables](https://pulse-app.si/en/docs/packages/variables): Every setting and its default.
- [Exactly what is sent](https://pulse-app.si/en/docs/packages/payload): The precise format of reports and logs.
