Difference between revisions of "Using Memcached For Caching"

From TMM Wiki
Jump to navigationJump to search
Line 7: Line 7:
 
To use memcached, you must first install and configure the PHP extension "memcached" on your server, which can be done by your server host.
 
To use memcached, you must first install and configure the PHP extension "memcached" on your server, which can be done by your server host.
  
'''NOTE''': PHP has two different functions-- memcache and memcache'''d'''. [[NATS]] only supports the memcached extension, so make sure you install memcache'''d''' and not memcache.
+
'''NOTE''': PHP has two different functions-- memcache and memcache'''d'''. [[NATS]] only supports the memcache'''d''' extension, so make sure you install memcache'''d''' and not memcache.
  
Using the Memcached extension will allow PHP to to force your server to store a surfer's session information in memcached for faster recall, as opposed to storing your session information in the database.
+
Using the Memcached extension will allow PHP to force your server to store a surfer's session information in memcached (memory) for faster recall, as opposed to storing your session information in the database (storage).
  
 
== Using Memcached in NATS ==
 
== Using Memcached in NATS ==
Line 18: Line 18:
 
* '''MEMCACHE_EXPIRE''' - The number of seconds before your cache data is reset.
 
* '''MEMCACHE_EXPIRE''' - The number of seconds before your cache data is reset.
  
You can pass memcache_server as one IP, or an array of IPs, ports, and priority as can be seen in the following example code:
+
You can pass memcache_server as one IP, or an array of IPs, ports, and priority as can be seen in the following example codes:
  
  

Revision as of 12:05, 6 July 2010

NATS 4
NATS Setup
Post-Installation Steps
Apache Configuration
MySQL Settings
Creating Admin Accounts
Multiple Server Setup
Using Memcached for Caching
File Upload Setup
Link Domain
HTTPS Setup
NATS4 Files and Directories
NATS4 Go Live Checklist
NATS3 to NATS4 Going Live Checklist
Moving NATS4
Members Admin
The Members Admin
View Member Details
Add Member
MySQL Auth
Mod Authn DB
Multisite Access
Member Logging
Member Password Retrieval
OpenID Connect
Mod Auth OpenIDC
ID Numbers

NATS4 now offers a method to use the new PHP class Memcached for caching certain integrated database functions. These include functions such as nats_get_identid and nats_identid_details. Using Memcached allows you to temporarily store data and access information in RAM of your server as opposed to the hard disk -- this will speed up your database.

To use memcached, you must first install and configure the PHP extension "memcached" on your server, which can be done by your server host.

NOTE: PHP has two different functions-- memcache and memcached. NATS only supports the memcached extension, so make sure you install memcached and not memcache.

Using the Memcached extension will allow PHP to force your server to store a surfer's session information in memcached (memory) for faster recall, as opposed to storing your session information in the database (storage).

Using Memcached in NATS

To use Memcached in NATS, you must set your config variables, as well as the expire variable:

  • MEMCACHE_SERVER - What server IP memcached is configured on.
  • MEMCACHE_PORT - The port that memcached can be accessed on.
  • MEMCACHE_EXPIRE - The number of seconds before your cache data is reset.

You can pass memcache_server as one IP, or an array of IPs, ports, and priority as can be seen in the following example codes:


Passing memcache_server as one IP:

$config['MEMCACHE_SERVER'] = '127.0.0.1';
$config['MEMCACHE_PORT'] = 11211;


Passing memcache_server as an array of IPs, ports, and priority:

$config['MEMCACHE_SERVER'] = Array(
array('127.0.0.1', 11211, 33),
array('127.0.0.2', 11211, 67)
)


In the above example, you can see the IP (127.0.0.1), the port (11211), and the priority (33) of the array. Priority here works similarly to cascade weights; the higher the weight, the more likely that server is to be chosen. Once you have defined your config variables, you must also define MEMCACHE_EXPIRE, which can be seen in the following example code:


$config['MEMCACHE_EXPIRE'] = 86400;


In the above example, your memcached session would expire in 86,400 seconds.

NATS is currently configured to cache queries that are run doing the surfer process that return the same results, such as selecting a site ID for your shortname, and selecting a return URL for a tour. It can also cache core functionalities in NATS that return the same data.

In the future, this feature will be built up over time to encompass more aspects of NATS.

NOTE: You must be on NATS 4.0.75.1 in order to use memcached in NATS.