tourze / symfony-memory-watch-bundle
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.1
- psr/log: ^3|^2|^1
- symfony/framework-bundle: ^6.4
This package is auto-updated.
Last update: 2025-03-31 00:31:15 UTC
README
A Symfony bundle that monitors and logs memory usage in your application during the request lifecycle.
Features
- Monitors memory usage between request and response
- Logs warnings when memory usage exceeds defined thresholds
- Zero configuration required to get started
- Works with Symfony's PSR-compatible logging
- Lightweight with minimal performance impact
Installation
composer require tourze/symfony-memory-watch-bundle
Register the bundle
For Symfony applications using Flex, the bundle should be automatically registered. Otherwise, add it manually to your config/bundles.php
:
<?php return [ // ... Tourze\MemoryWatchBundle\MemoryWatchBundle::class => ['all' => true], ];
Quick Start
The bundle works automatically after installation, monitoring memory usage with a default threshold of 50MB.
You can customize the memory threshold by creating a bundle configuration file:
# config/packages/memory_watch.yaml services: Tourze\MemoryWatchBundle\EventSubscriber\MemoryWatchSubscriber: properties: memoryThresholdMB: 100 # Set your custom threshold in MB
How It Works
The bundle uses an event subscriber to:
- Record memory usage at the beginning of the request
- Measure memory usage at the end of the request
- Log a warning when the difference exceeds the configured threshold
Memory usage data is collected using PHP's memory_get_usage()
function. The bundle uses a WeakMap
to associate memory measurements with request objects, ensuring no memory leaks occur.
Requirements
- PHP 8.1+
- Symfony 6.4+
- PSR-compatible logger
Contributing
Contributions are welcome! Feel free to submit a pull request.
License
The MIT License (MIT). Please see License File for more information.