|
1 | 1 | <?php
|
2 | 2 |
|
| 3 | +use Illuminate\Support\Arr; |
3 | 4 | use Illuminate\Support\Str;
|
4 | 5 |
|
5 |
| -return [ |
| 6 | +$config = [ |
6 | 7 |
|
7 | 8 | /*
|
8 | 9 | |--------------------------------------------------------------------------
|
|
108 | 109 | 'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache'),
|
109 | 110 |
|
110 | 111 | ];
|
| 112 | + |
| 113 | +// on fortrabbit: construct credentials from App secrets |
| 114 | +if (env('APP_SECRETS')) { |
| 115 | + $secrets = json_decode(file_get_contents(env('APP_SECRETS')), true); |
| 116 | + if (array_key_exists('MEMCACHE', $secrets)) { |
| 117 | + $servers = [[ |
| 118 | + 'host' => $secrets['MEMCACHE']['HOST1'], |
| 119 | + 'port' => $secrets['MEMCACHE']['PORT1'], |
| 120 | + 'weight' => 100, |
| 121 | + ]]; |
| 122 | + if ($secrets['MEMCACHE']['COUNT'] > 1) { |
| 123 | + $servers[] = [ |
| 124 | + 'host' => $secrets['MEMCACHE']['HOST2'], |
| 125 | + 'port' => $secrets['MEMCACHE']['PORT2'], |
| 126 | + 'weight' => 100, |
| 127 | + ]; |
| 128 | + } |
| 129 | + Arr::set($config, 'stores.memcached.servers', $servers); |
| 130 | + } |
| 131 | +} |
| 132 | + |
| 133 | +if (extension_loaded('memcached')) { |
| 134 | + $timeout_ms = 50; |
| 135 | + $options = [ |
| 136 | + // Assure that dead servers are properly removed and ... |
| 137 | + \Memcached::OPT_REMOVE_FAILED_SERVERS => true, |
| 138 | + |
| 139 | + // ... retried after a short while (here: 2 seconds) |
| 140 | + \Memcached::OPT_RETRY_TIMEOUT => 2, |
| 141 | + |
| 142 | + // KETAMA must be enabled so that replication can be used |
| 143 | + \Memcached::OPT_LIBKETAMA_COMPATIBLE => true, |
| 144 | + |
| 145 | + // Replicate the data, write it to both memcached servers |
| 146 | + \Memcached::OPT_NUMBER_OF_REPLICAS => 1, |
| 147 | + |
| 148 | + // Those values assure that a dead (due to increased latency or |
| 149 | + // really unresponsive) memcached server is dropped fast |
| 150 | + \Memcached::OPT_POLL_TIMEOUT => $timeout_ms, // milliseconds |
| 151 | + \Memcached::OPT_SEND_TIMEOUT => $timeout_ms * 1000, // microseconds |
| 152 | + \Memcached::OPT_RECV_TIMEOUT => $timeout_ms * 1000, // microseconds |
| 153 | + \Memcached::OPT_CONNECT_TIMEOUT => $timeout_ms, // milliseconds |
| 154 | + |
| 155 | + // Further performance tuning |
| 156 | + \Memcached::OPT_NO_BLOCK => true, |
| 157 | + ]; |
| 158 | + Arr::set($config, 'stores.memcached.options', $options); |
| 159 | +} |
| 160 | + |
| 161 | +return $config; |
0 commit comments