A package to self-generate 32bit unique integer identifiers that can be used as primary keys in relational databases

1.0.4 2024-01-13 13:40 UTC

This package is auto-updated.

Last update: 2024-04-13 16:51:29 UTC


README

The goal for this package is:

  • To provide unique identifiers.
  • The identifiers will be integer so they can be used as primary keys in relational databases to keep performance.
  • Do not depend on third services to generate the Ids as happens with workers.
  • The generated identifier will be 32 bytes.

The current formula is:

UniqueId = php-object-identifier + random-integer + microtime

To this identifier gets repeated it should coincide the object identifier, the microtime, and a 7 number random integer. That is really very improbable but may happen in very rare ocasion.

Example of use:

<?php

use JordiMorillo\Uid\Uid;

class MyProductId extends Uid {}

$myProductId = new MyProductId();

echo "$myProductId"; //This should cast the identifier as a string of numbers

$myProductIdString = $myProductId->toString();

$anotherProductId = new MyProductId($myProductIdString); //This should be a similar equal as $myProductId