internal / destroy
Fund package maintenance!
Patreon
Installs: 3 582
Dependents: 3
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 1
Requires
- php: >=8.1
Requires (Dev)
- buggregator/trap: ^1.10
- phpunit/phpunit: ^10.5
- spiral/code-style: ^2.2.2
- ta-tikoma/phpunit-architecture-test: ^0.8.4
- vimeo/psalm: ^6.10
Suggests
- ext-simplexml: to support XML configs parsing
This package is auto-updated.
Last update: 2025-09-08 19:08:48 UTC
README
Destruction as a Service
The package provides explicit resource management for PHP applications through the Destroyable
interface.
It solves memory leaks in long-running applications by enabling deterministic cleanup of resources and breaking circular reference chains that prevent garbage collection.
Why Not Just __destruct()
?
PHP's __destruct()
method has critical limitations with circular references.
While simple two-object cycles (A → B → A) can sometimes be resolved by gc_collect_cycles()
,
more complex scenarios with three or more interconnected objects often fail to trigger destructors at all.
Additionally, gc_collect_cycles()
has significant performance overhead,
making frequent calls impractical in high-performance applications.
// Simple cycle - might be collected eventually $a->ref = $b; $b->ref = $a; // Complex cycle - often never collected $a->ref = $b; $b->ref = $c; $c->ref = $a;
The Destroyable
interface provides explicit control over cleanup,
ensuring resources are freed deterministically without relying on garbage collection cycles or performance-impacting manual collection calls.
Perfect for daemon processes, event-driven applications, and any scenario where deterministic resource cleanup is critical.
Installation
composer require internal/destroy