# Symfony

> Once you add the pulse-si/symfony bundle and start the worker, Pulse finds your Doctrine connections, Redis, Messenger transports, and Scheduler.

- Section: Packages
- Availability: From the Free plan, logs on Pro and Team. PHP 8.1 or later, Symfony 6.4 to 8.
- URL: https://pulse-app.si/en/docs/packages/symfony

## Install

**zsh**

```bash
composer require pulse-si/symfony
```

Add the bundle if it isn’t already there:

**config/bundles.php**

```php
return [
    Pulse\Symfony\PulseBundle::class => ['all' => true],
];
```

Put the key the Pulse app shows you in `.env.local`, then start the worker next to your app, like `messenger:consume`:

**zsh**

```bash
echo "PULSE_KEY=pk_live_…" >> .env.local
bin/console pulse:work
```

The first report goes out 2 seconds later. For a one-off test, `bin/console pulse: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.

## 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/nimbus/bin/console pulse:work
autostart=true
autorestart=true
stopwaitsecs=15
user=www-data
```

### systemd

**pulse.service**

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

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

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

### Docker Compose

**compose.yaml**

```yaml
services:
  pulse:
    image: nimbus-app
    command: php bin/console pulse:work
    env_file: .env.local
    restart: unless-stopped
```

> **Several containers**
>
> The worker, `messenger:consume` and your requests share the `var/pulse/` folder. Mount `var/` 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 |
| --- | --- | --- |
| Doctrine DBAL connections | `SELECT 1`, the platform’s neutral query | PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle |
| `\Redis`, `Predis\ClientInterface`, `Relay\Relay` services, cache pools on Redis | `PING` | Redis |
| Messenger transports that can count (Doctrine, Redis, SQS…) | Reads the number of waiting messages | `File async`, `File failed`… |
| Scheduler (`#[AsSchedule]`, `#[AsCronTask]`, `#[AsPeriodicTask]`) | Expression, last and next run, success | The job’s message |

Each check has 5 seconds to respond and only reads. The bundle writes only to `var/pulse/`. AMQP transports aren’t counted, because querying them would declare the queue. 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 its message (`RenewSubscriptions`), the command for a `RunCommandMessage` (`app:renew`), or the service for `#[AsCronTask]`. Runs are recorded by `messenger:consume scheduler_default` itself. A handler that throws counts as a failure, with its message.

For work that doesn’t go through the Scheduler (a system cron, a command), wrap it with the `Pulse\Pulse` service. If it fails, the failure is recorded and the error comes back to you unchanged.

**src/Command/RenewCommand.php**

```php
use Pulse\Pulse;

public function __construct(private Pulse $pulse) {}

public function __invoke(): void
{
    $this->pulse->track('renew-subscriptions', fn () => $this->subscriptions->renew());
}
```

## Choose what is sent

The heartbeat is always sent. The rest is set by [variables](https://pulse-app.si/en/docs/packages/variables), or in YAML, which takes priority over them. No configuration is required.

**config/packages/pulse.yaml**

```yaml
pulse:
    send: checks,crons,logs
    exclude: 'File failed'
    log_level: WARN
    http_probes:
        'Route /health': 'https://nimbus.example/health'
```

`auto_detect: false` turns off the dependency search, and `directory` changes the `var/pulse/` folder.

## Logs

On Pro and Team, with MonologBundle, the bundle declares a `pulse` handler that receives every channel except `event`. It runs after your handlers and never stops a message from passing on. Level and channel are kept, and secrets masked.

**dev.log**

```text
app.ERROR: Payment declined token=abc123
ERROR  app  Payment declined token=***
```

The handler writes each cleaned line to `var/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.local`, or the service’s variables. |
| `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 `messenger:consume scheduler_default` with the same `PULSE_KEY` as the worker. |
| No logs | MonologBundle must be installed. The web and the consumers must see the same `PULSE_KEY` and the same `var/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.
