- How do I install audunru/memory-usage in a Laravel application?
- Install it with Composer by running composer require audunru/memory-usage. The package ships a service provider that Laravel's package auto-discovery registers automatically, so no manual provider entry is needed. Publish the config file with php artisan vendor:publish, then register the middleware in your HTTP kernel or on a route group. Pin the constraint to ^5.1.1 so you do not pull in the peak memory reset bug from 5.1.0.
- Which Laravel and PHP versions does audunru/memory-usage support?
- The authoritative source is the require block in the package's composer.json, so check it against your runtime before adopting. Confirm explicitly that your exact Laravel major (including Laravel 12) and PHP version (including PHP 8.4) are covered rather than assuming forward compatibility. If you run Octane, treat that as a separate gating compatibility check.
- Does memory-usage work correctly with Laravel Octane and Swoole?
- Peak memory in PHP is process-scoped and memory_get_peak_usage does not reset on its own, so per-request figures are only meaningful if the package resets the peak between matched requests. Version 5.1.1 fixes exactly that: resetting peak memory usage per matched request, which is the behaviour long-running workers need. Verify the fix under Octane or Swoole in staging before trusting production numbers, because worker reuse is the case that exposes the problem.
- What does a matched request mean in the memory-usage configuration?
- It means selective instrumentation: the middleware only records memory for requests that match the routes or patterns you list, rather than capturing every request globally. This is the configuration you want in production, since it keeps matching overhead and log volume confined to endpoints you actually care about. Check the published config file for the exact matching keys your version supports, such as route names or URI patterns, and start with a small set of high-memory-suspect routes.
- Why are my logged memory figures inflated or not resetting between requests?
- Version 5.1.0 accumulated peak memory across matched requests instead of resetting it, so any numbers collected on 5.1.0 for multiple matched requests in the same process are inflated and not comparable to 5.1.1. Pin audunru/memory-usage to ^5.1.1, treat earlier 5.1.0 output as unusable, and discard it rather than attempting to normalise it. Re-establish a clean baseline after upgrading before building any dashboards or thresholds.
- How much overhead does the memory-usage middleware add per request?
- The measurement itself is a cheap call into PHP's memory functions, so per-request overhead is small but nonzero. The larger cost is log write volume, which scales linearly with the number of instrumented requests. Scope the middleware to specific routes or add request sampling before enabling it broadly, and measure the real overhead in staging rather than assuming it is free.
- Where does memory-usage write its output, and can I ship it to a log aggregator?
- It emits the recorded peak memory to a Laravel log channel, so point it at a dedicated channel instead of your default application log if you intend to keep the data. Configure retention and rotation on that channel, and confirm the line format is structured enough for your aggregator to parse. Log volume grows with instrumented request volume, so factor that into your retention planning.
- Is audunru/memory-usage a replacement for Laravel Pulse or Telescope?
- No. It is a narrow, single-metric package that logs PHP peak memory per matched request, while Pulse, Telescope and commercial APMs cover queries, requests, cache, exceptions and dashboards. If you already run an APM with memory graphs, this package is largely redundant and should be scoped to a targeted diagnostic instead of a permanent dependency. If your team has no memory visibility at all, it is a cheap, credible gap-filler for debugging suspected leaks on heavy endpoints.
- How do I test that memory-usage is logging correctly?
- Write a feature test that hits a matched route and asserts a log entry is written on the configured channel. Confirm config caching works with php artisan config:cache and that middleware ordering does not bypass the package. Because peak memory is process-scoped, assert on the presence and shape of the entry rather than exact byte values.
- Is audunru/memory-usage actively maintained?
- It is a small, single-maintainer package, so weigh the bus factor accordingly and review recent commits, releases, the CI matrix and the license before committing to it. The 5.1.1 patch is a good signal that correctness issues get addressed. Keep the dependency version-pinned and read the changelog on every upgrade.