Skip to content

Commit 79902c6

Browse files
authored
adds region tags to flex memcache (GoogleCloudPlatform#291)
1 parent 736dac2 commit 79902c6

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

appengine/flexible/memcache/app.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,30 @@
2727
$app['twig.path'] = [ __DIR__ ];
2828
$app['memcached'] = function () {
2929
if (getenv('USE_GAE_MEMCACHE')) {
30-
$addr = getenv('GAE_MEMCACHE_HOST') ?: 'localhost';
30+
$host = getenv('GAE_MEMCACHE_HOST') ?: 'localhost';
3131
$port = getenv('GAE_MEMCACHE_PORT') ?: '11211';
3232
} else {
3333
$server = getenv('MEMCACHE_SERVER') ?: 'localhost:11211';
34-
list($addr, $port) = explode(':', $server);
34+
list($host, $port) = explode(':', $server);
3535
}
3636
$username = getenv('MEMCACHE_USERNAME');
3737
$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';
3843
$memcached = new Memcached;
3944
if ($username && $password) {
4045
$memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
4146
$memcached->setSaslAuthData($username, $password);
4247
}
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");
4550
}
51+
# [END memcached]
4652
return $memcached;
4753
};
48-
# [END memcached]
4954

5055
$app->get('/vars', function () {
5156
$vars = array('MEMCACHE_PORT_11211_TCP_ADDR',
@@ -106,7 +111,6 @@
106111
]);
107112
});
108113

109-
# [START memcached]
110114
$app->get('/memcached/{key}', function (Application $app, $key) {
111115
/** @var Memcached $memcached */
112116
$memcached = $app['memcached'];
@@ -119,6 +123,5 @@
119123
$value = $request->getContent();
120124
return $memcached->set($key, $value, time() + 600); // 10 minutes expiration
121125
});
122-
# [END memcached]
123126

124127
return $app;

0 commit comments

Comments
 (0)