You can test your Memcached installation with a client like php-memcached-sasl, a simple Memcached client written in PHP. You can use this or any other client since the Bitnami Multi-tier solution for Memcached doesn’t require SASL authentication method by default.
NOTE: The Bitnami Memcached Stack does not include PHP. To use the example script below, you must have PHP installed on your machine. You can install PHP in your machine (refer to PHP Official Documentation for more information regarding how to install it), or you can launch a new server with PHP using the Bitnami LAMP Stack.
Download the php-memcached-sasl client from this link and begin by extracting the contents of the downloaded archive. The archive includes a simple script named example.php.
$ curl -o php-memcache-sasl-master.zip 'https://codeload.github.com/hull-graveyard/php-memcache-sasl/zip/master' $ unzip php-memcache-sasl-master.zip $ cd php-memcache-sasl-master $ nano example.php
The script begins by including the necessary PHP class and instantiating an object of the class:
include('MemcacheSASL.php'); $m = new MemcacheSASL;
Now, you have to connect to Memcached. In order to connect to the Memcached, you have two options:
IMPORTANT: Making this application’s network ports public is a significant security risk. You are strongly advised to only allow access to those ports from trusted networks. If, for development purposes, you need to access from outside of a trusted network, please do not allow access to those ports via a public IP address. Instead, use a secure channel such as a VPN or an SSH tunnel. Follow these instructions to remotely connect safely and reliably.
Once you have an active SSH tunnel or you opened the port for remote access, configure the client object by defining the Memcached server host and port, and SASL configuration. Replace these values in the script with actual values for your server:
Use the values below for Server host and port when:
Accessing through an SSH tunnel:
Accessing opening ports:
You can now use the object’s add() and get() methods to add or remove values from the cache. In this example, the add() method stores the value ‘12345’ using the key ‘test’. The key can then be used with the get() method to retrieve the original value whenever needed.
var_dump($m->add('test', '12345')); $var = $m->get('test');
Here’s the complete code for the modified example.php script:
<?php include('MemcacheSASL.php'); $m = new MemcacheSASL; $m->addServer('host', 'port'); // replace these values var_dump($m->add('test', '12345')); $var = $m->get('test'); print "$var"; ?>
Save the file and run it:
$ php example.php
The script will connect to your Memcached server, save the value to the key ‘test’, then retrieve and display it.