Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion appengine/flexible/memcache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ $ composer install
**Prerequisites**

- Install the [Google Cloud SDK](https://developers.google.com/cloud/sdk/).
- Set up memcache using [Redis Labs Memcache Cloud][redis labs memcache].
- edit `app.yaml` and update the environment variables for your Memcache
instance.

**Deploy with gcloud**

Expand All @@ -33,4 +36,6 @@ $ curl http://{YOUR_PROJECT_ID}.appspot.com/memcached/a
$ curl http://{YOUR_PROJECT_ID}.appspot.com/memcached/a -T hello.txt
$ curl http://{YOUR_PROJECT_ID}.appspot.com/memcached/a
hello
```
```

[redis labs memcache]: https://cloud.google.com/appengine/docs/flexible/python/using-redislabs-memcache
15 changes: 13 additions & 2 deletions appengine/flexible/memcache/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,20 @@
$app->register(new TwigServiceProvider());
$app['twig.path'] = [ __DIR__ ];
$app['memcached'] = function () {
$addr = getenv('MEMCACHE_PORT_11211_TCP_ADDR');
$port = (int) getenv('MEMCACHE_PORT_11211_TCP_PORT');
if (getenv('USE_GAE_MEMCACHE')) {
$addr = getenv('GAE_MEMCACHE_HOST') ?: 'localhost';
$port = getenv('GAE_MEMCACHE_PORT') ?: '11211';
} else {
$server = getenv('MEMCACHE_SERVER') ?: 'localhost:11211';
list($addr, $port) = explode(':', $server);
}
$username = getenv('MEMCACHE_USERNAME');
$password = getenv('MEMCACHE_PASSWORD');
$memcached = new Memcached;
if ($username && $password) {
$memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
$memcached->setSaslAuthData($username, $password);
}
if (!$memcached->addServer($addr, $port)) {
throw new Exception("Failed to add server $addr:$port");
}
Expand Down
14 changes: 13 additions & 1 deletion appengine/flexible/memcache/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@ runtime: php
vm: true

runtime_config:
document_root: web
document_root: web

# [START env_variables]
env_variables:
# If you are using the App Engine Memcache service (currently in alpha),
# uncomment this section and comment out the other Memcache variables.
# USE_GAE_MEMCACHE: 1
MEMCACHE_SERVER: your-memcache-server
# If you are using a Memcached server with SASL authentiation enabled,
# fill in these values with your username and password.
MEMCACHE_USERNAME: ""
MEMCACHE_PASSWORD: ""
# [END env_variables]
1 change: 1 addition & 0 deletions appengine/flexible/memcache/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"require-dev": {
"gecko-packages/gecko-memcache-mock": "^2.0",
"google/cloud-tools": "<=1.0",
"paragonie/random_compat": "^2.0",
"guzzlehttp/guzzle": "^6.2",
"monolog/monolog": "^1.19",
"phpunit/phpunit": "~4"
Expand Down
Loading