Download the PHP package gpslab/base64uid without Composer

On this page you can find all versions of the php package gpslab/base64uid. 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 base64uid

Latest Stable Version Total Downloads Build Status Coverage Status Scrutinizer Code Quality SensioLabs Insight StyleCI License

Base64 UID

Generate UID like YouTube.

Introduction

The library generates a unique identifier consisting of 64 characters and a length of 10 characters (you can change the length of the identifier). This gives us 6410 = 260 = 1 152 921 504 606 846 976 combinations.

To represent this number, imagine that in order to get all possible values of identifiers with a length of 10 characters and generating an ID every microsecond, it takes 36 559 years.

UUID works on the same principle, but its main drawback is that it's too long. It is not convenient to use it as a public identifier, for example in the URL. In order to get the same number of combinations as the UUID, we need 2128 = 6421 lines 21 characters long, that is, almost 2 times shorter than the UUID (37 characters). And if we take an identifier of the same length as the UUID, then we get 6437 = 2222 against 2128 for the UUID.

The most important advantage of this approach is that you ourselves control the number of combinations by changing the length of the string and the character set. This will optimize the length of the identifier for your business requirements.

Collision

The probability of collision of identifiers can be calculated by the formula:

Where

Take an identifier with a length of 11 characters, like YouTube, which will give us N = 6411 = 266 and we will get:

That is, by generating 236 = 68 719 476 736 identifiers you are almost guaranteed to get a collision.

For calculations with large numbers, i recommend this online calculator.

Installation

Pretty simple with Composer, run:

Usage

With length 6 chars (646 = 68 719 476 736 combinations).

The floating-length identifier will give more unique identifiers (648 + 649 + 6410 = 1 171 217 378 093 039 616 combinations).

You can customize charset.

Other algorithms for generate UID

Random char

Generate random characters of a finite UID from a charset.

Limit the length of the UID and the charset.

Random bytes

Generate random bytes and encode it in Base64.

Encoded random bits

Generate bitmap with random bits and encode it in Base64. The bitmap length is 64 bits and it require 64-bit mode of processor architecture.

Encoded bitmap of time

Generate bitmap with current time in microseconds and encode it in Base64. The bitmap length is 64 bits and it require 64-bit mode of processor architecture.

Generated bitmap has a structure:

Responsibly select the number of bits allocated to store the current time. The $time_length defines the limit of the stored date:

Bits limit Maximum available bitmap Unix Timestamp Date
40-bits 1111111111111111111111111111111111111111 1099511627775 2004-11-03 19:53:48 (UTC)
41-bits 11111111111111111111111111111111111111111 2199023255551 2039-09-07 15:47:36 (UTC)
42-bits 111111111111111111111111111111111111111111 4398046511103 2109-05-15 07:35:11 (UTC)
43-bits 1111111111111111111111111111111111111111111 8796093022207 2248-09-26 15:10:22 (UTC)
44-bits 11111111111111111111111111111111111111111111 17592186044415 2527-06-23 06:20:44 (UTC)
45-bits 111111111111111111111111111111111111111111111 35184372088831 3084-12-12 12:41:29 (UTC)

To reduce the size of the saved time, you can use a $time_offset that allows you to move the starting point of time:

Offset microseconds Offset date Maximum available date for 41-bits
0 1970-01-01 00:00:00 (UTC) 2039-09-07 15:47:36 (UTC)
1577836800000 2020-01-01 00:00:00 (UTC) 2089-09-06 15:47:36 (UTC)

Encoded bitmap of floating time

It is similar to the previous generator TimeBinaryGenerator, but the position with bits of the current time is floating. That is, the length of the prefix and suffix is randomly generated each time. Simultaneously generated identifiers have less similarity, but the likelihood of collision increases.

Snowflake-id

Snowflake-id use time in microseconds and generator id. This allows you to customize the generator to your environment and reduce the likelihood of a collision, but the identifiers are very similar to each other and the identifier reveals the scheme of your internal infrastructure. Snowflake-id used in Twitter, Instagram, etc.

Domain-driven design (DDD)

How to usage in your domain.

For example create a ArticleId ValueObject:

Repository interface for Article:

Concrete repository for Article:

Now we can create a new entity with ArticleId:

License

This bundle is under the MIT license. See the complete license in the file: LICENSE


All versions of base64uid with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
paragonie/random_compat Version >=2
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 gpslab/base64uid contains the following files

Loading the files please wait ....