tourze/symfony-memory-watch-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tourze/symfony-memory-watch-bundle

最新稳定版本:0.0.2

Composer 安装命令:

composer require tourze/symfony-memory-watch-bundle

包简介

README 文档

README

English | 中文

Latest Version Total Downloads

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

After installation, the bundle is ready to use with zero configuration. It will automatically:

  1. Monitor memory usage - Track memory consumption for each request
  2. Log warnings - Alert when memory usage exceeds 50MB threshold
  3. Clean up automatically - Use WeakMap to prevent memory leaks

The bundle logs to your application's default logger when memory usage exceeds the threshold. Check your logs to see output like:

[2024-01-01 12:00:00] app.WARNING: 内存使用超过阈值 {"使用内存":75.5,"内存阈值":"50MB"}

No additional configuration is required - the bundle works out of the box.

How It Works

The bundle uses an event subscriber to:

  1. Record memory usage at the beginning of the request
  2. Measure memory usage at the end of the request
  3. 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.

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-31