Servers & Services > Memcached
Memcached is an in-memory key-value store for small chunks of arbitrary data. The Memcached and igbinary PHP extensions are added to your PHP configuration when Memcached is added to your GroupStart servers.
Note: The Memcached PHP extension will not be enabled if the GroupStart option is not checked!
When the Memcached extension is enabled, the following section is included in the phpInfo (Webstart > Tools -> phpInfo in the MAMP PRO interface) which shows you the configuration options.
In the upper right corner of this screen you will find information about the version of the Memcached server and the port used.
-
Include Memcached server in GroupStart
Select this checkbox if you want the Memcached server to start and stop automatically when the Start/Stop button in the toolbar is clicked. The Memcached PHP extension is automatically included when this option is enabled. -
Maximum memory usage
Here you can set the size of the maximum available memory. -
Clear Cache
Click this button to clear the cache. -
Statistics
Clicking this button will display statistics. -
Allow network access to Memcached
Select this checkbox if you want to access the Memcached server over the network. Otherwise, you will not be able to access your Memcached server over the network, even from other locally installed programs. -
Log level
Select how much information should be written to the Memcached log. The following options are available:Name Content Verbose errors, warnings Very Verbose errors, warnings, client commands, responses Extremely Verbose errors, warnings, client commands, responses, internal transitions -
Path to Memcached log file
The path to your Memcached log file. This log file is located at “/Applications/MAMP/logs/memcached_error.log”.
Sidebar
Right-clicking on the Memcached entry in the sidebar opens a context menu with several options.
-
Add to GroupStart / Remove from GroupStart.
These options allow you to add or remove Memcached from the GroupStart. If Memcached is added to the GroupStart, it will be automatically started and stopped when you click the Start/Stop button in the toolbar. -
If Memcached is running
- Restart server
This option allows you to restart Memcached individually.
- Restart server
-
If Memcached is not running
- Force Quit Server
If Memcached is running but MAMP PRO is unable to detect the correct status, the application may not be able to (re)start or stop the server instances. Calling this function will help MAMP PRO regain control of Memcached.
- Force Quit Server
Examples
The following example shows how to connect to the Memcached server using PHP. The connection can be made either through a UNIX socket or through the network. In the following example, a value (“MAMP PRO”) is stored in the cache and then retrieved.
PHP (Connect using an UNIX socket)
<?php
/*
Note:
The checkbox "Include Memcached server in GroupStart" must be activated under "Memcached".
*/
$memcached = new Memcached();
// Socket
$memcached->addServer('/Applications/MAMP/tmp/memcached.sock', 0);
$version = $memcached->getVersion();
echo '<pre>';
print_r($version);
echo '</pre>';
$memcached->set('Key1', 'MAMP PRO');
$result = $memcached->get('Key1');
echo $result;
?>
PHP (Connect via network)
<?php
/*
Note:
The "Include Memcached server in GroupStart" checkbox under "Memcached" must be selected.
*/
$memcached = new Memcached();
// Network
// "Allow network access to Memcached" must be activated
// You can set the host to either "127.0.0.1" or "localhost".
$memcached->addServer('127.0.0.1', 11211);
$version = $memcached->getVersion();
echo '<pre>';
print_r($version);
echo '</pre>';
$memcached->set('Key1', 'MAMP PRO');
$result = $memcached->get('Key1');
echo $result;
?>