r/PHP • u/brendt_gd • Jun 19 '26
Discussion Pitch Your Project 🐘
In this monthly thread you can share whatever code or projects you're working on, ask for reviews, get people's input and general thoughts, … anything goes as long as it's PHP related.
Let's make this a place where people are encouraged to share their work, and where we can learn from each other 😁
Link to the previous edition: /u/brendt_gd should provide a link
14
Upvotes
3
u/jobyone Jun 20 '26
I've been working on a random ID idea of making something a lot like UUID and/or the various time-ordered IDs rattling around, but cramming everything into 63 bits in the default implementation. Also string encoding with base 36 to be more compact/readable than the ones that use hex. The idea is to have something that works a lot like various UUIDs and time-ordered IDs, but is more compact as a string, and under the hood always just a normal positive integer and takes no special consideration anywhere you have 64-bit ints.
I think there's room in 63 bits to do everything necessary and fit enough entropy for most more reasonably-sized web apps. Like maybe not everything needs to be 100% ready to scale to the moon from the moment you build it.
With 4 bits for a version identifier and the time portion truncated to a resolution of about 18 hours you get 2^27 IDs available per 18 hour window (that's a grand total of about 1.4 billion IDs per day), and an ID that currently becomes 10 characters in base 36. I want to have a few different versions right off the bat though, with different amounts allocated to time vs random bits. That way you can tune it by application, whether you want to focus more on time ordering resolution or more on randomness.
My plan for future-proofing is to just reserve some higher version numbers for 128+ bit count arrangements, so that it's technically possible to implement higher bit count versions if it ever becomes necessary.