Table of Contents

PHP

We’ve built a small PHP example here: MemCachier PHP sample app.

PHP Memcached Client

We recommended you use the PHP Memcached client to connect with MemCachier. It supports the full protocol and has great performance. We also recommend that you use the composer dependency manager for PHP, although that is up to you.

The php-memcached client is not a pure PHP client but a PECL extention that makes use of libmemcached. You thus need to install php-memcached via your OS package manager. In older operating systems you have to make sure libmemcached has SASL authentication support enabled but for newer operating systems such as Ubuntu 16.04 this is the default. After the installation you need to uncomment ;extension=memcached.so in /etc/php/conf.d/memcached.ini for the extention to work.

First, if using composer, you’ll need to modify your composer.json file to include the module:

Next, ensure that your new requirements are “frozen” to composer.lock by running:

$ composer update

Then, you can connect to MemCachier using the client:

The values for MEMCACHIER_SERVERS, MEMCACHIER_USERNAME, and MEMCACHIER_PASSWORD are listed on your cache overview page. Make sure to add them to your environment.

You should look at the PHP Memcached client documentation for a list of API calls you can make against MemCachier.

PHP Session Support

You can configure PHP to store sessions in MemCachier as follows.

First, start by configuring an appropriate .user.ini in your document root. It should contain the following:

In your code you should then be able to run:

Alternative PHP Client – MemcacheSASL

This is not our recommended client for using MemCachier from PHP. We recommend the php memcached client. However, it is an easier client to use as it’s a pure PHP implementation while the recommended php client requires a C extension to be installed with SASL support. It doesn’t support multiple proxy servers like the memcached client but is otherwise quite good.

You should first install the PHPMemcacheSASL client. You can either grab the code directly or use composer for package management. We suggest composer.

First, if using composer, you’ll need to modify your composer.json file to include the module:

Then, you can connect to MemCachier using the client:

The values for MEMCACHIER_SERVERS, MEMCACHIER_USERNAME, and MEMCACHIER_PASSWORD are listed on your cache overview page. Make sure to add them to your environment.