Download the PHP package moves/snowflake without Composer

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

🚨 WARNINGS 🚨

This package is only compatible with 64-bit installations of PHP.

This package has not been tested against incredibly strenuous loads such as the actual traffic seen regularly by Twitter.

Introduction

This is a PHP implementation of Twitter's Snowflake, Sony's Sonyflake, and our own custom Modelflake ID generator.

Traits are also included which allow you to directly and automatically generate IDs on Eloquent Model classes.

Installation

To add this library into your project, run:

Usage

Eloquent Models

Prerequisites

For each separate deployment of your application, be sure to set a unique value for the SNOWFLAKE_MACHINE_ID environment key.

The default implementation of the provided Eloquent Snowflake generator traits requires you to have a configured Cache driver.

🚨 It is important to note that the file Cache driver is not supported for deployments on distributed infrastructure such as "Serverless"/AWS Lambdas. 🚨

Snowflake IDs rely on the creation of a unique sequence number. On traditional deployment systems where each "environment" necessitates exactly one physical or virtual server instance, atomic sequence number generation is only necessary between threads on each individual server. However, with modern deployment systems where a single "environment" may consist of any number of physical or virtual servers, atomic locking must be ensured across all server instances. This is only possible via a dedicated microservice, or via a shared cache system.

Usage

To use the ID generator of your choice on your Eloquent Model classes, simply add the corresponding trait to your Model.

Moves\Snowflake\Traits\EloquentTwitterSnowflakeId for Twitter Snowflake

Moves\Snowflake\Traits\EloquentSonyflakeId for Twitter Snowflake

Moves\Snowflake\Traits\EloquentModelflakeId for Twitter Snowflake

or

Moves\Snowflake\Traits\EloquentSnowflakeId to specify your own custom ID Generator class

On create, your model class will automatically generate a unique ID and apply it to your model instance before it is inserted into the database.

Note that JavaScript only supports up to 53-bit integers, and thus integer snowflake IDs will not be processed as the correct value when retrieved as data from your API. As such, all of the included ID generation traits also automatically add string casting on your model's key field so snowflake IDs are returned as strings when using toArray or toJson.

Overriding Default Sequence Number Generation

The supplied traits provide a default implementation for generating a unique sequence number, relying on Laravel's Cache facade and atomic locking. However, you can override the default implementation by providing your own function closure which returns a unique sequence number. See Providing Your Own Generator for more details.

Providing Your Own Generator

To provide your own generator class, use the Moves\Snowflake\Traits\EloquentSnowflakeId trait, and implement the following method header:

You can build your own class which implements the ISnowflakeGenerator interface, or you can provide an instance of one of the generators from this package with alternate values passed to the constructor.

For example, this is how you might provide your own sequence number generator function to the TwitterSnowflake generator:

Direct Usage

This package is still usable outside of Eloquent model classes. Instantiate and call the appropriate generator class wherever you need it:

You can also use the generators to parse an existing Snowflake ID into its component parts:


All versions of snowflake with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/support Version ^10.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 moves/snowflake contains the following files

Loading the files please wait ....