Class MemcacheManager

Description

Begin Document

Located in /classes/class_MemcacheManager.php (line 35)


	
			
Method Summary
static void _failure (string $host, int $port)
MemcacheManager __construct ()
void add (string $key, string $var, [int $expire = 0], [bool $json = false], [bool $encrypt = false], [bool $zlib = false])
void addserver (string $host, int $port)
void decrement (string $key, [int $value = 1])
string decrypt (string $string)
void delete (string $key, [int $timeout = 0])
string encrypt (string $string)
void flushmc ()
void get (string $keys, [bool $json = false], [ $decrypt = false], [bool $zlib = false], bool $encrypt)
void increment (string $key, [int $value = 1])
string pbkdf2 (string $p, string $s, int $c, int $kl, [string $a = 'sha256'])
void replace (string $key, string $var, [int $expire = 0], [bool $json = false], [bool $encrypt = false], [bool $zlib = false])
string report ()
void set (string $key, string $var, [int $expire = 0], [bool $json = false], [bool $encrypt = false], [bool $zlib = false])
array statistics ()
array status (string $host, int $port)
Methods
static method _failure (line 115)

Callback Handler for failed connection

  • author: Peter Schmalfeldt
  • version: 1.0
static void _failure (string $host, int $port)
  • string $host: Point to the host where memcached is listening for connections. This parameter may also specify other transports like unix:///path/to/memcached.sock to use UNIX domain sockets, in this case port must also be set to 0.
  • int $port: Point to the port where memcached is listening for connections. This parameter is optional and its default value is 11211. Set this parameter to 0 when using UNIX domain sockets.
Constructor __construct (line 98)

Constructor

Create Memcache Manager

  1.  <?php
  2.  $mc new MemcacheManager();
  3.  $mc->addserver('localhost'11211);
  4.  
  5.  $data array(
  6.      'username'=>'memcachelover',
  7.         'email'=>'me@myemail.com',
  8.            'displayname'=>'Memcache Lover',
  9.            'location'=>array(
  10.              'country'=>'USA',
  11.              'state'=>'Oregon',
  12.              'city'=>'Portland'
  13.            )
  14.  );
  15.  
  16.  $mc->add('memcachelover'$datatruetruetrue);    // adds the key with JSON encoding, encryption and compression
  17.  echo $mc->get('memcachelover'falsefalsetrue);    // would echo the uncompressed, but still encrypted key
  18.  echo $mc->get('memcachelover'falsetruetrue);    // would echo the uncompressed, decrypted JSON formatted string
  19.  print_r($mc->get('memcachelover',truetruetrue));    // would print the uncompressed, decrypted array
  20.  print_r($mc->statistics());                            // this would print the array of usage stats for all servers
  21.  echo $mc->report();                                    // this would print our custom report
  22.  $mc->flushmc();                                        // this would fluch all connected servers
  23.  $mc->close();                                        // this would close all connections
  24.  ?>

  • access: public
MemcacheManager __construct ()
add (line 231)

Stores variable $var with $key ONLY if such key doesn't exist at the server yet.

  1.  <?php
  2.  $mc new MemcacheManager();
  3.  $mc->addserver('localhost'11211);
  4.  $mc->add('mykey1'$myarray130truetruetrue);
  5.  $mc->add('mykey2'$myarray230truetrue);
  6.  $mc->add('mykey3'$myarray330true);
  7.  $mc->add('mykey4'$myarray430);
  8.  $mc->add('mykey5'$myarray5);
  9.  ?>

  • access: public
void add (string $key, string $var, [int $expire = 0], [bool $json = false], [bool $encrypt = false], [bool $zlib = false])
  • string $key: The key that will be associated with the item
  • string $var: The variable to store. Strings and integers are stored as is, other types are stored serialized.
  • int $expire: Expiration time of the item. If it's equal to zero, the item will never expire. You can also use Unix timestamp or a number of seconds starting from current time, but in the latter case the number of seconds may not exceed 2592000 (30 days).
  • bool $json: Whether to encode using JSON
  • bool $encrypt: Whether to encrypt string
  • bool $zlib: Use MEMCACHE_COMPRESSED to store the item compressed (uses zlib).
