Skip to content

A free open source IT asset/license management system

Fixed #8827 - allow array of memcache servers

snipe99ea2d30aed3
diff --git a/config/cache.php b/config/cache.php
index 34c2b75f53..260afc1086 100644
--- a/config/cache.php
+++ b/config/cache.php
@@ -2,6 +2,36 @@
use Illuminate\Support\Str;
+// Memcached server pool. MEMCACHED_HOST can be a single hostname
+// (single-server, the historical shape) or a comma-separated list to
+// spread the cache across a pool. Each list entry accepts one of:
+//
+// host
+// host:port
+// host:port:weight
+//
+// A missing port falls back to MEMCACHED_PORT (or 11211). A missing
+// weight defaults to 100 — matching the pre-existing single-server
+// default, so distribution stays uniform until an operator opts into
+// per-server weighting.
+$memcachedDefaultPort = (int) env('MEMCACHED_PORT', 11211);
+$memcachedServers = [];
+foreach (array_filter(array_map('trim', explode(',', (string) env('MEMCACHED_HOST', '127.0.0.1')))) as $entry) {
+ $parts = explode(':', $entry);
+ $memcachedServers[] = [
+ 'host' => $parts[0],
+ 'port' => isset($parts[1]) ? (int) $parts[1] : $memcachedDefaultPort,
+ 'weight' => isset($parts[2]) ? (int) $parts[2] : 100,
+ ];
+}
+if (empty($memcachedServers)) {
+ $memcachedServers[] = [
+ 'host' => '127.0.0.1',
+ 'port' => $memcachedDefaultPort,
+ 'weight' => 100,
+ ];
+}
+
return [
/*
@@ -64,13 +94,7 @@ return [
'options' => [
// Memcached::OPT_CONNECT_TIMEOUT => 2000,
],
- 'servers' => [
- [
- 'host' => env('MEMCACHED_HOST', '127.0.0.1'),
- 'port' => env('MEMCACHED_PORT', 11211),
- 'weight' => 100,
- ],
- ],
+ 'servers' => $memcachedServers,
],
'redis' => [