I am trying to test using App Engine's Memcache with our servers running under Compute Engine. Currently we just have a couple VM instances which run Memcache where we call:
$memcache->addServer('memcache', 11211);
to reference each server. Looking at Google's sample code, it doesn't mention anything about what server we should call. I tried to test the below code from their document but it errors on creating the object. I understand that I might have to include a class, but it didn't mention anything in the document or what server to call. Can anyone help?
<?php
header('Content-Type: text/plain');
echo "Setting Value\n";
$memcache = new Memcached;
echo "Get who value<br>";
$who = $memcache->get('who');
echo 'Previously incremented by ' . $who . "\n";
$memcache->set('who', 'PHP');
$count = $memcache->increment('count', 1, 0);
echo 'Count incremented by PHP = ' . $count . "\n";
To enable the PHP memcache extensions, build PHP using the --enable-memcache option to configure when building from source. On Debian-based distributions, use the php-memcache package. To set global runtime configuration options, specify the configuration option values within your php. ini file.
Shared memcache is the free default for App Engine applications. It provides cache capacity on a best-effort basis and is subject to the overall demand of all the App Engine applications using the shared memcache service. Dedicated memcache provides a fixed cache capacity assigned exclusively to your application.
Google App Engine provides a hosted Memcache service while Google Compute Engine does not.
On App Engine, the connection to the server is made automatically for the app running on App Engine, which means you don't need to specify a host/port in the app.
On Compute Engine, however, if you want to use memcache, you will need to run your own memcached server, either in the same or different VM as your application, and specify its host/port in your PHP client.
PHP provides two classes to connect to memcached:
Each provides a method to specify server(s) to connect to, e.g.,
Memcache::addServer
Memcached::addServer
but it's still up to you to run these memcached servers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With