Download the PHP package visus/cuid2 without Composer

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

visus/cuid2

GitHub Workflow Status (with event)

Sonar Quality Gate Sonar Coverage Sonar Tests

PHP Version Packagist Downloads GitHub

This library is a PHP implementation of CUID2. CUID2 identifiers are secure, URL-safe, and collision-resistant. You can generate these identifiers on multiple machines at the same time. The machines do not need to coordinate with each other.

Table of Contents - [General Overview](#general-overview) - [Architecture](#architecture) - [CUID2 Structure](#cuid2-structure) - [Generation Process](#generation-process) - [Getting Started](#getting-started) - [Installation](#installation) - [Instance-Based Usage](#instance-based-usage) - [Static-Based Usage](#static-based-usage) - [Validation](#validation) - [Considerations](#considerations) - [Performance: GMP Extension](#performance-gmp-extension) - [Contributing](#contributing)

General Overview

CUID2 stands for Collision-resistant Unique Identifier, version 2. CUID2 solves common problems with UUIDs and other identifier systems. This PHP library gives you these features:

For more information about CUID2, go to the official project website.

Architecture

CUID2 Structure

Each CUID2 identifier contains several components. The library combines and hashes these components to make the identifier unique.

Generation Process

  1. Prefix: The library adds a random lowercase letter. This adds entropy.
  2. Timestamp: The library records the current time in milliseconds. This makes the identifier sortable.
  3. Counter: The library adds a value that always increases. This prevents collisions when you generate identifiers quickly.
  4. Fingerprint: The library adds an identifier for the machine and the process. This identifier includes the hostname, the process ID, and environment data.
  5. Random Data: The library adds cryptographically secure random bytes.
  6. Hashing: The library combines all components and hashes them with SHA3-512. The result is a raw 64-byte digest, not a hex string.
  7. Encoding: The library converts the raw digest bytes directly to base36. It does not build an intermediate hex string.
  8. Truncation: The library trims the result to the length you request, minus the prefix.

Example output: p6p168tx2rxtgyehd3p2wz04

This design prevents collisions. Even when multiple processes generate identifiers at the same time, the timestamp, the counter, the fingerprint, and the random data keep each identifier unique.

Getting Started

Installation

Use Composer to install visus/cuid2:

Requirements:

Recommended:

Instance-Based Usage

Static-Based Usage

Validation

The isValid() method checks whether a string matches the CUID2 format.

[!NOTE] This method validates only the format. It does not guarantee that this library generated the value. It does not guarantee that the value is globally unique.

Considerations

Performance: GMP Extension

This library converts a raw hash digest to base36 during identifier generation. It reads the digest bytes directly and never builds an intermediate hex string, on either the GMP path or the pure-PHP fallback. For the best performance, install and enable the GMP extension. This step is strongly recommended.

Performance Comparison (GMP median vs. the pure-PHP Utils::bytesToBase36() fallback):

Digest Size GMP Median Pure PHP Median Performance Gain
SHA3-512 (64 bytes) 0.36 μs 11.3 μs ~31x faster
32 bytes 0.22 μs 4.7 μs ~21x faster
16 bytes 0.15 μs 2.2 μs ~15x faster
8 bytes 0.14 μs 1.3 μs ~9x faster

Key Takeaways:

Installation:

To check whether the extension is loaded, run one of these commands. On Unix, run php -m | grep gmp. On Windows, run php -m | findstr gmp.

Contributing

You can contribute to this project. See CONTRIBUTING.md for detailed guidelines about:

This project follows the Conventional Commits standard. This project maintains 100% code coverage.


All versions of cuid2 with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
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 visus/cuid2 contains the following files

Loading the files please wait ...