{"id":24694458,"url":"https://github.com/roadrunner-php/lock","last_synced_at":"2025-10-09T01:31:05.448Z","repository":{"id":143065219,"uuid":"614289444","full_name":"roadrunner-php/lock","owner":"roadrunner-php","description":"🔌 PHP integration package for the RoadRunner Lock plugin, which allows for easy management of distributed locks in PHP applications. The plugin provides a fast, lightweight, and reliable way to acquire, release, and manage locks in a distributed environment.","archived":false,"fork":false,"pushed_at":"2024-02-10T12:16:30.000Z","size":26,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"1.x","last_synced_at":"2025-09-13T16:55:16.475Z","etag":null,"topics":["locks","mutex","mutex-lock","php","roadrunner"],"latest_commit_sha":null,"homepage":"https://roadrunner.dev/","language":"PHP","has_issues":false,"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/roadrunner-php.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"roadrunner-server"}},"created_at":"2023-03-15T09:37:36.000Z","updated_at":"2025-09-08T15:12:42.000Z","dependencies_parsed_at":"2024-02-10T13:27:35.371Z","dependency_job_id":null,"html_url":"https://github.com/roadrunner-php/lock","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":"roadrunner-php/package-skeleton","purl":"pkg:github/roadrunner-php/lock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roadrunner-php%2Flock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roadrunner-php%2Flock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roadrunner-php%2Flock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roadrunner-php%2Flock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/roadrunner-php","download_url":"https://codeload.github.com/roadrunner-php/lock/tar.gz/refs/heads/1.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roadrunner-php%2Flock/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000725,"owners_count":26082895,"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-10-08T02:00:06.501Z","response_time":56,"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":["locks","mutex","mutex-lock","php","roadrunner"],"created_at":"2025-01-26T23:59:46.690Z","updated_at":"2025-10-09T01:31:05.200Z","avatar_url":"https://github.com/roadrunner-php.png","language":"PHP","funding_links":["https://github.com/sponsors/roadrunner-server"],"categories":[],"sub_categories":[],"readme":"\u003ca href=\"https://roadrunner.dev\" target=\"_blank\"\u003e\n  \u003cpicture\u003e\n    \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://github.com/roadrunner-server/.github/assets/8040338/e6bde856-4ec6-4a52-bd5b-bfe78736c1ff\"\u003e\n    \u003cimg align=\"center\" src=\"https://github.com/roadrunner-server/.github/assets/8040338/040fb694-1dd3-4865-9d29-8e0748c2c8b8\"\u003e\n  \u003c/picture\u003e\n\u003c/a\u003e\n\n# RoadRunner locks\n\n[![PHP Version Require](https://poser.pugx.org/roadrunner-php/lock/require/php)](https://packagist.org/packages/roadrunner-php/lock)\n[![Latest Stable Version](https://poser.pugx.org/roadrunner-php/lock/v/stable)](https://packagist.org/packages/roadrunner-php/lock)\n[![phpunit](https://github.com/roadrunner-php/lock/actions/workflows/phpunit.yml/badge.svg)](https://github.com/roadrunner-php/lock/actions)\n[![psalm](https://github.com/roadrunner-php/lock/actions/workflows/psalm.yml/badge.svg)](https://github.com/roadrunner-php/lock/actions)\n[![Codecov](https://codecov.io/gh/roadrunner-php/lock/branch/1.x/graph/badge.svg)](https://codecov.io/gh/roadrunner-php/lock/)\n[![Total Downloads](https://poser.pugx.org/roadrunner-php/lock/downloads)](https://packagist.org/packages/roadrunner-php/lock)\n\u003ca href=\"https://discord.gg/spiralphp\"\u003e\u003cimg src=\"https://img.shields.io/badge/discord-chat-magenta.svg\"\u003e\u003c/a\u003e\n\nThis package provides a PHP integration package for the RoadRunner Lock plugin, which allows for easy management of\ndistributed locks in PHP applications. The plugin provides a fast, lightweight, and reliable way to acquire, release,\nand manage locks in a distributed environment, making it ideal for use in high-traffic web applications and\nmicroservices.\n\n## Requirements\n\nMake sure that your server is configured with following PHP version and extensions:\n\n- PHP 8.1+\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require roadrunner-php/lock\n```\n\n## Usage\n\n```php\nuse RoadRunner\\Lock\\Lock;\nuse Spiral\\Goridge\\RPC\\RPC;\n\nrequire __DIR__ . '/vendor/autoload.php';\n\n$lock = new Lock(RPC::create('tcp://127.0.0.1:6001'));\n```\n\n### Acquire lock\n\nLocks a resource so that it can be accessed by one process at a time. When a resource is locked, other processes that\nattempt to lock the same resource will be blocked until the lock is released.\n\n```php\n$id = $lock-\u003elock('pdf:create');\n\n// Acquire lock with ttl - 10 seconds\n$id = $lock-\u003elock('pdf:create', ttl: 10);\n// or\n$id = $lock-\u003elock('pdf:create', ttl: new \\DateInterval('PT10S'));\n\n// Acquire lock and wait 5 seconds until lock will be released\n$id = $lock-\u003elock('pdf:create', wait: 5);\n// or\n$id = $lock-\u003elock('pdf:create', wait: new \\DateInterval('PT5S'));\n\n// Acquire lock with id - 14e1b600-9e97-11d8-9f32-f2801f1b9fd1\n$id = $lock-\u003elock('pdf:create', id: '14e1b600-9e97-11d8-9f32-f2801f1b9fd1');\n```\n\n### Acquire read lock\n\nLocks a resource for shared access, allowing multiple processes to access the resource simultaneously. When a resource\nis locked for shared access, other processes that attempt to lock the resource for exclusive access will be blocked\nuntil all shared locks are released.\n\n```php\n$id = $lock-\u003elockRead('pdf:create', ttl: 10);\n// or\n$id = $lock-\u003elockRead('pdf:create', ttl: new \\DateInterval('PT10S'));\n\n// Acquire lock and wait 5 seconds until lock will be released\n$id = $lock-\u003elockRead('pdf:create', wait: 5);\n// or\n$id = $lock-\u003elockRead('pdf:create', wait: new \\DateInterval('PT5S'));\n\n// Acquire lock with id - 14e1b600-9e97-11d8-9f32-f2801f1b9fd1\n$id = $lock-\u003elockRead('pdf:create', id: '14e1b600-9e97-11d8-9f32-f2801f1b9fd1');\n```\n\n### Release lock\n\nReleases an exclusive lock or read lock on a resource that was previously acquired by a call to `lock()`\nor `lockRead()`.\n\n```php\n// Release lock after task is done.\n$lock-\u003erelease('pdf:create', $id);\n\n// Force release lock\n$lock-\u003eforceRelease('pdf:create');\n```\n\n### Check lock\n\nChecks if a resource is currently locked and returns information about the lock.\n\n```php\n$status = $lock-\u003eexists('pdf:create');\nif($status) {\n    // Lock exists\n} else {\n    // Lock not exists\n}\n```\n\n### Update TTL\n\nUpdates the time-to-live (TTL) for the locked resource.\n\n```php\n// Add 10 seconds to lock ttl\n$lock-\u003eupdateTTL('pdf:create', $id, 10);\n// or\n$lock-\u003eupdateTTL('pdf:create', $id, new \\DateInterval('PT10S'));\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Credits\n\n- [butschster](https://github.com/butschster)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froadrunner-php%2Flock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froadrunner-php%2Flock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froadrunner-php%2Flock/lists"}