diff --git a/PHP/php_snowdrift.h b/PHP/php_snowdrift.h index 22b5d062377cef0a2ccb4df50109e5cbd2b0d5cf..82efc5a0cda39ae62fd537a7cc57331598a3da96 100644 --- a/PHP/php_snowdrift.h +++ b/PHP/php_snowdrift.h @@ -54,7 +54,6 @@ ZEND_BEGIN_MODULE_GLOBALS(snowdrift) uint8_t Method; uint64_t BaseTime; uint8_t WorkerId; -uint8_t WorkerIdNum; uint8_t WorkerIdBitLength; uint8_t SeqBitLength; uint32_t MaxSeqNumber; diff --git a/PHP/snowdrift.c b/PHP/snowdrift.c index 656b8a5841bc1f5fc392ce9b172382309220a6c7..628c56a884735e70de4f013b6c4efaeb66c33e11 100644 --- a/PHP/snowdrift.c +++ b/PHP/snowdrift.c @@ -43,11 +43,10 @@ PHP_INI_BEGIN() STD_PHP_INI_ENTRY("snowdrift.Method", "1", PHP_INI_SYSTEM, OnUpdateLongGEZero, Method, zend_snowdrift_globals, snowdrift_globals) STD_PHP_INI_ENTRY("snowdrift.BaseTime", "1582136402000", PHP_INI_SYSTEM, OnUpdateLongGEZero, BaseTime, zend_snowdrift_globals, snowdrift_globals) STD_PHP_INI_ENTRY("snowdrift.WorkerId", "1", PHP_INI_SYSTEM, OnUpdateLongGEZero, WorkerId, zend_snowdrift_globals, snowdrift_globals) -STD_PHP_INI_ENTRY("snowdrift.WorkerIdNum", "63", PHP_INI_SYSTEM, OnUpdateLongGEZero, WorkerIdNum, zend_snowdrift_globals, snowdrift_globals) STD_PHP_INI_ENTRY("snowdrift.WorkerIdBitLength", "6", PHP_INI_SYSTEM, OnUpdateLongGEZero, WorkerIdBitLength, zend_snowdrift_globals, snowdrift_globals) STD_PHP_INI_ENTRY("snowdrift.SeqBitLength", "6", PHP_INI_SYSTEM, OnUpdateLongGEZero, SeqBitLength, zend_snowdrift_globals, snowdrift_globals) STD_PHP_INI_ENTRY("snowdrift.MaxSeqNumber", "0", PHP_INI_SYSTEM, OnUpdateLongGEZero, MaxSeqNumber, zend_snowdrift_globals, snowdrift_globals) -STD_PHP_INI_ENTRY("snowdrift.MinSeqNumber", "0", PHP_INI_SYSTEM, OnUpdateLongGEZero, MinSeqNumber, zend_snowdrift_globals, snowdrift_globals) +STD_PHP_INI_ENTRY("snowdrift.MinSeqNumber", "5", PHP_INI_SYSTEM, OnUpdateLongGEZero, MinSeqNumber, zend_snowdrift_globals, snowdrift_globals) STD_PHP_INI_ENTRY("snowdrift.TopOverCostCount", "2000", PHP_INI_SYSTEM, OnUpdateLongGEZero, TopOverCostCount, zend_snowdrift_globals, snowdrift_globals) PHP_INI_END() @@ -56,16 +55,12 @@ PHP_INI_END() static int snowdrift_init() { wid_num = (-1L << SD_G(WorkerIdBitLength)) ^ -1L; - if (SD_G(WorkerIdNum) < wid_num) - { - wid_num = SD_G(WorkerIdNum); - } shmctx.size = wid_num * sizeof(snowflake); if (shm_alloc(&shmctx) == -1) { return FAILURE; } - if (SD_G(MaxSeqNumber) < SD_G(MinSeqNumber)) + if (SD_G(MaxSeqNumber) != 0 && SD_G(MaxSeqNumber) < SD_G(MinSeqNumber)) { return FAILURE; } diff --git a/PHP/src/snowflake/snowflake.c b/PHP/src/snowflake/snowflake.c index 5a298fbb002c8d28e835e052cc94426c793723ef..feebd4505b808eaac430bbc707a68627a7cf9069 100644 --- a/PHP/src/snowflake/snowflake.c +++ b/PHP/src/snowflake/snowflake.c @@ -43,7 +43,10 @@ void Config(snowflake *flake) flake->BaseTime = flake->BaseTime != 0 ? flake->BaseTime : 1577808000000; flake->_TimestampShift = (uint8_t)(flake->WorkerIdBitLength + flake->SeqBitLength); flake->_CurrentSeqNumber = flake->MinSeqNumber; - return; + if (flake->MaxSeqNumber <= flake->MinSeqNumber) + { + flake->MinSeqNumber = 0; + } } void inline EndOverCostAction(uint64_t useTimeTick, snowflake *flake)