Nextcloud PHP API (master)

ISnowflakeGenerator

Nextcloud Snowflake ID generator

Customized version of Snowflake IDs for Nextcloud: 1 bit : Unused, always 0, avoid issue with PHP signed integers. 31 bits: Timestamp from 2025-10-01. Allows to store a bit more than 68 years. Allows to find creation time. 10 bits: Milliseconds (between 0 and 999) 9 bits: Server ID, identify server which generated the ID (between 0 and 511) 1 bit : CLI or Web (0 or 1) 12 bits: Sequence ID, usually a serial number of objects created in the same number on same server (between 0 and 4095)

Tags
since
33.0.0
Attributes
#[Consumable]
$since: '33.0.0'

Table of Contents

Constants

TS_OFFSET  : mixed = 1759276800
Offset applied on timestamps to keep it short Start from 2025-10-01 at 00:00:00

Methods

minForTimeId()  : string
Return the smallest possible Snowflake ID for a given timestamp
nextId()  : string
Get a new Snowflake ID.

Constants

TS_OFFSET

Offset applied on timestamps to keep it short Start from 2025-10-01 at 00:00:00

public mixed TS_OFFSET = 1759276800
Tags
since
33.0

Methods

minForTimeId()

Return the smallest possible Snowflake ID for a given timestamp

public minForTimeId(int $timestamp) : string

Not a real snowflake ID! Only use it for comparisons. Examples:

  • find all Snowflake IDs generated from a given $timestamp Look for >= minForTimeId($timestamp)
  • delete all Snowflake IDs generated before a given $timestamp Delete where id < minForTimeId($timestamp)
Parameters
$timestamp : int
Tags
since
34.0.1
Return values
string

nextId()

Get a new Snowflake ID.

public nextId() : string

Each call to this method is guaranteed to return a different ID.

Tags
since
33.0
Return values
string
On this page

Search results