Skip to content

Commit 091f0b4

Browse files
committed
Select memcached rand fn based on *_WP_ORG_MODE
We use mt_rand for memcached because CSPRNGs can have lag spikes and we simply gain nothing from the cryto properties. But wordpress.org prohibits mt_rand, so we use wp_rand for WP.org only.
1 parent b9918e3 commit 091f0b4

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/Memcached.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,18 @@ public static function getRandomServer(
4545
$total_weight += $s['weight'] ?? 1;
4646
}
4747

48-
$rand = mt_rand( 1, $total_weight );
48+
if ( defined( 'STATIC_DEPLOY_WP_ORG_MODE' ) && STATIC_DEPLOY_WP_ORG_MODE ) {
49+
$rand = wp_rand( 1, $total_weight );
50+
} else {
51+
$rand = mt_rand( 1, $total_weight );
52+
}
53+
54+
if ( ! defined( 'STATIC_DEPLOY_WP_ORG_MODE' ) || ! STATIC_DEPLOY_WP_ORG_MODE ) {
55+
$rand = mt_rand( 1, $total_weight );
56+
} else {
57+
$rand = wp_rand( 1, $total_weight );
58+
}
59+
4960
$current = 0;
5061

5162
foreach ( $servers as $server ) {

0 commit comments

Comments
 (0)