PHPackages                             upscale/stdlib-object-lifecycle - 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. [CLI &amp; Console](/categories/cli)
4. /
5. upscale/stdlib-object-lifecycle

ActiveLibrary[CLI &amp; Console](/categories/cli)

upscale/stdlib-object-lifecycle
===============================

Library to monitor lifecycle of objects allocated by long-running PHP scripts

2.0.3(6y ago)537Apache-2.0PHP

Since Aug 2Pushed 6y ago2 watchersCompare

[ Source](https://github.com/upscalesoftware/stdlib-object-lifecycle)[ Packagist](https://packagist.org/packages/upscale/stdlib-object-lifecycle)[ Docs](https://github.com/upscalesoftware/stdlib-object-lifecycle)[ RSS](/packages/upscale-stdlib-object-lifecycle/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (13)Used By (0)

Object Lifecycle Monitoring
===========================

[](#object-lifecycle-monitoring)

This library tracks existence of objects throughout their lifecycle until eventual destruction. It can accurately detect memory leaks in long-running CLI scripts or event-driven web-servers, such as [Swoole](https://www.swoole.co.uk/) or [ReactPHP](https://reactphp.org/).

The monitoring can be easily activated for applications with centralized object instantiation, i.e. using a DI container.

**Features:**

- Watch any object w/o modifying its source code
- Detect objects that are still alive
- Detect objects that have been destroyed
- Debug info on alive/destroyed objects: class, hash, trace
- Garbage collection of circular references

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

[](#installation)

The library is to be installed via [Composer](https://getcomposer.org/) as a dependency:

```
composer require upscale/stdlib-object-lifecycle
```

Usage
-----

[](#usage)

Detect destruction of objects:

```
$obj1 = new \stdClass();
$obj2 = new \stdClass();
$obj3 = new \stdClass();

// Circular references subject to garbage collection
$obj1->ref = $obj2;
$obj2->ref = $obj1;

$watcher = new \Upscale\Stdlib\Object\Lifecycle\Watcher();
$watcher->watch($obj1);
$watcher->watch([$obj2, $obj3]);

unset($obj1);

// Outputs 3 because of circular references
echo count($watcher->detectAliveObjects());

unset($obj2);

// Outputs 3 because of pending garbage collection
echo count($watcher->detectAliveObjects(false));

// Outputs 1 after forced garbage collection
echo count($watcher->detectAliveObjects());

unset($obj3);

// Outputs 0 and 3 respectively
echo count($watcher->detectAliveObjects());
echo count($watcher->detectGoneObjects());
```

Methods `detectAliveObjects()` and `detectGoneObjects()` return the following debug information:

```
array(
  array(
    'type' => 'stdClass',
    'hash' => '00000000524c32e1000000002cee0034',
    'trace' => '#0 demo.php(26): Upscale\\Stdlib\\Object\\Lifecycle\\Watcher->watch(Object(stdClass))
#1 demo.php(10): Example->runTest()
#2 demo.php(53): Example->test()
#3 {main}',
  ),
  ...
)
```

Contributing
------------

[](#contributing)

Pull Requests with fixes and improvements are welcome!

License
-------

[](#license)

Licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity70

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~36 days

Recently: every ~65 days

Total

12

Last Release

2494d ago

Major Versions

1.5.0 → 2.0.02019-01-18

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6521759?v=4)[Upscale Software](/maintainers/upscalesoftware)[@upscalesoftware](https://github.com/upscalesoftware)

---

Top Contributors

[![sshymko](https://avatars.githubusercontent.com/u/1231423?v=4)](https://github.com/sshymko "sshymko (33 commits)")

---

Tags

clihealthdebugreactphpobjectmemoryswoolescriptlife cyclelifecycleramgarbage collectiondestructorleakallocationallocatedestructcircular referencescyclic references

### Embed Badge

![Health badge](/badges/upscale-stdlib-object-lifecycle/health.svg)

```
[![Health](https://phpackages.com/badges/upscale-stdlib-object-lifecycle/health.svg)](https://phpackages.com/packages/upscale-stdlib-object-lifecycle)
```

###  Alternatives

[symfony/console

Eases the creation of beautiful and testable command line interfaces

9.8k1.1B13.3k](/packages/symfony-console)[nunomaduro/collision

Cli error handling for console/command-line PHP applications.

4.7k348.7M10.5k](/packages/nunomaduro-collision)[nunomaduro/termwind

It's like Tailwind CSS, but for the console.

2.5k260.6M361](/packages/nunomaduro-termwind)[wp-cli/wp-cli

WP-CLI framework

5.1k18.5M387](/packages/wp-cli-wp-cli)[clue/stdio-react

Async, event-driven console input &amp; output (STDIN, STDOUT) for truly interactive CLI applications, built on top of ReactPHP

20010.7M27](/packages/clue-stdio-react)[wp-cli/php-cli-tools

Console utilities for PHP

68327.0M374](/packages/wp-cli-php-cli-tools)

PHPackages © 2026

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