promphp/prometheus_client_php
Prometheus client library for PHP with counters, gauges, histograms, and summaries. Supports Redis, Predis, APCu/APCng, or in-memory storage for metric aggregation across workers, with simple APIs to register, update, and expose metrics for scraping.
CollectorRegistry binding)./metrics) via middleware or route handlers.Route::get('/metrics', fn() => $renderer->render(...))).CollectorRegistry to Laravel’s container for DI.job.processed).HandleIncomingRequest.prometheus_client_php in HandleJobs.prometheus_push_gateway_php) for ephemeral jobs (e.g., Laravel Artisan commands).laravel_job_duration_seconds > 5).| Risk Area | Mitigation Strategy |
|---|---|
| Multi-Process State | Redis/APCu adapters handle process isolation; In-Memory is unsafe for long-running processes. |
| Performance Overhead | Benchmark adapters (e.g., APCng vs. Redis) for your workload. Redis adds ~1–5ms latency. |
| Storage Dependencies | Redis/Predis require external services; APCu needs PHP extension. |
| Label Cardinality | High-cardinality labels (e.g., user_id) may bloat metrics; use sparingly. |
| Laravel Caching | APCu conflicts with Laravel’s cache; use separate Redis instances if both are needed. |
| Prometheus Scraping | Ensure /metrics endpoint is scrapeable (no auth, low TTL). |
route, user_id)?CollectorRegistry in a service provider./metrics via PrometheusMetricsMiddleware.Illuminate\Queue\Events\JobProcessed.laravel_job_duration_seconds histogram.Illuminate\Http\Request lifecycle (e.g., http_request_duration_seconds).composer.json.CollectorRegistry./metrics endpoint.http://laravel-app/metrics.error_rate > 0.01).| Component | Compatibility Notes |
|---|---|
| Laravel 10+ | Fully supported (PHP 8.2+). |
| Redis | Tested with Redis 6/7/8; ACL/auth support. |
| APCu | Requires apcu PHP extension. |
| Predis | Optional for advanced Redis features (e.g., connection pooling). |
| PDO | Supports MySQL/PostgreSQL/SQLite; useful for air-gapped deployments. |
| Prometheus | Uses standard exposition format; no version conflicts. |
instance if redundant).promphp/prometheus_client_php for PHP 8.3+ compatibility.maxmemory-policy.apc.shm_size to avoid evictions.prometheus --web.enable-labels-on-buckets to debug./metrics returns 200 OK with valid Prometheus format.promphp) for PHP-specific issues.ab or k6).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Redis Unavailable | Metrics loss for distributed apps | Fallback to In-Memory (with warnings). |
| APCu Cache Eviction | Transient metric loss | Increase apc.shm_size. |
| Prometheus Scrape Failures | Alerting gaps | Use scrape_timeout in Prometheus. |
| High Cardinality Labels | Prometheus overload | Limit labels (e.g., `le |
How can I help you explore Laravel packages today?