PHPackages                             alasaly/monitor-memory-leak - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. alasaly/monitor-memory-leak

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

alasaly/monitor-memory-leak
===========================

Monitor memory leak in php

12PHP

Since Oct 16Pushed 2y ago1 watchersCompare

[ Source](https://github.com/mohhamedion/monitor-memory-leak)[ Packagist](https://packagist.org/packages/alasaly/monitor-memory-leak)[ RSS](/packages/alasaly-monitor-memory-leak/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Memory Leak Monitor Library
===========================

[](#memory-leak-monitor-library)

Overview
--------

[](#overview)

It's generally hard to encounter memory leaks in PHP thanks to the built-in garbage collector. However, there are situations where we inadvertently create memory usage spikes, especially when dealing with heavy logic or potentially infinite loops. For example, if you're constantly updating information in your application, it can be helpful to monitor memory usage to ensure your application remains efficient and doesn't consume unnecessary resources.

The Memory Leak Monitor Library is a PHP package designed to address these concerns. It allows you to monitor memory usage in your PHP applications and trigger exceptions when memory leaks are detected, helping you identify and address memory-related issues in your code.

Installation
------------

[](#installation)

```
composer require alasaly/monitor-memory-leak

```

Usage
-----

[](#usage)

Basic Usage

```
use Alasaly\MonitorMemoryLeak\Classes\Monitor;

$monitor = new Monitor();
//By default, it will throw exception if the memory is 100% over the memory allocated to PHP
//You can modify the limits
$monitor->setAllowedMemoryLeak(1000);

//You can set this option to false if you only want to monitor memory without terminating the process
$monitor->setThrowError(false);

$data = [];
while (true)
{

    // some heavy logic

    $data[] = "==============";

   $monitor->checkMemoryLeak(function ($usedMemory){
       // You can send telegram notification or save to logs
       var_dump($usedMemory);
   });
}
```

Handling Memory Leak Exceptions
-------------------------------

[](#handling-memory-leak-exceptions)

If a memory leak is detected and you have set $throwError to true, a MemoryReachLimitException will be thrown. You can catch and handle this exception in your code:

```
try {
    // Monitor memory usage
    $monitor->checkMemoryLeak();
} catch (MemoryReachLimitException $e) {
    // Handle the exception here
    echo $e->getMessage();
}
```

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity20

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/d10ed9af730cbc5ff89f62e836da6d702e0178c340f9ce187b32636689f026e8?d=identicon)[mohhamedion](/maintainers/mohhamedion)

---

Top Contributors

[![mohhamedion](https://avatars.githubusercontent.com/u/41584933?v=4)](https://github.com/mohhamedion "mohhamedion (19 commits)")

### Embed Badge

![Health badge](/badges/alasaly-monitor-memory-leak/health.svg)

```
[![Health](https://phpackages.com/badges/alasaly-monitor-memory-leak/health.svg)](https://phpackages.com/packages/alasaly-monitor-memory-leak)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.2k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M94](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M138](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[datadog/php-datadogstatsd

An extremely simple PHP datadogstatsd client

19124.6M15](/packages/datadog-php-datadogstatsd)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