addserver (line 134)

Add a memcached server to connection pool

  1.  <?php
  2.  $mc new MemcacheManager();
  3.  $mc->addserver('localhost'11211);
  4.  ?>

  • access: public
void addserver (string $host, int $port)
  • string $host: Point to the host where memcached is listening for connections. This parameter may also specify other transports like unix:///path/to/memcached.sock to use UNIX domain sockets, in this case port must also be set to 0.
  • int $port: Point to the port where memcached is listening for connections. This parameter is optional and its default value is 11211. Set this parameter to 0 when using UNIX domain sockets.
decrement (line 394)

Decrement item's value

  1.  <?php
  2.  $mc new MemcacheManager();
  3.  $mc->addserver('localhost'11211);
  4.  $mc->decrement('mykey1'5);
  5.  $mc->decrement('mykey2');
  6.  ?>

  • access: public
void decrement (string $key, [int $value = 1])
  • string $key: Key of the item do decrement.
  • int $value: Decrement the item by value . Optional and defaults to 1.
decrypt (line 704)

Decrypt String with Key

The function decryptString()

  • return: Decrypted String
  • author: Peter Schmalfeldt
  • version: 1.0
  • access: public
string decrypt (string $string)
  • string $string: String to Decrypt
delete (line 347)

Delete item from the server

  1.  <?php
  2.  $mc new MemcacheManager();
  3.  $mc->addserver('localhost'11211);
  4.  $mc->delete('mykey1'30);
  5.  $mc->delete('mykey2');
  6.  ?>

  • access: public
void delete (string $key, [int $timeout = 0])
  • string $key: The key associated with the item to delete.
  • int $timeout: Execution time of the item. If it's equal to zero, the item will be deleted right away whereas if you set it to 30, the item will be deleted in 30 seconds.
encrypt (line 734)

Encrypt String with Key

The function encryptString()

  • return: Encoded String
  • author: Peter Schmalfeldt
  • version: 1.0
  • access: public
string encrypt (string $string)
  • string $string: String to Encrypt
flushmc (line 202)

Immediately invalidates all existing items but doesn't actually free any resources, it only marks all the items as expired, so occupied memory will be overwritten by new items.

Please note that after flushing, you have to wait about a second to be able to write to Memcached again. If you don't, your data is not saved.

  1.  <?php
  2.  $mc new MemcacheManager();
  3.  $mc->addserver('localhost'11211);
  4.  $mc->flushmc();
  5.  ?>

  • access: public
void flushmc ()
get (line 321)

Retrieve item from the server

  1.  <?php
  2.  $mc new MemcacheManager();
  3.  $mc->addserver('localhost'11211);
  4.  echo $mc->get('mykey1'truetruetrue);
  5.  echo $mc->get('mykey2'truetrue);
  6.  echo $mc->get('mykey3'true);
  7.  echo $mc->get('mykey4');
  8.  ?>

  • access: public
void get (string $keys, [bool $json = false], [ $decrypt = false], [bool $zlib = false], bool $encrypt)
  • string $keys: The key or array of keys to fetch
  • bool $json: Whether to decode using JSON
  • bool $encrypt: Whether to decrypt string
  • bool $zlib: Use MEMCACHE_COMPRESSED to store the item compressed (uses zlib).
  • $decrypt
increment (line 373)

Increment item's value

  1.  <?php
  2.  $mc new MemcacheManager();
  3.  $mc->addserver('localhost'11211);
  4.  $mc->increment('mykey1'5);
  5.  $mc->increment('mykey2');
  6.  ?>

  • access: public
void increment (string $key, [int $value = 1])
  • string $key: Key of the item to increment
  • int $value: Increment the item by value . Optional and defaults to 1.
pbkdf2 (line 761)

PBKDF2 Implementation (as described in RFC 2898);

  • return: derived key
  • access: public
