Dan Brown

Made memcached config allow mulitple servers

...@@ -17,6 +17,12 @@ SESSION_DRIVER=file ...@@ -17,6 +17,12 @@ SESSION_DRIVER=file
17 #SESSION_DRIVER=memcached 17 #SESSION_DRIVER=memcached
18 QUEUE_DRIVER=sync 18 QUEUE_DRIVER=sync
19 19
20 +# Memcached settings
21 +# If using a UNIX socket path for the host, set the port to 0
22 +# This follows the following format: HOST:PORT:WEIGHT
23 +# For multiple servers separate with a comma
24 +MEMCACHED_SERVERS=127.0.0.1:11211:100
25 +
20 # Storage 26 # Storage
21 STORAGE_TYPE=local 27 STORAGE_TYPE=local
22 # Amazon S3 Config 28 # Amazon S3 Config
...@@ -56,9 +62,4 @@ MAIL_HOST=localhost ...@@ -56,9 +62,4 @@ MAIL_HOST=localhost
56 MAIL_PORT=1025 62 MAIL_PORT=1025
57 MAIL_USERNAME=null 63 MAIL_USERNAME=null
58 MAIL_PASSWORD=null 64 MAIL_PASSWORD=null
59 -MAIL_ENCRYPTION=null
60 -
61 -# Memcached settings
62 -#MEMCACHED_HOST=127.0.0.1
63 -# If using a UNIX socket path for the host, set the port to 0
64 -#MEMCACHED_PORT=11211
...\ No newline at end of file ...\ No newline at end of file
65 +MAIL_ENCRYPTION=null
...\ No newline at end of file ...\ No newline at end of file
......
1 <?php 1 <?php
2 2
3 +// MEMCACHED - Split out configuration into an array
4 +if (env('CACHE_DRIVER') === 'memcached') {
5 + $memcachedServerKeys = ['host', 'port', 'weight'];
6 + $memcachedServers = explode(',', trim(env('MEMCACHED_SERVERS', '127.0.0.1:11211:100'), ','));
7 + foreach ($memcachedServers as $index => $memcachedServer) {
8 + $memcachedServerDetails = explode(':', $memcachedServer);
9 + $components = count($memcachedServerDetails);
10 + if ($components < 2) $memcachedServerDetails[] = '11211';
11 + if ($components < 3) $memcachedServerDetails[] = '100';
12 + $memcachedServers[$index] = array_combine($memcachedServerKeys, $memcachedServerDetails);
13 + }
14 +}
15 +
3 return [ 16 return [
4 17
5 /* 18 /*
...@@ -49,13 +62,7 @@ return [ ...@@ -49,13 +62,7 @@ return [
49 62
50 'memcached' => [ 63 'memcached' => [
51 'driver' => 'memcached', 64 'driver' => 'memcached',
52 - 'servers' => [ 65 + 'servers' => env('CACHE_DRIVER') === 'memcached' ? $memcachedServers : [],
53 - [
54 - 'host' => env('MEMCACHED_HOST', '127.0.0.1'),
55 - 'port' => env('MEMCACHED_PORT', 11211),
56 - 'weight' => 100,
57 - ],
58 - ],
59 ], 66 ],
60 67
61 'redis' => [ 68 'redis' => [
......