Download the PHP package utopia-php/pools without Composer
On this page you can find all versions of the php package utopia-php/pools. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download utopia-php/pools
More information about utopia-php/pools
Files in utopia-php/pools
Package pools
Short Description A simple library to manage connection pools
License MIT
Informations about the package pools
Utopia Pools
[!IMPORTANT] This repository is a read-only mirror of
packages/poolsin appwrite/appwrite. Development happens there — please open issues and pull requests against appwrite/appwrite.
Utopia pools library is simple and lite library for managing long living connection pools. This library is aiming to be as simple and easy to learn and use. This library is maintained by the Appwrite team.
Although this library is part of the Utopia Framework project it is dependency free, and can be used as standalone with any other PHP project or framework.
Concepts
- Pool - A list of long living connections. You can pop connections out and use them and push them back to the pool for reuse.
- Connection - An object that holds a long living database or other external connection in a form of a resource. PDO object or a Redis client are examples of resources that can be used inside a connection.
- Group - A group of multiple pools.
Getting started
Install using Composer:
Examples
Acquiring connections
timeout bounds how long pop() waits for a connection to become available.
The pool creates one when it has spare capacity, otherwise it waits for one to
come back, and it throws once the budget is spent. There is one number for
waiting, and it is the number a caller experiences.
It does not cover time spent inside init. The pool cannot interrupt a blocking
connect, so give init its own connect timeout if you need the total bounded —
for PDO that is PDO::ATTR_TIMEOUT.
If creating a connection fails, that exception propagates untouched, so callers
keep the original type to act on. The pool does not retry and does not fall back
to waiting, because waiting for another caller's connection after your own
create failed is a retry in disguise. Own retries in init:
Compose utopia-php/circuit-breaker
there rather than counting attempts, because a breaker carries state between
calls and an attempt counter cannot.
Upgrading from 1.x
Configuration is constructor-only, and the retry knobs are gone.
timeoutis a required constructor argument, and it is the pool's only timeout. It replacessetRetryAttempts(),setRetrySleep()andsetSynchronizationTimeout(). Pass the total wait you want, in seconds.setReconnectAttempts()andsetReconnectSleep()are removed with no replacement. Wrapinitif you want to retry a failed connect.setTelemetry()is removed. Passtelemetry:to the constructor.Group::setReconnectAttempts(),Group::setReconnectSleep()andGroup::setTelemetry()are removed. Pools arrive configured.Pool::getName()andPool::getSize()are now the$nameand$sizeproperties. ThegetReconnectAttempts(),getReconnectSleep(),getRetryAttempts(),getRetrySleep()andgetSynchronizationTimeout()getters are removed.Connectionisfinal readonly.getID(),getResource()andgetPool()become the$idand$resourceproperties;getPool()has no replacement.setID(),setResource()andsetPool()are removed.Connection::reclaim()andConnection::destroy()returnvoidinstead of the pool.Pool::release()no longer takes a$starttimestamp. The pool measures use time itself.Adapter::pop()takes afloattimeout. Custom adapters need the wider type.initis typedClosurerather thancallable. Pass a closure, or wrap a string or array callable withClosure::fromCallable().
Two behaviour changes worth checking against your own code:
- A failed connect used to be absorbed by an internal retry and can now reach
the caller on the first attempt, as whatever type
initthrew rather than a pool exception. destroy()no longer creates the replacement connection itself. Capacity is freed immediately and the nextpop()creates one, sodestroy()cannot block on a connect or fail for reasons unrelated to the connection you asked it to discard.
System requirements
Utopia pools requires PHP 8.4 or later. We recommend using the latest PHP version whenever possible.
Tests
Run the test suite and static analysis from the monorepo root:
Copyright and license
The MIT License (MIT) http://www.opensource.org/licenses/mit-license.php