PHPackages                             scrutinizer/resource-manager - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. scrutinizer/resource-manager

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

scrutinizer/resource-manager
============================

Provides automatic, robust resource management with an easy-to-use interface

01.2kPHP

Since Mar 4Pushed 4y ago1 watchersCompare

[ Source](https://github.com/scrutinizer-ci/resource-manager)[ Packagist](https://packagist.org/packages/scrutinizer/resource-manager)[ RSS](/packages/scrutinizer-resource-manager/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Robust, Automatic Resource Management
=====================================

[](#robust-automatic-resource-management)

This library helps you manage resources with an easy-to-use interface. Resources like temporary file, or directories are automatically clean-up when leaving the scope, background processes are stopped, and any other custom resources are destroyed.

Usage
-----

[](#usage)

```
use Scrutinizer\ResourceManager\ScopedResourceManager;

class SomeClass {
    private $rm;

    public function __construct(ResourceManager $rm)
    {
        $this->rm = new FilesystemResourceManager($rm);
    }

    public function run()
    {
        $rs = $this->rm->managed(function() {
            $someTmpFile = $this->rm->createTemporaryFile();

            // do something with $someTmpFile

            return $result;
        });

        // $someTmpFile has been automatically cleaned-up here.
    }
}

$someClass = new SomeClass(new ScopedResourceManager());
$someClass->run();
```

Resource Manager Implementations
--------------------------------

[](#resource-manager-implementations)

By default, you would want to use the `ScopedResourceManager` which allows arbitrary nesting of scopes. This manager can also be wrapped by other implementations which provide some convenience methods like f.e. the `FilesystemResourceManager` which allows you to easily create managed temporary files, or directories.

Background Processes
--------------------

[](#background-processes)

If you start a background process, like a server f.e., that you want to clean-up when leaving the scope, you can use the resource manager's `manage` method:

```
use Scrutinizer\ResourceManager\ScopedResourceManager;
use Symfony\Component\Process\Process;

class SomeTest extends \PHPUnit_Framework_TestCase
{
    private $rm;

    public function testSomething()
    {
        // The resource manager's global scope will automatically be cleaned up
        // when PHP calls all object destructors.
    }

    protected function setUp()
    {
        $this->rm = new ScopedResourceManager();

        $proc = new Process('some-server-cmd');
        $proc->start();
        $this->rm->manage($proc);
    }
}
```

Custom Resources
----------------

[](#custom-resources)

By default, this library supports temporary files, temporary directories, and Symfony background processes (using its Process component). You can also add create your own resources by implementing `Scrutinizer\ResourceManager\Resource`:

```
use Scrutinizer\ResourceManager\Resource;
use Scrutinizer\ResourceManager\ScopedResourceManager;

class PhpFileResource implements Resource
{
    private $handle;

    public function __construct($fileHandle)
    {
        $this->handle = $fileHandle;
    }

    public function destroy()
    {
        fclose($this->handle);
    }
}

$rm = new ScopedResourceManager();
$rm->manage(new PhpFileResource($someHandle));
```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity26

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/9da34818b48c46c2690876202264d1e45cb9893c368facb55f8851e47495ecfb?d=identicon)[johannes](/maintainers/johannes)

---

Top Contributors

[![schmittjoh](https://avatars.githubusercontent.com/u/197017?v=4)](https://github.com/schmittjoh "schmittjoh (10 commits)")

### Embed Badge

![Health badge](/badges/scrutinizer-resource-manager/health.svg)

```
[![Health](https://phpackages.com/badges/scrutinizer-resource-manager/health.svg)](https://phpackages.com/packages/scrutinizer-resource-manager)
```

###  Alternatives

[tatter/menus

Dynamic menus for CodeIgniter 4

1713.8k1](/packages/tatter-menus)[llm/mcp-server

PHP SDK for building MCP servers

431.1k](/packages/llm-mcp-server)[asorasoft/chhankitek

Convert from AD (Anno Domini) to Lunar (Chhankitek) format.

104.2k](/packages/asorasoft-chhankitek)[mohammedmanssour/super-simple-dto

Creating data transfer objects with the power of php objects

122.8k1](/packages/mohammedmanssour-super-simple-dto)

PHPackages © 2026

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