switon/pool

Owner-scoped object pools with guard-based borrow and return for Switon Framework

Maintainers

Package info

github.com/switon-php/pool

Documentation

pkg:composer/switon/pool

Statistics

Installs: 38

Dependents: 4

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-06 13:43 UTC

This package is auto-updated.

Last update: 2026-06-07 03:51:57 UTC


README

Pool CI PHP 8.3+

Switon's resource pool manager for pooling resources by owner and type, guard-based auto-return, and pool lifecycle events.

Highlights

  • Owner-scoped pools: each owner gets its own pool space.
  • Multiple pool types: one owner can keep separate variants such as default and readonly.
  • Scoped borrowing: PoolGuard returns resources automatically when it goes out of scope.
  • Capacity control: pool size, timeout, and busy conditions are handled explicitly.
  • Observable lifecycle: resource acquiring, returning, and busy states can be observed.

Installation

composer require switon/pool

Quick Start

use Switon\Core\Attribute\Autowired;
use Switon\Pooling\PoolManagerInterface;

final class DatabaseClient
{
    public function query(string $sql): array
    {
        return [];
    }
}

final class ReportService
{
    #[Autowired] protected PoolManagerInterface $poolManager;

    public function __construct()
    {
        $this->poolManager->add($this, new DatabaseClient(), 4);
    }

    public function load(): array
    {
        $db = $this->poolManager->guard($this, timeout: 1.0);

        return $db->query('SELECT * FROM reports');
    }
}

Docs: https://docs.switon.dev/latest/pool

License

MIT.