robinvdvleuten / php-ulid Goto Github PK
View Code? Open in Web Editor NEWA PHP port of alizain/ulid with some minor improvements.
Home Page: https://packagist.org/packages/robinvdvleuten/ulid
License: MIT License
A PHP port of alizain/ulid with some minor improvements.
Home Page: https://packagist.org/packages/robinvdvleuten/ulid
License: MIT License
Hello,
I was try the script, but it's seems ulid's last 80 bits isn't unique. Here is example:
$php rr.php
01F46VF3ZZR6FYNWDYQXFA9NQT
01f46vf3zzr6fynwdyqxfa9nqv
and here is the script:
include 'Ulid/Ulid.php';
use Ulid\Ulid;
$ulid = Ulid::generate();
echo (string) $ulid, "\n"; // 01F46VF3ZZR6FYNWDYQXFA9NQT
// Or if you prefer a lowercased output
$ulid = Ulid::generate(true);
echo (string) $ulid, "\n"; // 01f46vf3zzr6fynwdyqxfa9nqv
Only the last char is different, but in specification last 80 bits need to be unique for example in Postgres ulid:
generate_ulid
01F46WA08EPZTRXY4108T4XAMA
01F46WA08ET4RGV447EKD337ES
01F46WA08EHWXAGBSWQMWHZVHK
01F46WA08EZTD358CC7YGKPRKX
01F46WA08EWRBMMJHCA335794Q
01F46WA08EG7H98DZY789T48VH
01F46WA08EY4X6MQW5986SAP82
01F46WA08EXY9BM9YY284C7GM2
01F46WA08E2W1CTYQ9CX1JW02N
01F46WA08EW8ESAW6QBD65ZK4A
(10 rows)
There is a fromTimestamp(.., true) which returns a lowercased string but an example in uppercase, might be a mistake?
Line 39 in 5389c9a
Can we generate the timestamp from this ulid? Is there a functionality already present in this package?
Good day.
Method decodeTime() return incorrect timestamp.
In method generate(): $now = (int) (microtime(true) * 1000);.
Maybe decodeTime() must return $carry/1000 ?
See ramsey/uuid for a similar implementation.
https://github.com/ulid/spec#monotonicity
By casting to (int)
at https://github.com/robinvdvleuten/php-ulid/blob/master/src/Ulid.php#L69 this is removing the float portion of the return value of microtime(true)
thus checking if the current call happened within the same second (instead of millisecond) of the last request.
This should be changed such that it uses the value: microtime(true) * 1000
for milliseconds.
The $lastGenTime
static property (which is supposed to be used to keep track of whether it's generating a new ULID in the same millisecond) is never updated, so the code path for handling generating a ULID in the same millisecond will never be executed (and there are no tests for this behaviour).
Is there a reason why the minimum version is set to 7.1 in composer.json
? I went through the code and couldn't really find any reason for it not to be 7.0 as minimum, unless I missed something.
I'm asking because we're in the midst of finally migrating a more recent version of PHP, which we're doing in steps, but would love to start using this library from 7.0 already. I can definitely help with the changes if needed. Just curious about the why of the limitation. Thanks!
It's 2019 and, you know, there's no logical reason to support anything before php 7.1
The ulid spec does not state it explicitly, but aren't ulids supposed to be uppercase? Lowercase won't change anything when sorting and it might take less memory and database in some circumstances, but shouldn't the technique be the same over all languages?
Otherwise: Thanks for the library, good job! ๐
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.