Skip to content

feat: add configurable bit-length, sequence number parameters, and ID generation method - #87

Draft
godruoyi with Copilot wants to merge 9 commits into
masterfrom
copilot/fix-id-generator-options
Draft

feat: add configurable bit-length, sequence number parameters, and ID generation method#87
godruoyi with Copilot wants to merge 9 commits into
masterfrom
copilot/fix-id-generator-options

Conversation

Copilot AI commented Apr 23, 2026

Copy link
Copy Markdown

The PHP library had no equivalent for the Go version's WorkerIdBitLength, SeqBitLength, MaxSeqNumber, MinSeqNumber, and Method parameters — all bit allocations were hardcoded constants with no way to adjust them, and only one ID generation strategy was available.

Changes

src/Snowflake.php

  • Added configurable workerIdBitLength (≥ 0), datacenterBitLength (≥ 0), sequenceBitLength (≥ 1) with setters/getters; the only hard constraint is that their sum must not exceed 62 (the remaining bits are used for the timestamp). No per-field upper bounds are enforced — the caller is free to allocate bits however they see fit.
  • Both workerIdBitLength and datacenterBitLength may be set to 0 for single-node deployments
  • Added maxSequenceNumber (0 = auto-derive from sequenceBitLength) and minSequenceNumber (default 0; reserving low sequence numbers for clock-rollback slots, etc.)
  • Cross-validation: maxSequenceNumber > minSequenceNumber when both non-zero
  • Added method property with two constants mirroring the Go Method field:
    • DRIFT_METHOD (1, default): on sequence overflow the timestamp is incremented by 1 (borrowing a future millisecond) — no blocking, maximum throughput. A $lastTimestamp property ensures IDs remain strictly monotonic across calls.
    • TRADITIONAL_METHOD (2): on sequence overflow the generator spin-waits until the real clock advances to the next millisecond.
  • buildId(), parseId(), id(), idForTimestamp() now use instance bit lengths instead of hardcoded constants; defaults are identical to prior behavior — fully backward compatible

src/RandomSequenceResolver.php

  • Added minSequence support; initial per-ms sequence now drawn from [minSequence, maxSequence] inclusive
  • Switched crc32(…) % max to abs(crc32(…)) % range — eliminates the pre-existing negative sequence bug

README.md — documented all new options with examples, including single-node, IP-derived node ID, and method selection examples

Usage

// Go-style narrow bit allocation: 4 dc + 6 worker + 6 seq = 16 bits (47 for timestamp)
$snowflake = (new Snowflake(1, 1))
    ->setSequenceBitLength(6)   // max 63 sequences/ms
    ->setDatacenterBitLength(4) // max 15 datacenters
    ->setWorkerIdBitLength(6)   // max 63 workers
    ->setMaxSequenceNumber(60)  // cap sequences at 60
    ->setMinSequenceNumber(5);  // reserve 0–4 for clock-rollback

$snowflake->id();

Single-node example (no worker/datacenter fields, all bits for sequence):

$snowflake = new Snowflake(0, 0);
$snowflake
    ->setDatacenterBitLength(0)  // no datacenter field
    ->setWorkerIdBitLength(0)    // no worker field
    ->setSequenceBitLength(20);  // up to 2^20-1 = 1 048 575 sequences per millisecond

$snowflake->id();

Choosing the ID generation method:

// Drift method (default — no blocking on overflow)
$snowflake = new Snowflake;
$snowflake->setMethod(Snowflake::DRIFT_METHOD);      // 1
$snowflake->id();

// Traditional method (spin-wait on overflow)
$snowflake->setMethod(Snowflake::TRADITIONAL_METHOD); // 2
$snowflake->id();

There is no explicit setTimestampBitLength() — the timestamp automatically uses all remaining bits (63 − datacenterBitLength − workerIdBitLength − sequenceBitLength).

The implementation is intentionally semantic-free: it packs whatever bit lengths the caller configures without enforcing any meaning. The caller is responsible for choosing a configuration appropriate for the expected load and uniqueness requirements.

Note: Very small sequenceBitLength values (e.g. 1–2 bits) severely limit per-millisecond throughput.

Copilot AI linked an issue Apr 23, 2026 that may be closed by this pull request
Copilot AI and others added 3 commits April 23, 2026 02:16
- Add workerIdBitLength, datacenterBitLength, sequenceBitLength properties
  to Snowflake with setters/getters (defaults maintain backward compat)
- Add maxSequenceNumber and minSequenceNumber configuration
- Update buildId(), parseId(), id(), idForTimestamp() to use instance
  bit lengths instead of hardcoded constants
- Update getDefaultSequenceResolver() to pass max/min to RandomSequenceResolver
- Add minSequence support to RandomSequenceResolver with abs() fix
  for correct non-negative sequence generation
