|
27 | 27 | $app['twig.path'] = [ __DIR__ ];
|
28 | 28 | $app['memcached'] = function () {
|
29 | 29 | if (getenv('USE_GAE_MEMCACHE')) {
|
30 |
| - $addr = getenv('GAE_MEMCACHE_HOST') ?: 'localhost'; |
| 30 | + $host = getenv('GAE_MEMCACHE_HOST') ?: 'localhost'; |
31 | 31 | $port = getenv('GAE_MEMCACHE_PORT') ?: '11211';
|
32 | 32 | } else {
|
33 | 33 | $server = getenv('MEMCACHE_SERVER') ?: 'localhost:11211';
|
34 |
| - list($addr, $port) = explode(':', $server); |
| 34 | + list($host, $port) = explode(':', $server); |
35 | 35 | }
|
36 | 36 | $username = getenv('MEMCACHE_USERNAME');
|
37 | 37 | $password = getenv('MEMCACHE_PASSWORD');
|
| 38 | + # [START memcached] |
| 39 | + // $host = 'YOUR_MEMCACHE_HOST'; |
| 40 | + // $port = 'YOUR_MEMCACHE_PORT'; |
| 41 | + // $username = 'OPTIONAL_MEMCACHE_USERNAME'; |
| 42 | + // $password = 'OPTIONAL_MEMCACHE_PASSWORD'; |
38 | 43 | $memcached = new Memcached;
|
39 | 44 | if ($username && $password) {
|
40 | 45 | $memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
|
41 | 46 | $memcached->setSaslAuthData($username, $password);
|
42 | 47 | }
|
43 |
| - if (!$memcached->addServer($addr, $port)) { |
44 |
| - throw new Exception("Failed to add server $addr:$port"); |
| 48 | + if (!$memcached->addServer($host, $port)) { |
| 49 | + throw new Exception("Failed to add server $host:$port"); |
45 | 50 | }
|
| 51 | + # [END memcached] |
46 | 52 | return $memcached;
|
47 | 53 | };
|
48 |
| -# [END memcached] |
49 | 54 |
|
50 | 55 | $app->get('/vars', function () {
|
51 | 56 | $vars = array('MEMCACHE_PORT_11211_TCP_ADDR',
|
|
106 | 111 | ]);
|
107 | 112 | });
|
108 | 113 |
|
109 |
| -# [START memcached] |
110 | 114 | $app->get('/memcached/{key}', function (Application $app, $key) {
|
111 | 115 | /** @var Memcached $memcached */
|
112 | 116 | $memcached = $app['memcached'];
|
|
119 | 123 | $value = $request->getContent();
|
120 | 124 | return $memcached->set($key, $value, time() + 600); // 10 minutes expiration
|
121 | 125 | });
|
122 |
| -# [END memcached] |
123 | 126 |
|
124 | 127 | return $app;
|
0 commit comments