Download the PHP package mattkingshott/snowflake without Composer

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

Snowflake

This package enables a Laravel application to create Twitter Snowflake identifiers. It is a very thin wrapper around the excellent Snowflake PHP library created by Godruoyi.

What are Snowflakes?

Snowflakes are a form of unique identifier devised by Twitter. In this respect, they are similar to other unique identifier algorithms such as UUID or ULID.

Why should I use them?

Some of the benefits of using Snowflakes (over alternatives such as UUID) include:

Installation

Pull in the package using Composer:

Configuration

Snowflake includes a configuration file with several settings that you can use to initialize the Snowflake service. You should begin by publishing this configuration file:

Distributed architecture

The service allows for the use of a distributed architectural setup involving data centers and worker nodes that are each responsible for generating Snowflakes according to their own designated identifiers. For maximum flexibility, as well as backward compatibility, this is the default configuration.

If you do not intend to run a distributed architectural setup, then your first step should be to set the corresponding configuration value to false.

Data centers and worker nodes

When using a distributed architectural setup, you'll need to set the data center and worker node that the application should use when generating Snowflakes. These are both set to 1 by default, as that is a good starting point, but you are free to increase these numbers as you add more centers and nodes.

The maximums for each of these configuration values is 31. This gives you up to 31 nodes per data center, and 31 data centers in total. Therefore, you can have up 961 worker nodes each generating unique Snowflakes.

If you have disabled distributed architecture, then you can skip the data center and worker node values as they will be ignored by the service.

Starting timestamp

The service compares the Unix Epoch with the given starting timestamp as part of the process in generating a unique Snowflake. As a result, Snowflakes can be generated for up to 69 years using any given starting timestamp.

In most cases, you should set this value to the current date using a format of YYYY-MM-DD.

Do not set the timestamp to a date in the future, as that won't achieve anything. You should also avoid using a date in the past, as that may reduce the number of years for which you can generate timestamps.

Sequence resolver

In order to handle the generation of unique keys within the same millisecond, the service uses a sequence resolver. There are several to choose from, however they each have dependencies, such as Redis. You are free to use any of them, however the default option is a good choice, as it doesn't have any dependencies.

Usage

You can generate a Snowflake by resolving the service out of the container and calling its id method:

WARNING: Do not create instances of the Snowflake service, as doing so risks generating matching keys / introducing collisions. Instead, always resolve the Snowflake singleton out of the container. You can also use the global helper method (see below).

Since this is a little cumbersome, the package also registers a global snowflake() helper method that you can use anywhere.

Databases

If you want to use Snowflakes in your database e.g. for primary and foreign keys, then you'll need to perform a couple of steps.

First, modify your migrations so that they use the Snowflake migration methods e.g.

Here's an example:

Next, if you're using Eloquent, add the package's Snowflakes trait to your Eloquent models:

Finally, configure the model's $casts array to use the package's SnowflakeCast for all Snowflake attributes. This cast automatically handles conversion from string to integer and vice-versa when storing or fetching a Snowflake from the database. It also ensures that languages which do not support 64-bit integers (such as JavaScript), will not truncate the Snowflake.

Contributing

Thank you for considering a contribution to Snowflake. You are welcome to submit a PR containing improvements, however if they are substantial in nature, please also be sure to include a test or tests.

License

The MIT License (MIT). Please see License File for more information.


All versions of snowflake with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
godruoyi/php-snowflake Version ^2.0
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 mattkingshott/snowflake contains the following files

Loading the files please wait ....