{"id":20208206,"url":"https://github.com/cubiclesoft/php-ext-sync","last_synced_at":"2025-04-10T12:55:05.796Z","repository":{"id":16740379,"uuid":"19497818","full_name":"cubiclesoft/php-ext-sync","owner":"cubiclesoft","description":"SEE NOTE.  CubicleSoft authored PHP Extension:  Synchronization objects (sync).  MIT license.","archived":false,"fork":false,"pushed_at":"2014-07-23T13:49:13.000Z","size":172,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T11:44:39.270Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","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/cubiclesoft.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}},"created_at":"2014-05-06T14:41:20.000Z","updated_at":"2018-10-05T14:02:06.000Z","dependencies_parsed_at":"2022-07-13T13:51:15.370Z","dependency_job_id":null,"html_url":"https://github.com/cubiclesoft/php-ext-sync","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cubiclesoft%2Fphp-ext-sync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cubiclesoft%2Fphp-ext-sync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cubiclesoft%2Fphp-ext-sync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cubiclesoft%2Fphp-ext-sync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cubiclesoft","download_url":"https://codeload.github.com/cubiclesoft/php-ext-sync/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248221767,"owners_count":21067621,"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":"2024-11-14T05:34:31.623Z","updated_at":"2025-04-10T12:55:05.769Z","avatar_url":"https://github.com/cubiclesoft.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"CubicleSoft PHP Extension:  Synchronization Objects (sync)\n==========================================================\n\nNOTE:  This repository has been moved to PECL.  You can find the PECL package here:\n\nhttp://pecl.php.net/package/sync\n\nThe GIT repo here:\n\nhttp://git.php.net/?p=pecl/system/sync.git;a=summary\n\nThe mirrored repo on GitHub is over here:\n\nhttps://github.com/php/pecl-system-sync\n\nAnd the documentation on the package is over here:\n\nhttp://us.php.net/manual/en/book.sync.php\n\nWhat follows is the original summary/basic documentation.  Please use the above links for the latest releases.\n\nSummary\n-------\n\nThe 'sync' extension introduces synchonization objects into PHP.  Named and unnamed Mutex, Semaphore, Event, and Reader-Writer objects provide OS-level synchronization on both *NIX (POSIX semaphores required) and Windows platforms.  The extension comes with a test suite that integrates cleanly into 'make test'.\n\nThis extension uses the liberal MIT open source license.  And, of course, it sits on GitHub for all of that pull request and issue tracker goodness to easily submit changes and ideas respectively.\n\nDetails\n-------\n\nAn exception may be thrown from the constructors if the target object can't be created for some reason.\n\nAll synchronization objects are attempted to be unlocked cleanly within PHP itself.  The exception is if an object's $autounlock option is initialized to false.  If PHP terminates a script and doesn't unlock the object, it can leave the object in an unpredictable state.\n\nNOTE:  When using \"named\" objects, the initialization must be identical for a given name and have a specific purpose.  Reusing named objects for other purposes is not a good idea and will probably result in breaking both applications.  However, different object types can share the same name (e.g. a Mutex and an Event object can have the same name).\n\n```\nvoid SyncMutex::__construct([string $name = null])\n  Constructs a named or unnamed mutex object.\n\nbool SyncMutex::lock([int $wait = -1])\n  Locks a mutex object.  $wait is in milliseconds.\n\nbool SyncMutex::unlock([bool $all = false])\n  Unlocks a mutex object.\n\n\nvoid SyncSemaphore::__construct([string $name = null, [int $initialval = 1, [bool $autounlock = true]]])\n  Constructs a named or unnamed semaphore object.  Don't set $autounlock to false unless you really know what you are doing.\n\nbool SyncSemaphore::lock([int $wait = -1])\n  Locks a semaphore object.  $wait is in milliseconds.\n\nbool SyncSemaphore::unlock([int \u0026$prevcount])\n  Unlocks a semaphore object.\n\n\nvoid SyncEvent::__construct([string $name = null, [bool $manual = false]])\n  Constructs a named or unnamed event object.\n\nbool SyncEvent::wait([int $wait = -1])\n  Waits for an event object to fire.  $wait is in milliseconds.\n\nbool SyncEvent::fire()\n  Lets a thread through that is waiting.  Lets multiple threads through that are waiting if the event object is 'manual'.\n\nbool SyncEvent::reset()\n  Resets the event object state.  Only use when the event object is 'manual'.\n\n\nvoid SyncReaderWriter::__construct([string $name = null, [bool $autounlock = true]])\n  Constructs a named or unnamed reader-writer object.  Don't set $autounlock to false unless you really know what you are doing.\n\nbool SyncReaderWriter::readlock([int $wait = -1])\n  Read locks a reader-writer object.  $wait is in milliseconds.\n\nbool SyncReaderWriter::writelock([int $wait = -1])\n  Write locks a reader-writer object.  $wait is in milliseconds.\n\nbool SyncReaderWriter::readunlock()\n  Read unlocks a reader-writer object.\n\nbool SyncReaderWriter::writeunlock()\n  Write unlocks a reader-writer object.\n```\n\nUsage Examples\n--------------\n\nExample Mutex usage:\n\n```php\n$mutex = new SyncMutex();\n\n$mutex-\u003elock();\n...\n$mutex-\u003eunlock();\n\n\n$mutex2 = new SyncMutex(\"UniqueName\");\n\nif (!$mutex2-\u003elock(3000))\n{\n\techo \"Unable to lock mutex.\";\n\n\texit();\n}\n\n...\n\n$mutex2-\u003eunlock();\n```\n\nExample Semaphore usage:\n\n```php\n$semaphore = new SyncSemaphore(\"LimitedResource_2clients\", 2);\n\nif (!$semaphore-\u003elock(3000))\n{\n\techo \"Unable to lock semaphore.\";\n\n\texit();\n}\n\n...\n\n$semaphore-\u003eunlock();\n```\n\nExample Event usage:\n\n```php\n// In a web application:\n$event = new SyncEvent(\"GetAppReport\");\n$event-\u003efire();\n\n// In a cron job:\n$event = new SyncEvent(\"GetAppReport\");\n$event-\u003ewait();\n```\n\nExample Reader-Writer usage:\n\n```php\n$readwrite = new SyncReaderWriter(\"FileCacheLock\");\n$readwrite-\u003ereadlock();\n...\n$readwrite-\u003ereadunlock();\n\n$readwrite-\u003ewritelock();\n...\n$readwrite-\u003ewriteunlock();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcubiclesoft%2Fphp-ext-sync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcubiclesoft%2Fphp-ext-sync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcubiclesoft%2Fphp-ext-sync/lists"}