Download the PHP package yousefkadah/laravel-memory-profiler without Composer
On this page you can find all versions of the php package yousefkadah/laravel-memory-profiler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yousefkadah/laravel-memory-profiler
More information about yousefkadah/laravel-memory-profiler
Files in yousefkadah/laravel-memory-profiler
Package laravel-memory-profiler
Short Description A Laravel package for memory profiling Artisan commands without Xdebug
License MIT
Informations about the package laravel-memory-profiler
Laravel Memory Profiler
A Laravel package that provides memory profiling capabilities for Artisan commands without requiring Xdebug. This package helps developers identify memory leaks and optimize memory usage in their Laravel applications.
Features
- 🔍 Memory Leak Detection: Automatically detect memory leaks in long-running commands
- 📊 Visual Reports: Generate HTML reports with interactive charts
- 📈 Real-time Monitoring: Track memory usage over time during command execution
- 🗄️ Database Query Tracking: Monitor database queries that might cause memory issues
- ⚡ No Xdebug Required: Works without any external profiling extensions
- 🎯 Easy Integration: Simple flag-based profiling for any Artisan command
- 📋 Multiple Formats: Generate reports in JSON, HTML, or both formats
Installation
Install the package via Composer:
The package will automatically register its service provider.
Publish the configuration file (optional):
Usage
Basic Usage
Profile any Artisan command by prefixing it with profile:memory
:
Advanced Usage
Real-world Examples
Understanding the Reports
HTML Report
The HTML report includes:
- Summary Section: Key metrics like execution time, peak memory, and memory difference
- Memory Chart: Interactive chart showing memory usage over time
- Potential Issues: Automated analysis highlighting possible problems
- Sample Data: Detailed breakdown of memory usage at different time points
JSON Report
The JSON report contains:
- Command information and arguments
- Execution timing data
- Memory usage samples
- Database query logs (if enabled)
- Garbage collection statistics
- Automated analysis results
Key Metrics
- Peak Memory: Maximum memory usage during execution
- Memory Difference: Difference between final and initial memory usage
- Memory Trend: Whether memory usage is increasing, decreasing, or stable
- Potential Issues: Automated detection of memory leaks and high usage
Configuration
The package can be configured via the config/memory-profiler.php
file:
Detecting Memory Leaks
Common Signs of Memory Leaks
- Positive Memory Difference: Final memory usage is significantly higher than initial
- Increasing Memory Trend: Memory usage consistently grows over time
- High Peak Memory: Memory usage exceeds reasonable thresholds
Common Causes and Solutions
1. Eloquent Model Accumulation
2. Database Query Log Growth
3. Static Variable Accumulation
Best Practices
- Profile Long-running Commands: Focus on commands that run for extended periods
- Use Chunking: Process large datasets in smaller chunks
- Monitor Database Queries: Watch for N+1 queries and excessive query logging
- Clear Static Variables: Reset static caches in long-running processes
- Force Garbage Collection: Use
gc_collect_cycles()
if needed - Set Memory Limits: Use
--memory
option for queue workers
Troubleshooting
High Memory Usage
If you see high memory usage:
- Check the database query count in the report
- Look for increasing memory trends
- Examine the timing of peak memory usage
- Review your code for static variable accumulation
Inaccurate Results
If results seem inaccurate:
- Reduce the sampling interval for more precision
- Ensure no other processes are affecting memory
- Run the profiler multiple times for consistency
- Check if garbage collection is affecting measurements
Performance Impact
The profiler has minimal performance impact, but you can:
- Increase sampling interval to reduce overhead
- Disable database query tracking if not needed
- Use JSON format only for faster report generation
Requirements
- PHP 7.4 or higher
- Laravel 8.0, 9.0, 10.0, or 11.0
- Sufficient disk space for reports
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This package is open-sourced software licensed under the MIT license.
Support
If you discover any security vulnerabilities or bugs, please send an e-mail to [email protected].
Changelog
v1.0.0
- Initial release
- Basic memory profiling functionality
- HTML and JSON report generation
- Database query tracking
- Garbage collection monitoring
All versions of laravel-memory-profiler with dependencies
illuminate/console Version ^8.0|^9.0|^10.0|^11.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0