PHPackages                             bulldog/id - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bulldog/id

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bulldog/id
==========

ID Generator

v1.5.0(7y ago)15701MITPHPPHP ^7.1

Since Nov 4Pushed 7y ago2 watchersCompare

[ Source](https://github.com/bulldogcreative/id)[ Packagist](https://packagist.org/packages/bulldog/id)[ RSS](/packages/bulldog-id/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (8)Dependencies (2)Versions (10)Used By (1)

id
==

[](#id)

[![Build Status](https://camo.githubusercontent.com/966e2a372635833a8df8e53cc90ff662b5971c70e28b806137c3285b63b2e6ba/68747470733a2f2f7472617669732d63692e6f72672f62756c6c646f6763726561746976652f69642e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/bulldogcreative/id)[![PHP 7.2+](https://camo.githubusercontent.com/9e83969b6db4e5c3d85d5fba58e93a266d1a745c46c758a616fa922833fab7af/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72657175697265732d706870253230372e322532422d626c75652e737667)](https://camo.githubusercontent.com/9e83969b6db4e5c3d85d5fba58e93a266d1a745c46c758a616fa922833fab7af/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72657175697265732d706870253230372e322532422d626c75652e737667)[![PHP version](https://camo.githubusercontent.com/d62a7c25437c8148f061892205d84c5c29e586f5ec4cbd3ba00cf5c5b8aedd68/68747470733a2f2f62616467652e667572792e696f2f70682f62756c6c646f6725324669642e737667)](https://badge.fury.io/ph/bulldog%2Fid)

A library for generating IDs.

Object ID
---------

[](#object-id)

If your Object ID is long enough, it can be generated on multiple systems, without worrying about a collision. Using time-based buckets gives us locality for each new ID.

The first half of the ID is a bucket. The bucket is the difference between two unix timestamps. The first timestamp is the beginning of the current year, and the second timestamp is when the method is called. This is more efficient than only using the current timestamp. We will end up with more buckets this way.

The second half of the ID uses the `random_bytes` function. It is then safely encoded using base 64. We strip away any characters that are unsafe for URLs.

### Usage

[](#usage)

The example below generates 5,000 Object IDs.

```
