Download the PHP package glhd/bits without Composer

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

Build Status Coverage Status Latest Stable Release MIT Licensed Follow @inxilpro on Twitter Follow @chris@any.dev on Mastodon

Bits

Bits is a PHP library for generating unique 64-bit identifiers for use in distributed computing. You can use Bits to create Twitter Snowflake IDs, Sonyflake IDs, or any other unique ID that uses bit sequences.

Installation

Configuration

[!warning] If you do not configure the worker ID and datacenter ID, you may run into concurrency issues using Bits on multiple app servers.

There are two things you will need to configure to ensure that your IDs are valid and unique.

Set the BITS_WORKER_ID and BITS_DATACENTER_ID

Snowflakes are so compact because they rely on the fact that each worker has its own ID. If you are running multiple servers in multiple datacenters, you need to give each a unique value. You need to set a unique BITS_DATACENTER_ID (0-31) for each datacenter your application uses, and each worker in the same datacenter should have a unique BITS_WORKER_ID (0-31). This means that you can have, at most, 1024 separate workers generating snowflakes at the same exact moment in time.

[!note] If you use Lambda, this can be an issue. Eventually, we hope to have a serverless solution for Bits, but right now you need to manage locking/releasing IDs yourself if you're generating snowflakes in something like Laravel Vapor.

Set the BITS_EPOCH

Another reason snowflakes are compact is because they use a custom "epoch" value (rather than the Unix epoch of January 1, 1970). This is the earliest a snowflake can be generated, and also set the limit to how far in the future snowflakes can be generated. By default, this value is 2023-01-01, which should be fine for most systems. But if you're going to use time-travel to before January 2023 in your tests, this may cause problems (in which case you should set your epoch to before the earliest moment you would time-travel).

Usage

To get a new snowflake ID, simply call Snowflake::make(). This returns a new Snowflake object:

You can also use the snowflake() or sonyflake() global helper functions, if you prefer.

All Bits IDs implement __toString() and the Laravel Query\Expression interface so that you can easily pass them around without juggling types.

Usage with JavaScript

It's important to note that JavaScript only supports ~52-bit integers so if you're passing Snowflakes to JavaScript, be sure to cast them to a string.

All Bits IDs implement Jsonable and JsonSerializable, so if you pass a Bits instance to json_encode it will automatically handle this for you. But if you're using integer IDs that were generated by Bits, you will have to cast them yourself.

Usage with Eloquent Models

Bits provides a HasSnowflakes trait that behaves the same as Eloquent’s HasUuids and HasUlids traits. Simply add HasSnowflakes to your model, and whenever they're inserted or upserted, a new Snowflake will be generated for you.

You can also use Snowflake or Sonyflake as in your Eloquent $casts array to have that attribute automatically cast to a Bits instance.

Using IDs as timestamps

One nice property of Snowflakes and Sonyflakes is that they are sortable by time, and can have the timestamp extracted from the ID for later use. This means that if you want to, you can use these IDs in place of a created_at timestamp:

Usage with Livewire

If you're using Livewire, you can use the SnowflakeSynth synthesizer to make Snowflakes usable in your components.

All you need to do is to register the synthesizer in your AppServiceProvider:

If you're using a non-Snowflake variant of Bits, you can use the BitsSynth instead, which supports any version of Bits at the cost of storing a little more data.

About 64-bit Unique IDs

Snowflake format

Sonyflake format

Both of these IDs are represented by the same 64-bit integer, 56705782302306333, but convey different metadata. Depending on your scale and distribution needs, you may find one or the other format preferable, or choose to implement your own custom format.

Bits lets generate any kind of 64-bit unique ID you'd like, in the way that makes the most sense for your use-case.


All versions of bits with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/support Version ^9|^10|^11|^12|13.x-dev|dev-master|dev-main
illuminate/contracts Version ^9|^10|^11|^12|13.x-dev|dev-master|dev-main
ext-json Version *
nesbot/carbon Version ^2.62.1|^3.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 glhd/bits contains the following files

Loading the files please wait ....