{"id":36976642,"url":"https://github.com/phlib/mutex","last_synced_at":"2026-02-06T14:24:43.824Z","repository":{"id":45994182,"uuid":"21739167","full_name":"phlib/mutex","owner":"phlib","description":"PHP mutex handling in different ways","archived":false,"fork":false,"pushed_at":"2025-02-11T13:51:53.000Z","size":68,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-13T22:44:35.798Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phlib.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2014-07-11T14:30:59.000Z","updated_at":"2025-02-11T13:51:56.000Z","dependencies_parsed_at":"2025-01-29T15:34:54.588Z","dependency_job_id":null,"html_url":"https://github.com/phlib/mutex","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/phlib/mutex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phlib%2Fmutex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phlib%2Fmutex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phlib%2Fmutex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phlib%2Fmutex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phlib","download_url":"https://codeload.github.com/phlib/mutex/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phlib%2Fmutex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29164852,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T12:44:37.655Z","status":"ssl_error","status_checked_at":"2026-02-06T12:44:13.991Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2026-01-13T22:44:34.325Z","updated_at":"2026-02-06T14:24:43.801Z","avatar_url":"https://github.com/phlib.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phlib/mutex\n\n[![Code Checks](https://img.shields.io/github/actions/workflow/status/phlib/mutex/code-checks.yml?logo=github)](https://github.com/phlib/mutex/actions/workflows/code-checks.yml)\n[![Codecov](https://img.shields.io/codecov/c/github/phlib/mutex.svg?logo=codecov)](https://codecov.io/gh/phlib/mutex)\n[![Latest Stable Version](https://img.shields.io/packagist/v/phlib/mutex.svg?logo=packagist)](https://packagist.org/packages/phlib/mutex)\n[![Total Downloads](https://img.shields.io/packagist/dt/phlib/mutex.svg?logo=packagist)](https://packagist.org/packages/phlib/mutex)\n![Licence](https://img.shields.io/github/license/phlib/mutex.svg)\n\nPHP mutex handling in different ways\n\n## Install\n\nVia Composer\n\n``` bash\n$ composer require phlib/mutex\n```\n\n## Usage\n\n### MySQL\n\n```php\n$adapter = new \\Phlib\\Db\\Adapter([\n    'host' =\u003e '127.0.0.1',\n    'username' =\u003e 'my-user',\n    'password' =\u003e 'my-pass'\n]); \n$mutex = new \\Phlib\\Mutex\\MySQL('my-lock', $adapter);\nif ($mutex-\u003elock()) {\n    // Do some data manipulation while locked\n    $mutex-\u003eunlock();\n}\n```\n\n### Helpers\n\n**Get-Or-Create** provides a simple way to attempt retrieval of a value,\nor create it using a mutex if it doesn't already exist\n\n```php\n$getClosure = function() {\n    // attempt to get a value, eg. from DB, cache, etc.\n    if (!$value) {\n        throw new \\Phlib\\Mutex\\NotFoundException();\n    }\n    return $value;\n};\n\n$createClosure = function() {\n    // attempt to create a value and write eg. to DB, cache, etc.\n    return $value;\n};\n\n$value = \\Phlib\\Mutex\\Helper::getOrCreate($mutex, $getClosure, $createClosure);\n```\n\n## License\n\nThis package is free software: you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU Lesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public License\nalong with this program.  If not, see \u003chttp://www.gnu.org/licenses/\u003e.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphlib%2Fmutex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphlib%2Fmutex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphlib%2Fmutex/lists"}