{"id":29817101,"url":"https://github.com/cybercog/php-db-locker","last_synced_at":"2025-07-28T20:12:14.654Z","repository":{"id":57678292,"uuid":"490362626","full_name":"cybercog/php-db-locker","owner":"cybercog","description":"PHP application-level database locking mechanisms to implement concurrency control patterns.","archived":false,"fork":false,"pushed_at":"2025-07-25T14:20:56.000Z","size":31,"stargazers_count":5,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-25T21:25:00.010Z","etag":null,"topics":["advisory-locks","concurrency","concurrency-control","database","db","lock","locking","locks","mutex","race-condition-prevention","race-conditions"],"latest_commit_sha":null,"homepage":"https://komarev.com/sources","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/cybercog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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}},"created_at":"2022-05-09T16:31:18.000Z","updated_at":"2025-01-06T20:40:46.000Z","dependencies_parsed_at":"2025-07-25T16:12:18.315Z","dependency_job_id":"c57c6153-6f60-4429-8068-845965a15999","html_url":"https://github.com/cybercog/php-db-locker","commit_stats":{"total_commits":19,"total_committers":3,"mean_commits":6.333333333333333,"dds":0.5263157894736843,"last_synced_commit":"9d0ab857185b12d2dd34b55eabfc4e7e7a296e50"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cybercog/php-db-locker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cybercog%2Fphp-db-locker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cybercog%2Fphp-db-locker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cybercog%2Fphp-db-locker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cybercog%2Fphp-db-locker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cybercog","download_url":"https://codeload.github.com/cybercog/php-db-locker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cybercog%2Fphp-db-locker/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267108582,"owners_count":24037510,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-26T02:00:08.937Z","response_time":62,"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":["advisory-locks","concurrency","concurrency-control","database","db","lock","locking","locks","mutex","race-condition-prevention","race-conditions"],"created_at":"2025-07-28T20:12:14.004Z","updated_at":"2025-07-28T20:12:14.647Z","avatar_url":"https://github.com/cybercog.png","language":"PHP","readme":"# PHP DB Locker\n\n![cog-php-db-locker](https://user-images.githubusercontent.com/1849174/167773585-171bef35-8e6d-461c-b1b1-ad9d2b07290a.png)\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/cybercog/php-db-locker/releases\"\u003e\u003cimg src=\"https://img.shields.io/github/release/cybercog/php-db-locker.svg?style=flat-square\" alt=\"Releases\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/cybercog/php-db-locker/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/cybercog/php-db-locker.svg?style=flat-square\" alt=\"License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Introduction\n\n\u003e WARNING! This library is currently under development and may not be stable. Use in your services at your own risk.\n\nPHP application-level database locking mechanisms to implement concurrency control patterns.\n\nSupported drivers:\n\n- Postgres — [PostgreSQL Advisory Locks Documentation](https://www.postgresql.org/docs/current/explicit-locking.html#ADVISORY-LOCKS)\n\n## Installation\n\nPull in the package through [Composer](https://getcomposer.org/).\n\n```shell\ncomposer require cybercog/php-db-locker\n```\n\n## Usage\n\n### Postgres\n\n#### Transaction-level advisory lock\n\n```php\n$dbConnection = new PDO($dsn, $username, $password);\n\n$locker = new \\Cog\\DbLocker\\Postgres\\PostgresAdvisoryLocker();\n$lockId = \\Cog\\DbLocker\\Postgres\\PostgresLockKey::create('user', '4');\n\n$dbConnection-\u003ebeginTransaction();\n$lock = $locker-\u003eacquireSessionLevelLockHandler(\n    $dbConnection,\n    $lockId,\n    \\Cog\\DbLocker\\Postgres\\Enum\\PostgresLockWaitModeEnum::NonBlocking,\n    \\Cog\\DbLocker\\Postgres\\Enum\\PostgresLockAccessModeEnum::Exclusive,\n);\nif ($lock-\u003ewasAcquired) {\n    // Execute logic if lock was successful\n} else {\n    // Execute logic if lock acquisition has been failed\n}\n$dbConnection-\u003ecommit();\n```\n\n#### Session-level advisory lock\n\n```php\n$dbConnection = new PDO($dsn, $username, $password);\n\n$locker = new \\Cog\\DbLocker\\Postgres\\PostgresAdvisoryLocker();\n$lockId = \\Cog\\DbLocker\\Postgres\\PostgresLockKey::create('user', '4');\n\ntry {\n    $lock = $locker-\u003eacquireSessionLevelLockHandler(\n        $dbConnection,\n        $lockId,\n        \\Cog\\DbLocker\\Postgres\\Enum\\PostgresLockWaitModeEnum::NonBlocking,\n        \\Cog\\DbLocker\\Postgres\\Enum\\PostgresLockAccessModeEnum::Exclusive,\n    );\n    if ($lock-\u003ewasAcquired) {\n        // Execute logic if lock was successful\n    } else {\n        // Execute logic if lock acquisition has been failed\n    }\n} finally {\n    $lock-\u003erelease();\n}\n```\n\n## Changelog\n\nDetailed changes for each release are documented in the [CHANGELOG.md](https://github.com/cybercog/php-db-locker/blob/master/CHANGELOG.md).\n\n## License\n\n- `PHP DB Locker` package is open-sourced software licensed under the [MIT license](LICENSE) by [Anton Komarev].\n\n## 🌟 Stargazers over time\n\n[![Stargazers over time](https://chart.yhype.me/github/repository-star/v1/490362626.svg)](https://yhype.me?utm_source=github\u0026utm_medium=cybercog-php-db-locker\u0026utm_content=chart-repository-star-cumulative)\n\n## About CyberCog\n\n[CyberCog] is a Social Unity of enthusiasts. Research the best solutions in product \u0026 software development is our passion.\n\n- [Follow us on Twitter](https://twitter.com/cybercog)\n\n\u003ca href=\"https://cybercog.su\"\u003e\u003cimg src=\"https://cloud.githubusercontent.com/assets/1849174/18418932/e9edb390-7860-11e6-8a43-aa3fad524664.png\" alt=\"CyberCog\"\u003e\u003c/a\u003e\n\n[Anton Komarev]: https://komarev.com\n[CyberCog]: https://cybercog.su\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcybercog%2Fphp-db-locker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcybercog%2Fphp-db-locker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcybercog%2Fphp-db-locker/lists"}