laravel/pulse
Laravel Pulse is a real-time performance monitoring tool for Laravel. It provides a dashboard to track application health and key metrics, helping you identify bottlenecks and issues quickly in development and production environments.
## Getting Started
### Minimal Setup
1. **Installation**:
```bash
composer require laravel/pulse
php artisan pulse:install
This publishes the Pulse migration, config, and assets.
Run Migrations:
php artisan migrate
Start Pulse:
php artisan pulse:work
This starts the Pulse worker in the foreground. For production, use a process manager like Supervisor.
Access Dashboard:
Visit /pulse in your browser (ensure your app is running).
Illuminate\Http\Request).Illuminate\Queue\Jobs\Job).Illuminate\Database\Connection).Livewire\Component).use Laravel\Pulse\Facades\Pulse;
Pulse::record('custom_event', ['key' => 'value']);
Pulse::set('custom_metric', 42); // Incremental counter
// config/pulse.php
'cards' => [
\App\Pulse\Cards\ApiRateLimitCard::class,
],
Implement the Laravel\Pulse\Contracts\Card contract:
namespace App\Pulse\Cards;
use Laravel\Pulse\Contracts\Card;
class ApiRateLimitCard implements Card {
public function title(): string { return 'API Rate Limits'; }
public function render(): string { /* ... */ }
public function data(): array { return ['limits' => $this->fetchRateLimits()]; }
}
local environments or restrict access:
// config/pulse.php
'environments' => ['production', 'staging'],
'private_tunnel' => [
'enabled' => env('PULSE_TUNNEL_ENABLED', false),
'environments' => ['local'],
],
// config/pulse.php
'trim' => [
'duration' => '30 days',
],
Run the trim command manually:
php artisan pulse:trim
// config/pulse.php
'livewire' => [
'enabled' => true,
'highlighting' => true, // Syntax highlighting for Livewire code
],
// config/pulse.php
'thresholds' => [
'jobs' => [
'slow' => 5000, // ms
],
],
// config/pulse.php
'thresholds' => [
'queries' => [
'slow' => 100, // ms
'regex' => 'SELECT.*FOR UPDATE', // Custom regex patterns
],
],
Ingest logic:
// app/Providers/PulseServiceProvider.php
public function boot() {
Pulse::ingest(function ($data) {
// Forward data to Sentry, etc.
Sentry::captureEvent($data);
});
}
Worker Process Management:
pulse:work). In production, use Supervisor or similar:
[program:pulse]
command=php /path/to/artisan pulse:work
autostart=true
autorestart=true
Database Load:
trim.duration or use a read replica.pulse:trim --dry-run to test retention policies.Livewire Version Conflicts:
composer require livewire/livewire:^4.0
Private Tunnel Security:
private_tunnel feature exposes Pulse in local environments. Restrict access:
'private_tunnel' => [
'environments' => ['local'],
'ip' => '192.168.1.100', // Whitelist IPs
],
.env to toggle:
PULSE_TUNNEL_ENABLED=false
Custom Card Caching:
php artisan cache:clear
shouldCache() in your card to opt out.Enum Support:
Pulse::record() and Pulse::set():
Pulse::record('status', UserStatus::Active);
Redis Serialization:
// config/database.php
'redis' => [
'client' => 'phpredis',
'options' => [
'serialize' => \Illuminate\Redis\Connections\Connection::SERIALIZER_PHP,
],
],
Slow Query Highlighting:
'queries' => [
'highlighting' => false,
],
pulse:reload to refresh the dashboard after config changes.Environment Detection:
local vs. development). Override detection:
// app/Providers/PulseServiceProvider.php
Pulse::detectEnvironment(function () {
return app()->environment('staging') ? 'staging' : config('app.env');
});
Memory Leaks:
pulse:work. Upgrade and restart the worker:
php artisan pulse:work --stop
php artisan pulse:work
Check Worker Logs:
tail -f storage/logs/pulse.log
Enable Debug Mode:
// config/pulse.php
'debug' => true,
Test Locally with Tunneling:
php artisan pulse:tunnel
Access via the provided URL (e.g., https://pulse-12345.ngrok.io).
Inspect Raw Data:
Use the pulse:export command to dump data for analysis:
php artisan pulse:export --format=json > pulse_data.json
Custom Ingest Logic:
Extend Laravel\Pulse\Ingest to modify or enrich data before storage:
Pulse::extend(function ($ingest) {
$ingest->listen('request', function ($payload) {
$payload['custom_field'] = 'value';
return $payload;
});
});
Override Default Cards:
Replace built-in cards (e.g., RequestsCard) by binding your own:
// app/Providers/PulseServiceProvider.php
public function boot() {
Pulse::
How can I help you explore Laravel packages today?