Skip to content

Commit 603b20e

Browse files
committed
fix random() vs php_rand() for portability
1 parent 3aa3c2d commit 603b20e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

library.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "php_redis.h"
1818
#include "library.h"
1919
#include <ext/standard/php_math.h>
20+
#include <ext/standard/php_rand.h>
2021

2122
#define UNSERIALIZE_ONLY_VALUES 0
2223
#define UNSERIALIZE_ALL 1
@@ -64,7 +65,7 @@ PHPAPI int redis_check_eof(RedisSock *redis_sock TSRMLS_DC)
6465
// Wait for a while before trying to reconnect
6566
if (redis_sock->retry_interval) {
6667
// Random factor to avoid having several (or many) concurrent connections trying to reconnect at the same time
67-
long retry_interval = (count ? redis_sock->retry_interval : (random() % redis_sock->retry_interval));
68+
long retry_interval = (count ? redis_sock->retry_interval : (php_rand(TSRMLS_C) % redis_sock->retry_interval));
6869
usleep(retry_interval);
6970
}
7071
redis_sock_connect(redis_sock TSRMLS_CC); /* reconnect */

0 commit comments

Comments
 (0)