{"id":15028241,"url":"https://github.com/artnum/snowflake53","last_synced_at":"2026-02-22T19:31:21.498Z","repository":{"id":229880926,"uuid":"777901876","full_name":"artnum/snowflake53","owner":"artnum","description":"Generate 53 and 64 bits Snowflake ID. Uses shared memory for sequences (no need for redis or memcached).","archived":false,"fork":false,"pushed_at":"2025-04-15T13:48:13.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-15T14:44:05.205Z","etag":null,"topics":["id-generation","php82","semaphore","shared-memory","snowflake","snowflake-id","trait","web"],"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/artnum.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":"2024-03-26T18:02:45.000Z","updated_at":"2025-04-15T13:47:54.000Z","dependencies_parsed_at":"2025-04-15T14:35:07.621Z","dependency_job_id":null,"html_url":"https://github.com/artnum/snowflake53","commit_stats":null,"previous_names":["artnum/snowflake53"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/artnum/snowflake53","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artnum%2Fsnowflake53","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artnum%2Fsnowflake53/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artnum%2Fsnowflake53/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artnum%2Fsnowflake53/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/artnum","download_url":"https://codeload.github.com/artnum/snowflake53/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artnum%2Fsnowflake53/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29724351,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-22T19:15:09.475Z","status":"ssl_error","status_checked_at":"2026-02-22T19:15:09.045Z","response_time":110,"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":["id-generation","php82","semaphore","shared-memory","snowflake","snowflake-id","trait","web"],"created_at":"2024-09-24T20:07:53.267Z","updated_at":"2026-02-22T19:31:21.477Z","avatar_url":"https://github.com/artnum.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Snowflake53\n\nA trait to generate 53 bits snowflake id to fit into js Number.MAX_SAFE_INTEGER.\nSequence counting is done with shared memory and machine ID comes from\nenvironment variable or parameters\nIt also possible to generate 64 bits snowflake id.\n\nIt dosen't require any external infrastructure (like Memcached or Redis or ...)\nto keep sequence counting as it is done by shared memory and use semaphore for\nlocking. So other processes can tap into the sequence counting too :)\n\n## Install\n\nVia composer :\n\n```\n$ composer require artnum/snowflake53\n```\n\n## Usage\n\n```php\nrequire_once 'vendor/autoload.php';\n\nuse Snowflake53\\ID;\n\nclass IDGen {\n    use ID;\n}\n\n$gen = new IDGen();\necho $gen-\u003eget53() . PHP_EOL;\necho $gen-\u003eget64() . PHP_EOL;\n\n```\n\nAll functions are declared as static, so it is possible to use without a class\ninstance.\n\n```php\nrequire_once 'vendor/autoload.php';\n\nuse Snowflake53\\ID;\n\nclass IDGen {\n    use ID;\n}\n\necho IDGen::get53() . PHP_EOL;\necho IDGen::get64() . PHP_EOL;\n```\n\nYou can destroy, if you choose to, shared memory semgent and semaphore by calling\n`destroySHM`:\n\n```php\nrequire_once 'vendor/autoload.php';\n\nuse Snowflake53\\ID;\n\nclass IDGen {\n    use ID;\n}\n\nIDGen::destroySHM(); \n```\n\n## Shared memory path\n\nShared memory use a file path as identity. By default it is `__FILE__`.  But if\nyou use this in several different places on your server but still want all ID\nto be in sequence, you can set the public static variable $SHMPath to the path\nyou want. The file __must__ exist.\n\n```php\nrequire_once 'src/Snowflake53.php';\n\nuse Snowflake53\\ID;\n\nclass IDGen {\n    use ID;\n}\n\nIDGen::$SHMPath = '/tmp/snowflake53';\necho IDGen::get53() . PHP_EOL;\necho IDGen::get64() . PHP_EOL;\n\n\n$gen = new IDGen();\n$gen::$SHMPath = '/tmp/snowflake53';\necho $gen-\u003eget53() . PHP_EOL;\necho $gen-\u003eget64() . PHP_EOL;\n```\n\n## Machine ID\n\nMachine ID can be passed as argument of `get53` or `get64`. If not, it will try to\nget the ID from environment variable `SNOWFLAK53_MACHINE_ID`, \n`SNOWFLAKE64_MACHINE_ID` or `SNOWFLAKE_MACHINE_ID`. \nWhen getting a 53 bits ID, `SNOWFLAK53_MACHINE_ID` will be look at and then \n`SNOWFLAKE_MACHINE_ID`, when getting a 64 bits ID it's the opposite (first\n`SNOWFLAKE64_MACHINE_ID` and then `SNOWFLAKE_MACHINE_ID`).\n\nThe idea behind that is you set a unique machine  for 64 and 53 bits and so, you\nuse `SNOWFLAKE_MACHINE_ID` or you have a different machine ID for 53 bits or 64\nbits and so you set `SNOWFLAKE53_MACHINE_ID` and `SNOWFLAKE64_MACHINE_ID`.\n\n## License\n\nUnder [MIT license](https://opensource.org/license/mit).\n\n## Developer\n\n * Etienne Bagnoud \u003cetienne@artnum.ch\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartnum%2Fsnowflake53","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartnum%2Fsnowflake53","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartnum%2Fsnowflake53/lists"}