{"id":19326015,"url":"https://github.com/linkorb/xuid","last_synced_at":"2026-03-17T20:12:24.942Z","repository":{"id":42953169,"uuid":"47935542","full_name":"linkorb/xuid","owner":"linkorb","description":"XUID library for PHP","archived":false,"fork":false,"pushed_at":"2022-03-26T00:44:12.000Z","size":30,"stargazers_count":4,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-28T14:41:15.170Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linkorb.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":"2015-12-13T20:41:25.000Z","updated_at":"2021-02-18T12:39:51.000Z","dependencies_parsed_at":"2022-09-11T06:04:37.929Z","dependency_job_id":null,"html_url":"https://github.com/linkorb/xuid","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/linkorb/xuid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkorb%2Fxuid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkorb%2Fxuid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkorb%2Fxuid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkorb%2Fxuid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linkorb","download_url":"https://codeload.github.com/linkorb/xuid/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkorb%2Fxuid/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30630269,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T17:32:55.572Z","status":"ssl_error","status_checked_at":"2026-03-17T17:32:38.732Z","response_time":56,"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-10T02:12:12.573Z","updated_at":"2026-03-17T20:12:24.927Z","avatar_url":"https://github.com/linkorb.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"XUID Library\n============\n\nXUIDs are URL-friendly compressed UUIDs [www.xuid.org](http://www.xuid.org)\n\n## Why XUIDs?\n\nA UUID v4 is a great choice as a primary key for your database tables.\n\nBut, they are quite long to use in URLs and databases : 32 alphanumeric characters and four hyphens (36 characters total)\n\nA XUID is a UUID, converted into a 128-bit value, converted into a base64 string (stripped from padding characters), then converted into url-safe base64 (replacing `+` and `/` into `-` and `_` respectively - custom mappings available, see below for more info).\n\nThis gives you a 22 character string, safe to use in URLs.\n\nIt also safely decodes into a full UUID string again.\n\n## Benefits\n\n* Takes less space in database fields\n* Shorter URLs\n* Un-guessable primary keys in URLs\n\n## Usage\n\n```php\nuse Xuid\\Xuid;\n\n$xuid = new Xuid();\n\n$in = $xuid-\u003egetUuid(); // ffe25f31-907e-46c0-b2f8-8bbfedb9082b\n\n$tmp = $xuid-\u003eencode($in); // _-JfMZB-RsCy-Iu_7bkIKw\n\n$out = $xuid-\u003edecode($tmp); // ffe25f31-907e-46c0-b2f8-8bbfedb9082b\n\n$tmp = $xuid-\u003egetXuid();\n\n$newXuid = $xuid-\u003egetXuid();\nif (!$xuid-\u003eisValidXuid($newXuid)) {\n    // this Xuid is valid\n}\n```\n\nAll methods can be called statically as well:\n\n```php\nuse Xuid\\Xuid;\n\n$x = Xuid::getXuid();\n$u = Xuid::decode($x);\n```\n\n## Example\n\nYou'll find example code in the `example/` directory.\n\nTo generate 100 XUIDs, run the following command:\n\n```\nphp example/generate.php\n```\n\nExample output:\n```\ny9G-jWmYQcW5HyxiU_Pnew: cbd1be8d-6998-41c5-b91f-2c6253f3e77b\nIOnEowPFR-G74hEBtTSJVQ: 20e9c4a3-03c5-47e1-bbe2-1101b5348955\nJgn4-Hs3STyNMC_ectX4kA: 2609f8f8-7b37-493c-8d30-2fde72d5f890\n-rO6xKQFQCGPozxJf35lGw: fab3bac4-a405-4021-8fa3-3c497f7e651b\nc6l3fR3mThSlL1OlNYgCvg: 73a9777d-1de6-4e14-a52f-53a5358802be\n3PK9eo00T92z6oSsFNCY-A: dcf2bd7a-8d34-4fdd-b3ea-84ac14d098f8\nvCMyGdkGT-m6e6m4BKcfgA: bc233219-d906-4fe9-ba7b-a9b804a71f80\nJJ_1Ndd3S9SwG9urLr5NTQ: 249ff535-d777-4bd4-b01b-dbab2ebe4d4d\nKSn-sn-cToydyfvjLZHhBA: 2929feb2-7f9c-4e8c-9dc9-fbe32d91e104\nfi_nfoXrQ_GoYrzT4oZqRw: 7e2fe77e-85eb-43f1-a862-bcd3e2866a47\n1vKKRSlHQICMj5X5iktHZA: d6f28a45-2947-4080-8c8f-95f98a4b4764\nyWJ5VPsISbS46anoEO2HVQ: c9627954-fb08-49b4-b8e9-a9e810ed8755\n...etc\n```\n\n## Generatic alpha-numeric XUIDs only\n\n`-` and `_` are occassionally found in XUIDs. If you prefer alpha-numeric only XUIDs, simply call the following static method before generating your XUIDs:\n\n```php\nXuid\\Xuid::alphaNumericOnly();\n```\n\nThis will keep generating XUIDs until one is found that only contains alphanumeric characters.\nThat means that it could require two or more attempts before a valid XUID can be returned. In practice this does not add any noticable latency. But this is worth keeping in mind when generating XUIDs in bulk.\n\n## Custom character mappings\n\nThe default character mapping for XUIDs (url safe) is:\n\n* `+` =\u003e `-`\n* `/` =\u003e `_`\n\nBut you can apply any other mapping you want for any of the characters used in base64 encoding, by calling `Xuid::map()`. For example, you can create double-click safe XUIDs (the whole XUID is selectable simply by double clicking it), by mapping `+` and `_` to selectable characters. For example:\n\n```php\nXuid::setMap(\n    [\n        '+' =\u003e 'Æ',\n        '/' =\u003e 'Ä',\n    ]\n);\n\necho Xuid::getXuid() . PHP_EOL; // Outputs a XUID such as `xQamÆ0kGSjepUAD1bÄ09kg`\n```\n\nBeware to only pass in URL safe characters if your use-case requires URL safe XUIDs.\n\n## PHPUnit tests\n\n```\nvendor/bin/phpunit test/\n```\n\n\n## Brought to you by the LinkORB Engineering team\n\n\u003cimg src=\"http://www.linkorb.com/d/meta/tier1/images/linkorbengineering-logo.png\" width=\"200px\" /\u003e\u003cbr /\u003e\nCheck out our other projects at [engineering.linkorb.com](http://engineering.linkorb.com).\n\nBtw, we're hiring!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkorb%2Fxuid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinkorb%2Fxuid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkorb%2Fxuid/lists"}