string pbkdf2 (string $p, string $s, int $c, int $kl, [string $a = 'sha256'])
  • string $p: Password
  • string $s: Salt
  • int $c: Iteration count (use 1000 or higher)
  • int $kl: Derived key length
  • string $a: Hash algorithm
replace (line 293)

Should be used to replace value of existing item with key

  1.  <?php
  2.  $mc new MemcacheManager();
  3.  $mc->addserver('localhost'11211);
  4.  $mc->replace('mykey1'$myarray130truetruetrue);
  5.  $mc->replace('mykey2'$myarray230truetrue);
  6.  $mc->replace('mykey3'$myarray330true);
  7.  $mc->replace('mykey4'$myarray430);
  8.  $mc->replace('mykey5'$myarray5);
  9.  ?>

  • access: public
void replace (string $key, string $var, [int $expire = 0], [bool $json = false], [bool $encrypt = false], [bool $zlib = false])
  • string $key: The key that will be associated with the item
  • string $var: The variable to store. Strings and integers are stored as is, other types are stored serialized.
  • int $expire: Expiration time of the item. If it's equal to zero, the item will never expire. You can also use Unix timestamp or a number of seconds starting from current time, but in the latter case the number of seconds may not exceed 2592000 (30 days).
  • bool $json: Whether to encode using JSON
  • bool $encrypt: Whether to encrypt string
  • bool $zlib: Use MEMCACHE_COMPRESSED to store the item compressed (uses zlib).
report (line 413)

Get statistics from all servers in pool and generate custom report

  1.  <?php
  2.  $mc new MemcacheManager();
  3.  $mc->addserver('localhost'11211);
  4.  echo $mc->report();
  5.  ?>

  • return: HTML Table of statistics.
  • access: public
string report ()
set (line 262)

Stores an item var with key on the memcached server

  1.  <?php
  2.  $mc new MemcacheManager();
  3.  $mc->addserver('localhost'11211);
  4.  $mc->set('mykey1'$myarray130truetruetrue);
  5.  $mc->set('mykey2'$myarray230truetrue);
  6.  $mc->set('mykey3'$myarray330true);
  7.  $mc->set('mykey4'$myarray430);
  8.  $mc->set('mykey5'$myarray5);
  9.  ?>

  • access: public
void set (string $key, string $var, [int $expire = 0], [bool $json = false], [bool $encrypt = false], [bool $zlib = false])
  • string $key: The key that will be associated with the item
  • string $var: The variable to store. Strings and integers are stored as is, other types are stored serialized.
  • int $expire: Expiration time of the item. If it's equal to zero, the item will never expire. You can also use Unix timestamp or a number of seconds starting from current time, but in the latter case the number of seconds may not exceed 2592000 (30 days).
  • bool $json: Whether to encode using JSON
  • bool $encrypt: Whether to encrypt string
  • bool $zlib: Use MEMCACHE_COMPRESSED to store the item compressed (uses zlib).
statistics (line 183)

Get statistics from all servers in pool

  1.  <?php
  2.  $mc new MemcacheManager();
  3.  $mc->addserver('localhost'11211);
  4.  print_r($mc->statistics());
  5.  ?>

  • return: Returns a two-dimensional associative array of server statistics or FALSE on failure.
  • access: public
array statistics ()
status (line 164)

Returns a the servers online/offline status

  1.  <?php
  2.  $mc new MemcacheManager();
  3.  $mc->addserver('localhost'11211);
  4.  if($mc->status()>0echo 'Connection Established';
  5.  ?>

  • return: Returns 0 if server is failed, non-zero otherwise
  • access: public
array status (string $host, int $port)
  • string $host: Point to the host where memcached is listening for connections. This parameter may also specify other transports like unix:///path/to/memcached.sock to use UNIX domain sockets, in this case port must also be set to 0.
  • int $port: Point to the port where memcached is listening for connections. This parameter is optional and its default value is 11211. Set this parameter to 0 when using UNIX domain sockets.

Documentation generated on Fri, 13 Nov 2009 06:22:36 -0600 by phpDocumentor 1.4.3