{"id":19621580,"url":"https://github.com/pkg6/php-lock","last_synced_at":"2026-03-07T14:31:27.846Z","repository":{"id":65376106,"uuid":"591156165","full_name":"pkg6/php-lock","owner":"pkg6","description":"基于php对常见的分布式锁方案封装","archived":false,"fork":false,"pushed_at":"2025-05-20T07:02:32.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-09T12:53:57.528Z","etag":null,"topics":[],"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/pkg6.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":"2023-01-20T03:23:13.000Z","updated_at":"2025-05-20T07:02:35.000Z","dependencies_parsed_at":"2025-07-09T12:44:54.269Z","dependency_job_id":null,"html_url":"https://github.com/pkg6/php-lock","commit_stats":null,"previous_names":["pkg6/php-lock"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pkg6/php-lock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg6%2Fphp-lock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg6%2Fphp-lock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg6%2Fphp-lock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg6%2Fphp-lock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pkg6","download_url":"https://codeload.github.com/pkg6/php-lock/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg6%2Fphp-lock/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30217428,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T14:02:48.375Z","status":"ssl_error","status_checked_at":"2026-03-07T14:02:43.192Z","response_time":53,"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":"2024-11-11T11:23:37.293Z","updated_at":"2026-03-07T14:31:27.813Z","avatar_url":"https://github.com/pkg6.png","language":"PHP","readme":"## 锁实例化\n\n~~~\n//文件锁\n$lock = new \\Pkg6\\Lock\\FileLock('test');\n$lock =  \\Pkg6\\Lock\\FileLock::getInstance('test');\n\n//redis锁\n$redis = new \\Redis();\n$redis-\u003econnect('127.0.0.1', 6379);\n$lock =new \\Pkg6\\Lock\\RedisLock('test', $redis);\n$lock = \\Pkg6\\Lock\\RedisLock::getInstance('test', $redis);\n\n//memcache锁\n$memcache = new \\Memcache();\n$memcache-\u003econnect('127.0.0.1', 11211, 120);\n$lock =new \\Pkg6\\Lock\\MemcacheLock('test', $memcache);\n$lock = \\Pkg6\\Lock\\MemcacheLock::getInstance('test', $memcache);\n\n//memcached锁\n$memcached = new \\Memcached();\n$memcached-\u003eaddServer('127.0.0.1', 11211);\n$memcached-\u003esetOption(Memcached::OPT_BINARY_PROTOCOL, true);\n$lock = new \\Pkg6\\Lock\\MemcachedLock('test', $memcached);\n$lock = \\Pkg6\\Lock\\MemcachedLock::getInstance('test', $memcached);\n~~~\n\n## 锁基本使用\n\n~~~\n\nif (\\Pkg6\\Lock\\Lock::LOCK_RESULT_SUCCESS === $lock-\u003elock()) {\n   // 加锁后处理的任务\n   $lock-\u003eunlock();\n}\n~~~\n\n## 锁高级使用\n\n~~~\n$result = $lock-\u003elock(\n    function(){\n        // 加锁后处理的任务\n    },\n    function(){\n        // 判断是否其它并发已经处理过任务\n    }\n);\nswitch($result)\n{\n    case \\Pkg6\\Lock\\Lock::LOCK_RESULT_CONCURRENT_COMPLETE:\n        // 其它请求已处理\n        break;\n    case \\Pkg6\\Lock\\Lock::LOCK_RESULT_CONCURRENT_UNTREATED:\n        // 在当前请求处理\n        break;\n    case \\Pkg6\\Lock\\Lock::LOCK_RESULT_FAIL:\n        echo '获取锁失败', PHP_EOL;\n        break;\n}\n~~~\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkg6%2Fphp-lock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpkg6%2Fphp-lock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkg6%2Fphp-lock/lists"}