- Add comprehensive tests for all new parameters
- Document new configuration options in README

Agent-Logs-Url: https://github.com/godruoyi/php-snowflake/sessions/035a009f-7538-4a22-870d-7f2b82a24220

Co-authored-by: godruoyi <16079222+godruoyi@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix IdGeneratorOptions parameters for consistency feat: add configurable bit-length and sequence number parameters Apr 23, 2026
Copilot AI requested a review from godruoyi April 23, 2026 02:21
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 97.59036% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.18%. Comparing base (dec895d) to head (caee283).
⚠️ Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
src/Snowflake.php 97.46% 2 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@             Coverage Diff              @@
##             master      #87      +/-   ##
============================================
- Coverage     98.71%   98.18%   -0.54%     
- Complexity       91      128      +37     
============================================
  Files             7        8       +1     
  Lines           234      330      +96     
============================================
+ Hits            231      324      +93     
- Misses            3        6       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@godruoyi

Copy link
Copy Markdown
Owner

@copilot Does this support custom WorkerIdBitLength, SeqBitLength, MaxSeqNumber, and MinSeqNumber parameters ?

like i set WorkerIdBitLength = 0 datacenterBitLength = 0 and set setSequenceBitLength = 20 and set timestampbitlength = 20 what ever i want?

The minimum for setWorkerIdBitLength() is lowered from 1 to 0, enabling
fully single-node setups where all non-timestamp bits go to the sequence
(e.g. dc=0, worker=0, seq=20 gives up to 2^20-1 sequences per ms).
Adds a dedicated test and updates the README with a single-node example.

Agent-Logs-Url: https://github.com/godruoyi/php-snowflake/sessions/8e497dfa-9e5b-4cdb-8f99-e6d71711b140

Co-authored-by: godruoyi <16079222+godruoyi@users.noreply.github.com>

Copilot AI commented Apr 23, 2026

Copy link
Copy Markdown
Author

@copilot Does this support custom WorkerIdBitLength, SeqBitLength, MaxSeqNumber, and MinSeqNumber parameters ?

like i set WorkerIdBitLength = 0 datacenterBitLength = 0 and set setSequenceBitLength ...

Yes — all four parameters are supported. Here's a quick map:

Go param PHP method Range
WorkerIdBitLength setWorkerIdBitLength(int) 0 – 15
datacenter (no Go equivalent, but same concept) setDatacenterBitLength(int) 0 – 15
SeqBitLength setSequenceBitLength(int) 3 – 21
MaxSeqNumber setMaxSequenceNumber(int) 0 = auto (2^SeqBits−1)
MinSeqNumber setMinSequenceNumber(int) ≥ 0, < max

Constraint: datacenterBitLength + workerIdBitLength + sequenceBitLength ≤ 22. Timestamp bits are whatever's left (63 − sum).

Your exact scenario (worker=0, dc=0, seq=20) is now supported in commit 54ae4f8:

$snowflake = new Snowflake(0, 0);
$snowflake
    ->setDatacenterBitLength(0)
    ->setWorkerIdBitLength(0)
    ->setSequenceBitLength(20); // up to 2^20−1 = 1 048 575 sequences/ms

$snowflake->id();

