Optimizing Development Workflows with Laravel Herd 1.11: From Profiling to Production
Overview
herd.yml specification, deep visibility via the integrated
Prerequisites
To follow this tutorial, you should have a baseline understanding of the
Key Libraries & Tools
- Laravel Herd: A lightning-fast native macOS development environment.
- Laravel Forge: A server management and deployment service.
- SPX: A low-overhead PHP profiling extension.
- Laravel Reverb: A first-party WebSocket server for Laravel.
Automating Environments with herd.yml
The introduction of herd.yml is a massive win for team collaboration. Instead of manually documenting PHP versions or required services, you now codify them. Running herd init in your terminal triggers an interactive setup that detects your current environment and creates a configuration file. This file ensures that every developer on your team uses the exact same PHP version, secures the site via HTTPS, and spins up the necessary services like
# Example herd.yml structure generated after herd init
name: example-app
php: 8.3
https: true
services:
- mysql
- redis
- typesense
integrations:
forge: demo-site-id
When a new developer pulls the repository, they simply run herd init. The tool reads the YAML file and automatically configures the local site to match the project requirements, including port assignments and service dependencies.
Deep Performance Profiling with SPX
Performance bottlenecks often hide in plain sight. Herd 1.11 integrates php prefix with herd profile.
# Profile a slow Artisan command
herd profile artisan slow-command
For web requests, Herd provides a dedicated dashboard at /herd/profiler. Once enabled, it captures detailed call graphs for every request. This allows you to inspect the execution time of specific methods, such as a slow Sleep() call or a heavy database interaction, with microsecond precision.
Advanced Debugging with the Enhanced Dump UI
The dump() outputs to capture database queries, view data, and outgoing HTTP requests. A standout feature is the automatic variable name detection. If you dump a variable named $user, the UI explicitly labels it as such, removing the guesswork when multiple objects are dumped in sequence.
Furthermore, the Query tab now allows for duration thresholds. You can configure the UI to ignore fast queries and only display those exceeding 700ms, immediately highlighting potential database optimizations without cluttering your log with routine lookups.
Syntax Notes and Best Practices
- Active Profiling: Use the
herd profilecommand only when debugging; whileSPXis low-overhead, the generated reports consume disk space. - Version Control: Always commit your
herd.ymlfile toproducts/Git. It serves as the single source of truth for your local environment setup. - Secure WebSockets: When using Laravel Reverb, always enable the "Serve over HTTPS" option in Herd settings to maintain protocol consistency with your secured local site.
Tips & Gotchas
- Read-Only Environment: The new Laravel Forgeintegration displays your remote
.envfile in a read-only view. This prevents accidental production changes but means you must use the Forge web UI for edits. - Forge CLI Context: The products/Forge CLInow automatically detects your site context because of
herd.yml. You no longer need to manually specify server IDs when runningforge deploy-logsorforge ssh.
