audunru/memory-usage
A lightweight Laravel package for monitoring memory usage in your application. It provides simple helpers to read current and peak memory consumption, making it easy to log, display, or debug resource usage with minimal setup.
patterns / ignore_patterns), so we can rank endpoints by measured cost instead of by anecdote. That turns "the app feels slow/heavy" into a prioritized backlog of specific routes.warning at 10 MiB to the default channel and an emergency to Slack at 100 MiB. This gives us a cheap, two-tier early-warning capability without an APM contract — and a concrete decision to make about whether that's enough.paths rule sets carry slow_response_limit, and LogSlowResponse runs from terminate(). So one config buys memory and latency thresholds with per-path routing. Useful for sequencing "is this endpoint heavy, slow, or both?"memory_get_peak_usage is process-scoped — so use it to compare routes and releases, not to derive absolute capacity numbers.memory-usage response header, gated to configured environments, lets engineers see cost per request locally and in staging without reading logs. Low effort, meaningful reduction in "we didn't know that endpoint was heavy" surprises.Good fit when:
Look elsewhere when:
Adoption criteria we should apply: pin ^5.1.1 explicitly (never allow 5.1.0 — its matched-request figures are invalid); confirm the Laravel/PHP version matrix against our runtime including config caching; confirm middleware ordering against existing global middleware; confirm the target log channel has retention and rotation configured; assign an internal owner given maintainer concentration. Mitigating factor: the exit path is trivial — removing a middleware and a service provider — so vendor risk is bounded even at 0 GitHub stars.
To executives: This is a near-zero-cost observability add-on for our Laravel app. It writes per-route memory and slow-response lines to logs we already retain — no new infrastructure, no vendor contract, no schema change. It answers two questions we currently guess at: which endpoints cost the most memory, and did that change with the last release. The latest patch (v5.1.1) fixes a measurement defect, which is why we're adopting now and discarding any earlier trial data. Cost is bounded by log volume, which we control through path scoping rather than capturing everything. It also informs a larger decision: whether we need to buy a full APM platform, and it produces the evidence either way.
To engineering: A Laravel service provider registers two terminable global middleware. Logging happens in terminate(), after the response is sent, so streamed bodies are included and request latency isn't affected by the log write. Configuration is a single published file: paths rule sets with patterns, ignore_patterns, limit (MiB), slow_response_limit (seconds), channel, level, and optional header.environments. Rules evaluate independently, so one path can warn at one threshold and page at another. Pin ^5.1.1 — 5.1.0 accumulates peak memory across matched requests and produces inflated figures. Before rollout, verify reset behavior under Octane/queue workers if we use them, confirm the middleware can't throw into the request path, and confirm we don't silently no-op from an unpublished config or wrong middleware group. Enable on suspect routes first, sampling or path-scoping in production, not global capture on day one.
To product: Route-level memory data lets us sequence performance work by measured impact and validate whether a release actually made things better. It complements — does not replace — a profiling or APM strategy, and it is a diagnostic tool rather than a monitoring product. The one caveat to internalize: these are process-level numbers, so use them for comparison and ranking, never as an absolute per-request cost.
How can I help you explore Laravel packages today?