There is no explicit setTimestampBitLength() — the timestamp automatically uses all remaining bits (in the example above: 63 − 20 = 43 bits, ~278 years). You can indirectly "shrink" the timestamp by allocating more bits to worker/dc/seq.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/illuminate/contracts/zipball/4787042340aae19a7ea0fa82f4073c4826204a48
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/laravel/pint/zipball/0770e9b7fafd50d4586881d456d6eb41c9247a80
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/myclabs/DeepCopy/zipball/07d290f0c47959fd5eed98c95ee5602db07e0b6a
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/nikic/PHP-Parser/zipball/dca41cd15c2ac9d055ad70dbfd011130757d1f82
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/php-fig/simple-cache/zipball/764e0b3939f5ca87cb904f570ef9be2d78a07865
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/phpstan/phpstan/zipball/37982d6fc7cbb746dda7773530cda557cdf119e1
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/predis/predis/zipball/07105e050622ed80bd60808367ced9e379f31530
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/c34583b87e7b7a8055bf6c450c2c77ce32a24084
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/5e3a687f7d8ae33fb362c5c0743794bbb2420a1d
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/code-unit/zipball/a81fee9eef0b7a76af11d121767abc44c104e503
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/comparator/zipball/55dfef806eb7dfeb6e7a6935601fef866f8ca48d
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/complexity/zipball/68ff824baeae169ec9f2137158ee529584553799
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/diff/zipball/c41e007b4b62af48218231d6c2275e4c9b975b2e
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/environment/zipball/8074dbcd93529b357029f5cc5058fd3e43666984
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/exporter/zipball/0735b90f4da94969541dac1da743446e276defa6
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/global-state/zipball/987bafff24ecc4c9ac418cab1145b96dd6e9cbd9
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/856e7f6a75a84e339195d48c556f23be2ebf75d0
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/202d0e344a580d7f7d04b3fafce6933e59dae906
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/24ed13d98130f0e7122df55d06c5c4942a577957
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/7e308268858ed6baedc8704a304727d20bc07c77
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a95037b6d9e608ba092da1b23931e537cadc3c3c
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/0c7b06ff49e3d5072f057eb1fa59258bf287a748
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/php-timer/zipball/e2a2d67966e740530f4a3343fe2e030ffdc1161d
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/phpunit/zipball/33198268dad71e926626b618f3ec3966661e4d90
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/47e34210757a2f37a97dcd207d032e1b01e64c7a
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/type/zipball/462699a16464c3944eefc02ebdd77882bd3925bf
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/sebastianbergmann/version/zipball/c51fa83a5d8f43f1402e3f32a005e6262244ef17
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)
  • https://api.github.com/repos/theseer/tokenizer/zipball/b7489ce515e168639d17feec34b8847c326b0b3c
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/0cRKoH /usr/bin/composer install --no-interaction --ignore-platform-req=ext-redis --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -d /home/REDACTED/work/php-snowflake/php-snowflake (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@godruoyi

Copy link
Copy Markdown
Owner

@copilot This looks like a more advanced use case. The idea is that we allow callers to
customize the bit length of each component — but this puts the responsibility on the
caller to understand the Snowflake algorithm well enough to configure it correctly.

For example, a caller could allocate more bits to the datacenter and machine ID fields,
reduce the timestamp bits, and increase the sequence bits. Taking it further, they could
even map the current machine's IP address to the datacenter and machine ID fields — so
the system automatically derives those values from the host's IP at runtime.

In this model, the Snowflake implementation itself doesn't need to care about the
semantics — it just generates IDs based on whatever bit lengths the caller provides. Is
that the right understanding?

Copilot AI commented Apr 23, 2026

Copy link
Copy Markdown
Author

@copilot This looks like a more advanced use case. The idea is that we allow callers to
customize the bit length of each component — but this puts the responsibility on the
caller to understan...

That's exactly right. The implementation is intentionally semantic-free — it just shifts bits according to whatever lengths the caller configured. The caller owns the meaning of each field.

The IP-to-node-ID pattern works well with this. For example, using the last two octets of the host IP:

$ip = explode('.', gethostbyname(gethostname()));
$datacenter = (int) $ip[2] & 0x1F; // octet 3, low 5 bits
$worker     = (int) $ip[3] & 0x1F; // octet 4, low 5 bits

$snowflake = new Snowflake($worker, $datacenter);
$snowflake->id();

Or with a larger bit allocation to cover a wider IP range:

$lastOctet = (int) $ip[3]; // 0–255 needs 8 bits
$snowflake = new Snowflake($lastOctet, 0);
$snowflake
    ->setDatacenterBitLength(0)
    ->setWorkerIdBitLength(8)   // fits 0–255
    ->setSequenceBitLength(14); // 8+14=22, still within the budget

$snowflake->id();

The library doesn't validate or care what those numbers mean — it just packs them into the right bit positions.

@godruoyi

Copy link
Copy Markdown
Owner

@copilot Is it possible to have our Snowflake implementation impose no restrictions on the bit
length of each component, letting the caller configure them freely? The generator would
then produce IDs based purely on whatever lengths are provided.

For example:

  • Set sequence bits to 1 → only one sequence value ever exists
  • Set timestamp bits very large → the ID space can last for an extremely long time
  • Set datacenter bits very large → supports a massive number of datacenters

We don't enforce any constraints — we just generate based on what the caller gives us.
Is this feasible?

Copilot AI commented Apr 23, 2026

Copy link
Copy Markdown
Author

@copilot Is it possible to have our Snowflake implementation impose no restrictions on the bit
length of each component, letting the caller configure them freely? The generator would
then produc...

Yes, that's feasible and now implemented in commit 04b695c.

The per-field upper limits (0–15 for worker/datacenter, 3–21 for sequence) and the old sum ≤ 22 cap are gone. The only remaining constraint is the hard technical one: datacenterBitLength + workerIdBitLength + sequenceBitLength ≤ 62 (leaving at least 1 bit for the timestamp inside a 63-bit signed integer). Negative values are rejected. Everything else is the caller's choice.

Examples that now work:

// 1-bit sequence (2 values: 0 and 1)
(new Snowflake())->setSequenceBitLength(1);

// Very large timestamp range — give 55 bits to timestamp
(new Snowflake(0, 0))->setDatacenterBitLength(0)->setWorkerIdBitLength(0)->setSequenceBitLength(7); // 63−7=56 bits for ts

// Huge datacenter space
(new Snowflake(0, 0))->setWorkerIdBitLength(0)->setSequenceBitLength(6)->setDatacenterBitLength(30); // 30+0+6=36≤62

A note is added to setSequenceBitLength's docblock warning that very small bit widths (1–2 bits) severely limit per-millisecond throughput — the generator itself has no opinion on that choice.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/illuminate/contracts/zipball/4787042340aae19a7ea0fa82f4073c4826204a48
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/laravel/pint/zipball/0770e9b7fafd50d4586881d456d6eb41c9247a80
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/myclabs/DeepCopy/zipball/07d290f0c47959fd5eed98c95ee5602db07e0b6a
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/nikic/PHP-Parser/zipball/dca41cd15c2ac9d055ad70dbfd011130757d1f82
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/php-fig/simple-cache/zipball/764e0b3939f5ca87cb904f570ef9be2d78a07865
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/phpstan/phpstan/zipball/37982d6fc7cbb746dda7773530cda557cdf119e1
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/predis/predis/zipball/07105e050622ed80bd60808367ced9e379f31530
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/c34583b87e7b7a8055bf6c450c2c77ce32a24084
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/5e3a687f7d8ae33fb362c5c0743794bbb2420a1d
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/code-unit/zipball/a81fee9eef0b7a76af11d121767abc44c104e503
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/comparator/zipball/55dfef806eb7dfeb6e7a6935601fef866f8ca48d
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/complexity/zipball/68ff824baeae169ec9f2137158ee529584553799
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/diff/zipball/c41e007b4b62af48218231d6c2275e4c9b975b2e
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/environment/zipball/8074dbcd93529b357029f5cc5058fd3e43666984
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/exporter/zipball/0735b90f4da94969541dac1da743446e276defa6
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/global-state/zipball/987bafff24ecc4c9ac418cab1145b96dd6e9cbd9
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/856e7f6a75a84e339195d48c556f23be2ebf75d0
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/202d0e344a580d7f7d04b3fafce6933e59dae906
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/24ed13d98130f0e7122df55d06c5c4942a577957
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/7e308268858ed6baedc8704a304727d20bc07c77
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a95037b6d9e608ba092da1b23931e537cadc3c3c
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/0c7b06ff49e3d5072f057eb1fa59258bf287a748
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/php-timer/zipball/e2a2d67966e740530f4a3343fe2e030ffdc1161d
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/phpunit/zipball/33198268dad71e926626b618f3ec3966661e4d90
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/47e34210757a2f37a97dcd207d032e1b01e64c7a
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/type/zipball/462699a16464c3944eefc02ebdd77882bd3925bf
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/sebastianbergmann/version/zipball/c51fa83a5d8f43f1402e3f32a005e6262244ef17
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)
  • https://api.github.com/repos/theseer/tokenizer/zipball/b7489ce515e168639d17feec34b8847c326b0b3c
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gR6Zxt /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/RjAKGV /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins rgo/bin/git e/git rev-�� --git-dir (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/raL8dP /usr/bin/composer install --no-interaction --ignore-platform-req=ext-swoole --prefer-dist --no-plugins -n git tag &#39;--verify&#39; &#39;a81fee9eef0b7a76af11d121767abc44c104e503^{commit}&#39; git rgo/bin/git --git-dir (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@godruoyi

Copy link
Copy Markdown
Owner

@copilot what is this mean ? Method uint16 // 雪花计算方法,(1-漂移算法|2-传统算法),默认1 would you please implement it

Copilot AI commented Apr 23, 2026

Copy link
Copy Markdown
Author

@copilot what is this mean ? Method uint16 // 雪花计算方法,(1-漂移算法|2-传统算法),默认1 would you please implement it

That field specifies the ID generation method for handling sequence overflow:

  • Method 1 — drift algorithm (漂移算法): when all sequence numbers for a millisecond are exhausted, the timestamp is incremented by 1 (borrowing a future millisecond) instead of waiting. ID generation never blocks and throughput is bounded only by CPU speed. The embedded timestamp may briefly run ahead of the wall clock, but IDs remain strictly monotonic.
  • Method 2 — traditional algorithm (传统算法): when the sequence overflows, the generator spin-waits until the real clock advances to the next millisecond.

Both are now implemented in commit b024037. Drift is the default (matching the Go library):

use Godruoyi\Snowflake\Snowflake;

// Drift (default — no call needed)
$snowflake = new Snowflake;
$snowflake->setMethod(Snowflake::DRIFT_METHOD);     // 1
$snowflake->id();

// Traditional
$snowflake->setMethod(Snowflake::TRADITIONAL_METHOD); // 2
$snowflake->id();

Copilot AI changed the title feat: add configurable bit-length and sequence number parameters feat: add configurable bit-length, sequence number parameters, and ID generation method Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

保持一致

3 participants