{"id":20540554,"url":"https://github.com/utopia-php/pools","last_synced_at":"2026-06-03T07:01:13.861Z","repository":{"id":61257498,"uuid":"547873446","full_name":"utopia-php/pools","owner":"utopia-php","description":"Lite \u0026 fast micro PHP pools library that is **easy to use**.","archived":false,"fork":false,"pushed_at":"2026-02-26T08:59:07.000Z","size":257,"stargazers_count":8,"open_issues_count":2,"forks_count":3,"subscribers_count":6,"default_branch":"main","last_synced_at":"2026-02-26T15:40:36.277Z","etag":null,"topics":["hacktoberfest","php","pools","utopia"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/utopia-php.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-10-08T13:17:37.000Z","updated_at":"2026-02-26T08:42:45.000Z","dependencies_parsed_at":"2024-04-19T11:29:33.644Z","dependency_job_id":"db515694-921d-4ee8-aecd-1df6aab25c95","html_url":"https://github.com/utopia-php/pools","commit_stats":{"total_commits":52,"total_committers":3,"mean_commits":"17.333333333333332","dds":"0.32692307692307687","last_synced_commit":"d2870ab74b31b7f4027799f082e85122154f8bed"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/utopia-php/pools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fpools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fpools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fpools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fpools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/utopia-php","download_url":"https://codeload.github.com/utopia-php/pools/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fpools/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33852295,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-03T02:00:06.370Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","php","pools","utopia"],"created_at":"2024-11-16T01:16:12.486Z","updated_at":"2026-06-03T07:01:13.832Z","avatar_url":"https://github.com/utopia-php.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Utopia Pools\n\n[![Build Status](https://travis-ci.com/utopia-php/pools.svg?branch=main)](https://travis-ci.com/utopia-php/pools)\n![Total Downloads](https://img.shields.io/packagist/dt/utopia-php/pools.svg)\n[![Discord](https://img.shields.io/discord/564160730845151244?label=discord)](https://appwrite.io/discord)\n\nUtopia 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](https://appwrite.io).\n\nAlthough this library is part of the [Utopia Framework](https://github.com/utopia-php/framework) project it is dependency free, and can be used as standalone with any other PHP project or framework.\n\n## Concepts\n\n* **Pool** - A list of long living connections. You can pop connections out and use them and push them back to the pool for reuse.\n* **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.\n* **Group** - A group of multiple pools.\n\n## Getting Started\n\nInstall using composer:\n```bash\ncomposer require utopia-php/pools\n```\n## Examples\n\n```php\nuse PDO;\nuse Utopia\\Pools\\Pool;\nuse Utopia\\Pools\\Group;\n\n$pool = new Pool('mysql-pool', 1 /* number of connections */, function() {\n    $host = '127.0.0.1';\n    $db   = 'test';\n    $user = 'root';\n    $pass = '';\n    $charset = 'utf8mb4';\n\n    try {\n        $pdo = new PDO(\"mysql:host=$host;dbname=$db;charset=$charset\", $user, $pass);\n    } catch (\\PDOException $e) {\n        throw new \\PDOException($e-\u003egetMessage(), (int)$e-\u003egetCode());\n    }\n\n    return $pdo;\n});\n\n$pool-\u003esetReconnectAttempts(3); // number of attempts to reconnect\n$pool-\u003esetReconnectSleep(5); // seconds to sleep between reconnect attempts\n\n$pool-\u003esetRetryAttempts(3); // number of attempts to get connection\n$pool-\u003esetRetrySleep(5); // seconds to sleep between failed pop-connection attempts\n\n$connection = $pool-\u003epop(); // Get a connection from the pool\n$connection-\u003egetID(); // Get the connection ID\n$connection-\u003egetResource(); // Get the connection resource\n\n$pool-\u003epush($connection); // Return the connection to the pool\n\n$pool-\u003ereclaim(); // Recalim the pool, return all active connections automatically\n\n$pool-\u003ecount(); // Get the number of available connections\n\n$pool-\u003eisEmpty(); // Check if the pool is empty\n\n$pool-\u003eisFull(); // Check if the pool is full\n\n$group = new Group(); // Create a group of pools\n$group-\u003eadd($pool); // Add a pool to the group\n$group-\u003eget('mysql-pool'); // Get a pool from the group\n$group-\u003esetReconnectAttempts(3); // Set the number of reconnect attempts for all pools\n$group-\u003esetReconnectSleep(5); // Set the sleep time between reconnect attempts for all pools\n```\n\n## Reconnect and Retry\n\nBoth reconnect and retry logic is used in `pop()` method to handle problematic scenarios. Both allow you to configure 2 properties:\n\n- `attempts` - How many times library will retry when problem occurs\n- `sleep` - How long will library wait for before next retry attempt\n\n**Reconnect** settings are used when your connection initialization callback throws an exception. This can occur for example, when a handshake with SQL server fails.\n\n**Retry** settings are used when pool of connection is empty and there is no more connections to pop. This can occur for example, when your server supports more concurrent actions than your pool.\n\n## System Requirements\n\nUtopia Framework requires PHP 8.0 or later. We recommend using the latest PHP version whenever possible.\n\n## Tests\n\nTo run all unit tests, use the following Docker command:\n\n```bash\ndocker compose exec tests vendor/bin/phpunit --configuration phpunit.xml tests\n```\n\nTo run static code analysis, use the following Psalm command:\n\n```bash\ndocker compose exec tests vendor/bin/psalm --show-info=true\n```\n\n## Copyright and license\n\nThe MIT License (MIT) [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Futopia-php%2Fpools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Futopia-php%2Fpools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Futopia-php%2Fpools/lists"}