Skip to main content
This article describes how to use memcached on the following hosting packages:
  • Managed VPS
  • Managed Dedicated server
  • Turbo shared and reseller hosting accounts
Memcached is an open-source memory object caching system that web sites can use to help accelerate page load times. Memcached caches in RAM frequently accessed data, such as the results of API calls, database calls, and more. Memcached can significantly help improve site performance.

Managed VPS and Dedicated servers

Before you can use memcached on a managed VPS or Dedicated server, we must install it for you. To do this, please open a support ticket at https://my.hosting.com and request memcached for your system.

Connection parameters

After memcached is installed, you can connect to it using the following parameters:
  • Hostname: localhost
    👍 Tip Alternatively, you can use the IP address 127.0.0.1.
  • Port: 11211

Diagnostics

To verify memcached is running, you can use the memcached-tool program or usetelnet to connect to memcached directly. For example, the following commands demonstrate how to usememcached-tool to display general statistics for memcached, and then dump all of its stored key-value pairs:
Alternatively, you can usetelnet to connect directly to the running memcached instance. To do this, type the following command:
To display general statistics for memcached, type stats. To exit, type quit.

Code sample

The following PHP code demonstrates how to connect to memcached and store a key-value pair in the cache:
In this example, we store an object value ( $tmp ) that contains a string value and a random number between 0 and 1000 in the testkey key. The key-value pair expires from the cache after 10 seconds. For more information about how to use PHP with memcached, please visit https://secure.php.net/manual/en/book.memcached.php.

Turbo shared and reseller accounts

To connect to memcached on a Turbo Velocity or Turbo Nitro Web Hosting account, use the following Unix socket path. Replace username with your own account username: /opt/memcached/run/username/memcached-1.sock To verify that the memcached socket is active for your account, type the following command. Replace username with your own account username:
If you receive a No such file or directory error message, then the socket has not been activated for your account yet. To do this, type the following command:
The server checks for this file every five minutes, and starts the memcached process for the account if it does not already exist. After five minutes, run the ls command above again, and you should see the memcached-1.sock file in the directory listing.
ImportantBefore you try to use memcached with PHP on your account, you should also make sure the correct PHP extension is enabled. To do this, follow these steps:
  1. Log in to cPanel.
  2. In the Software section of the cPanel home screen, click Select PHP Version.
  3. In the list of PHP extensions, confirm that the memcached check box is selected. (If you do not see a list of PHP extensions, click Switch To PHP Extensions.) Note that there is a memcache extension and a memcached extension—you want to use the memcached extension.

Code sample

The following PHP code demonstrates how to connect to memcached and store a key-value pair in the cache.
ImportantIf you run this code, remember to replace username with your own account username.
In this example, we store an object value ( $tmp ) that contains a string value and a random number between 0 and 1000 in the testkey key. The key-value pair expires from the cache after 10 seconds. For more information about how to use PHP with memcached, please visit https://secure.php.net/manual/en/book.memcached.php.

More information