I originally thought this would be quite simple but it now appears far from trivial. Perhaps I am missing something. I want a way to create a sequence of 32-bit tokens that does not repeat and must be guaranteed unique across different sessions.
PHP/MySQL Experts : How to Generate a Unique Sequence of Numbers?
36
I originally thought this would be quite simple but it now appears far from trivial. Perhaps I am missing something.
I want a way to create a sequence of 32-bit tokens that does not repeat and must be guaranteed unique across different sessions.
Preferably pseudo-random but sequential would be OK too.
Although MySQL does not support sequences one possible way is to create a table with an auto_increment column and for a new token insert NULL and then read back last_insert_id, but I would prefer to avoid an extra database write per session.
Any other ideas?
The tokens must be 32-bits long and the method work consistently on 32/64-bit servers without requiring any extensions or privileges beyond a typical default hosting account.
I'm beginning to think the above method may be the only way and would be interested in the thoughts of some more experienced PHP/MySQL developers.
Cheers,
Phil
I want a way to create a sequence of 32-bit tokens that does not repeat and must be guaranteed unique across different sessions.
Preferably pseudo-random but sequential would be OK too.
Although MySQL does not support sequences one possible way is to create a table with an auto_increment column and for a new token insert NULL and then read back last_insert_id, but I would prefer to avoid an extra database write per session.
Any other ideas?
The tokens must be 32-bits long and the method work consistently on 32/64-bit servers without requiring any extensions or privileges beyond a typical default hosting account.
I'm beginning to think the above method may be the only way and would be interested in the thoughts of some more experienced PHP/MySQL developers.
Cheers,
Phil
- jaimegm
- [1] reply
- xiaophil
- jaimegm
- [ 1 ] Thanks
- [1] reply
- xiaophil
- [1] reply
- MemberWing
- [ 1 ] Thanks
- KirkMcD
- [ 1 ] Thanks
- [1] reply
- xiaophil
- wayfarer
- [1] reply
- xiaophil
- bucksuper
- [ 1 ] Thanks
- [1] reply
- xiaophil
- [ 1 ] Thanks
- [1] reply
- Johnny Slater
- [1] reply
- bucksuper
- Johnny Slater
- [1] reply
- Chris Jenkins
Next Topics on Trending Feed
-
36