aports/testing/php84-pecl-redis/fix-random2.patch
2024-07-04 20:10:11 +00:00

36 lines
1.2 KiB
Diff

Patch-Source: https://github.com/phpredis/phpredis/commit/c139de3abac1dd33b97ef0de5af41b6e3a78f7ab
From c139de3abac1dd33b97ef0de5af41b6e3a78f7ab Mon Sep 17 00:00:00 2001
From: michael-grunder <michael.grunder@gmail.com>
Date: Sat, 1 Jun 2024 13:09:30 -0700
Subject: [PATCH] We don't need to use a ranom value for our ECHO liveness
challenge.
A microsecond resolution timestamp combined with a monotonically
incremented counter should be sufficient.
This also fixes PHP 8.4 compilation as PHP 8.4 doesn't seem to have
`php_rand()`.
---
library.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/library.c b/library.c
index ce0cbda26..42a132c4c 100644
--- a/library.c
+++ b/library.c
@@ -2886,11 +2886,13 @@ redis_sock_create(char *host, int host_len, int port,
}
static int redis_uniqid(char *buf, size_t buflen) {
+ static unsigned long counter = 0;
struct timeval tv;
+
gettimeofday(&tv, NULL);
return snprintf(buf, buflen, "phpredis:%08lx%05lx:%08lx",
- (long)tv.tv_sec, (long)tv.tv_usec, (long)php_rand());
+ (long)tv.tv_sec, (long)tv.tv_usec, counter++);
}
static int redis_stream_liveness_check(php_stream *stream) {