File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ public function nextId(): string {
3434 // Relative time
3535 [$ seconds , $ milliseconds ] = $ this ->getCurrentTime ();
3636
37- $ serverId = $ this ->getServerId () & 0x1FF ; // Keep 9 bits
37+ $ serverId = $ this ->getServerId (); // Already 9 bits
3838 $ isCli = (int )$ this ->isCli (); // 1 bit
3939 $ sequenceId = $ this ->sequenceGenerator ->nextId ($ seconds , $ milliseconds , $ serverId ); // 12 bits
4040 if ($ sequenceId > 0xFFF || $ sequenceId === false ) {
@@ -104,12 +104,18 @@ private function getCurrentTime(): array {
104104
105105 /**
106106 * Return configured serverid or generate one if not set
107+ *
108+ * @return int<0, 511>
107109 */
108110 private function getServerId (): int {
109111 $ serverid = $ this ->config ->getSystemValueInt ('serverid ' , -1 );
110- return $ serverid > 0
111- ? $ serverid
112- : crc32 (gethostname () ?: random_bytes (8 ));
112+ if ($ serverid < 1 ) {
113+ // Fallback: generates a server ID based on hostname
114+ // or random bytes if hostname isn't available
115+ $ serverid = hexdec (hash ('xxh32 ' , gethostname () ?: random_bytes (8 )));
116+ }
117+
118+ return $ serverid & 0x1FF ;
113119 }
114120
115121 private function isCli (): bool {
You can’t perform that action at this time.
0 commit comments