{"id":26227853,"url":"https://github.com/takuya/php-sysv-ipc-semaphore","last_synced_at":"2025-04-19T16:19:24.690Z","repository":{"id":280857093,"uuid":"943419136","full_name":"takuya/php-sysv-ipc-semaphore","owner":"takuya","description":"php sysv semaphore wrapper","archived":false,"fork":false,"pushed_at":"2025-04-19T01:57:11.000Z","size":38,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-19T10:56:34.471Z","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":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/takuya.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":"2025-03-05T17:16:44.000Z","updated_at":"2025-04-19T01:57:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"6253197d-03ab-4dc3-857d-fa5e584627dd","html_url":"https://github.com/takuya/php-sysv-ipc-semaphore","commit_stats":null,"previous_names":["takuya/php-sysv-ipc-semaphore"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takuya%2Fphp-sysv-ipc-semaphore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takuya%2Fphp-sysv-ipc-semaphore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takuya%2Fphp-sysv-ipc-semaphore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takuya%2Fphp-sysv-ipc-semaphore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/takuya","download_url":"https://codeload.github.com/takuya/php-sysv-ipc-semaphore/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249731218,"owners_count":21317341,"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","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":"2025-03-12T20:20:04.410Z","updated_at":"2025-04-19T16:19:24.678Z","avatar_url":"https://github.com/takuya.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# php-sysv-ipc-semaphore\n\nThis package is wrapper for php sysv sem_xxx. And with `string $name`\n\n## Installing\n\nfrom Packagist\n\n```shell\ncomposer require takuya/php-sysv-ipc-semaphore\n```\n\nfrom GitHub\n\n```shell\nname='php-sysv-ipc-semaphore'\ncomposer config repositories.$name \\\nvcs https://github.com/takuya/$name  \ncomposer require takuya/$name:master\ncomposer install\n```\n\n## Examples\n\n```php\n\u003c?php\n$uniq_name = 'semphore_name';\n$semaphore = new IPCSemaphore($uniq_name);\n$semaphore-\u003eacquire();// first acquire must be success.\n$semaphore-\u003eacquire(true);// multiple acquired result true\n$semaphore-\u003erelease();\n//\n// remove from IPC\n//\n$semaphore-\u003edestroy();\n```\n\n## More easy way to use semaphore\nUsing semaphore with callback\n```php\n\u003c?php\n$semaphore = new IPCSemaphore('semphore_name');\n$ret = $semaphore-\u003ewithLock(function(){\n   // do something in lock\n   echo \"run in lock\";\n   return 1234;\n});\n$ret === 1234; //=\u003e true\n```\nUsing easy locking ( release() by destructor ).\n```php\n\u003c?php\nfunction RunWithLock(){\n  $semaphore = new IPCSemaphore('sem_name');\n  // $lock is local scope.\n  // auto released by destructor on garbage collection.\n  $lock = $semaphore-\u003elock();\n  return 1234;\n}\n/// \nRunWithLock();\n```\nUsing semaphore with try-finally\n```php\n\u003c?php\nfunction sample($msg){\n  try {\n    $sem = new IPCSemaphore(str_rand(10));\n    $sem-\u003eacquire(); \n    return $msg; // finally called before return.\n  } finally {\n    $sem-\u003erelease();\n  }\n}\n```\n\n### semaphore and thread-mutex\n\nCompare to Thread and SyncMutex , SysV semaphore has one big advantage in PHP.\n\nSysV function (ex `sem_get`) is bundled with PHP, no required PECL.\n\nBut, `sem_get()` does not accept string named. This package utilize pseudo string $name.  \n\n### remove ipc by manually\n\nIf unused ipc remains. use SHELL command to remove.\n\n```shell\nipcs -s | grep $USER | grep -oE '0x[a-f0-9]+' | xargs -I@ ipcrm --semaphore-key @\n```\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakuya%2Fphp-sysv-ipc-semaphore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftakuya%2Fphp-sysv-ipc-semaphore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakuya%2Fphp-sysv-ipc-semaphore/lists"}