Download the PHP package mediagone/small-uid without Composer

On this page you can find all versions of the php package mediagone/small-uid. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package small-uid

Small UID

⚠️ This project is in experimental phase, the API may may be subject to change.

Latest Version on Packagist Total Downloads

UUIDs are frequently used as database Primary Key in software development. However, they aren't the best choice mainly due to their random sorting and the resulting fragmentation in databases indexes.

Using ULIDs is generally a very good alternative, solving most of UUID flaws.

Small UIDs are also an ideal alternative when you do not need as much uniqueness and want shorter "user-friendly" encoded strings.

Summary:

  1. Installation
  2. Usages
    1. Creation
    2. Short-string representation
    3. Serialization
    4. Retrieving creation DateTime
  3. License

Introduction

Small UIDs are short unique identifiers especially designed to be used as efficient database Primary Key:

Small UID ULID UUID v4
Size 64 bits 128 bits 128 bits
Monotonic sort order Yes ** Yes No
Random bits 20 80 122
Collision odds *** 1,024 / ms * 1.099e+12 / ms * 2.305e+18

* the Uid includes a timestamp, so collisions may occur only during the same millisecond. \ ** monotonic sort order, but random order when generated at the same millisecond. \ *** theorical number of generated Uids before the first expected collision.

They are internally stored as 64-bit integers (44-bit timestamp followed by 20 random bits):

|-----------------------|  |------------|
        Timestamp            Randomness
         44 bits               20 bits

The random number suffix still guarantees a decent amount of uniqueness when many ids are created in the same millisecond (up to 1,048,576 different values) and you may only expect collision if you're generating more than 1024 random ids during the same millisecond.

Sorting

Because of the sequential timestamp, Small UIDs are naturally sorted chronologically. It improves indexing when inserting values in databases, new ids being appended to the end of the table without reshuffling existing data (read more in this article).

However, sort order within the same millisecond is not guaranteed because of the random bits suffix.

Installation

This package requires PHP (64-bit) 7.4+ and GMP extension.

Add it as Composer dependency:

If you're using Doctrine ORM, you'll probably want to install also appropriate custom types:

Usages

Creation

Most useful way to generate an Uid is the random() static factory method, which creates a new random Uid using the current timestamp and a random suffix:

You can also generate an Uid from a 16-chars long hexadecimal string:

You can also generate an Uid from a base62-encoded string using fromString method, but this will detailed in the next section.

In some cases, you may need a null-object Uid, therefore there is a special static factory method:

Short-string representation

Using the hexadecimal representation is not always convenient (eg. for use in URLs), hopefully it can be safely converted back and forth to a base-62 string, which is only 10 or 11-chars long (depending on the Uid's internal value).

To get an uid's short-string representation, just cast it to a string:

To convert back the short-string to an Uid instance, use the fromString() static factory method:

Serialization

You serialize your Uids using their hexadecimal representation (which is always a 16-chars long hexadecimal string):

Uids can also be converted to an 8-bit integer or a binary string (eg. for database persistence):

Retrieving creation DateTime

Every Uid embeds a timestamp reflecting its creation datetime:

License

Small UID is licensed under MIT license. See LICENSE file.


All versions of small-uid with dependencies

PHP Build Version
Package Version
Requires php-64bit Version ^7.4|^8.0
ext-gmp Version *
mediagone/types-common Version ^0.5.1|^0.6|^0.7
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mediagone/small-uid contains the following files

Loading the files please wait ....