Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

MemCachedClient Class Reference

List of all members.

Public Member Functions

 MemCachedClient ($options=0)
 set_servers ($servers)
 set_debug ($do_debug)
 forget_dead_hosts ()
 disconnect_all ()
 delete ($key, $time=0)
 add ($key, $val, $exptime=0)
 replace ($key, $val, $exptime=0)
 set ($key, $val, $exptime=0)
 get ($key)
 get_multi ($keys)
 incr ($key, $value=1)
 decr ($key, $value=1)
 error ()
 error_string ()
 error_clear ()
 set_compression ($setting=1)
 sock_to_host ($host)
 get_sock ($key)
 _incrdecr ($cmdname, $key, $value)
 _set ($cmdname, $key, $val, $exptime=0)
 _load_items ($sock, &$val, $sock_keys)
 _hashfunc ($num)
 _debug ($text)

Public Attributes

 $host_dead
 $cache_sock
 $debug
 $servers
 $active
 $errno
 $errstr
 $compress = 1
 $comp_active = 1
 $bucket

Constructor & Destructor Documentation

MemCachedClient::MemCachedClient options = 0  ) 
 

Constructor

Creates a new MemCachedClient object Takes one parameter, a array of options. The most important key is $options["servers"], but that can also be set later with the set_servers() method. The servers must be an array of hosts, each of which is either a scalar of the form <10.0.0.10:11211> or an array of the former and an integer weight value. (the default weight if unspecified is 1.) It's recommended that weight values be kept as low as possible, as this module currently allocates memory for bucket distribution proportional to the total host weights. $options["debug"] turns the debugging on if set to true

public

Parameters:
array $option an array of servers and debug status
Returns:
object MemCachedClient the new MemCachedClient object

Definition at line 129 of file MemCachedClient.inc.php.

References $options, and set_servers().


Member Function Documentation

MemCachedClient::_debug text  ) 
 

function that can be overridden to handle debug output by default debug info is print to the screen

private

Parameters:
$text string to output debug info

Definition at line 1147 of file MemCachedClient.inc.php.

References _debug().

Referenced by _debug(), _incrdecr(), _load_items(), _set(), delete(), get(), get_multi(), get_sock(), and sock_to_host().

MemCachedClient::_hashfunc num  ) 
 

creates our hash

private

Parameters:
int $num
Returns:
hash

Definition at line 1133 of file MemCachedClient.inc.php.

References _hashfunc().

Referenced by _hashfunc(), and get_sock().

MemCachedClient::_incrdecr cmdname,
key,
value
 

increments or decrements a numerical value in memcached. this function is called from incr() and decr() ONLY WORKS WITH NUMERIC VALUES Possible errors set are: MC_ERR_NOT_ACTIVE MC_ERR_GET_SOCK MC_ERR_SOCKET_WRITE MC_ERR_SOCKET_READ

private

Parameters:
string $cmdname the command to send, either incr or decr
string $key the key to perform the command on
mixed $value the value to incr or decr the key value by
Returns:
int the new value of the key, FALSE if something went wrong

Definition at line 745 of file MemCachedClient.inc.php.

References $sock, _debug(), _incrdecr(), MC_BUFFER_SZ, MC_ERR_GET_SOCK, MC_ERR_NOT_ACTIVE, MC_ERR_SOCKET_READ, and MC_ERR_SOCKET_WRITE.

Referenced by _incrdecr(), decr(), and incr().

MemCachedClient::_load_items sock,
&$  val,
sock_keys
 

retrieves the value, and returns it unserialized Possible errors set are: MC_ERR_SOCKET_WRITE MC_ERR_SOCKET_READ MC_ERR_GET_KEY MC_ERR_LOADITEM_END MC_ERR_LOADITEM_BYTES

private

Parameters:
resource $sock the socket to connection we are retriving from
array $val reference to the values retrieved
mixed $sock_keys either a string or an array of keys to retrieve
Returns:
array TRUE on success, else FALSE

Definition at line 961 of file MemCachedClient.inc.php.

References $errno, $line, _debug(), _load_items(), MC_BUFFER_SZ, MC_ERR_GET_KEY, MC_ERR_LOADITEM_BYTES, MC_ERR_LOADITEM_END, MC_ERR_SOCKET_READ, and MC_ERR_SOCKET_WRITE.

Referenced by _load_items(), and get_multi().

MemCachedClient::_set cmdname,
key,
val,
exptime = 0
 

sends the command to the server Possible errors set are: MC_ERR_NOT_ACTIVE MC_ERR_GET_SOCK MC_ERR_SOCKET_WRITE MC_ERR_SOCKET_READ MC_ERR_SET

private

Parameters:
string $cmdname the command to send, either incr or decr
string $key the key to perform the command on
mixed $value the value to set the key to
timestamp $exptime expiration time of the key
Returns:
bool TRUE on success, else FALSE

Definition at line 834 of file MemCachedClient.inc.php.

References $errno, $sock, _debug(), _set(), MC_BUFFER_SZ, MC_ERR_GET_SOCK, MC_ERR_NOT_ACTIVE, MC_ERR_SET, MC_ERR_SOCKET_READ, and MC_ERR_SOCKET_WRITE.

Referenced by _set(), add(), replace(), and set().

MemCachedClient::add key,
val,
exptime = 0
 

Like set(), but only stores in memcache if the key doesn't already exist. Possible errors set are: MC_ERR_NOT_ACTIVE MC_ERR_GET_SOCK MC_ERR_SOCKET_WRITE MC_ERR_SOCKET_READ MC_ERR_SET

public

Parameters:
string $key the key to set
mixed $val the value of the key
timestamp $exptime optional, the to to live of the key
Returns:
bool TRUE on success, else FALSE

Definition at line 326 of file MemCachedClient.inc.php.

References _set(), and add().

Referenced by add().

MemCachedClient::decr key,
value = 1
 

Like incr, but decrements. Unlike incr, underflow is checked and new values are capped at 0. If server value is 1, a decrement of 2 returns 0, not -1. ONLY WORKS WITH NUMERIC VALUES Possible errors set are: MC_ERR_NOT_ACTIVE MC_ERR_GET_SOCK MC_ERR_SOCKET_WRITE MC_ERR_SOCKET_READ

public

Parameters:
string $key the keys to increment
int $value the amount to increment the key bye
Returns:
int the new value of the key, else FALSE

Definition at line 524 of file MemCachedClient.inc.php.

References _incrdecr(), and decr().

Referenced by decr().

MemCachedClient::delete key,
time = 0
 

removes the key from the MemCache $time is the amount of time in seconds (or Unix time) until which the client wishes the server to refuse "add" and "replace" commands with this key. For this amount of item, the item is put into a delete queue, which means that it won't possible to retrieve it by the "get" command, but "add" and "replace" command with this key will also fail (the "set" command will succeed, however). After the time passes, the item is finally deleted from server memory. The parameter $time is optional, and, if absent, defaults to 0 (which means that the item will be deleted immediately and further storage commands with this key will succeed). Possible errors set are: MC_ERR_NOT_ACTIVE MC_ERR_GET_SOCK MC_ERR_SOCKET_WRITE MC_ERR_SOCKET_READ MC_ERR_DELETE

public

Parameters:
string $key the key to delete
timestamp $time optional, the amount of time server will refuse commands on key
Returns:
bool TRUE on success, FALSE if key does not exist

Definition at line 221 of file MemCachedClient.inc.php.

References $sock, _debug(), get_sock(), MC_BUFFER_SZ, MC_ERR_DELETE, MC_ERR_GET_SOCK, MC_ERR_NOT_ACTIVE, MC_ERR_SOCKET_READ, and MC_ERR_SOCKET_WRITE.

MemCachedClient::disconnect_all  ) 
 

disconnects from all servers

public

Definition at line 187 of file MemCachedClient.inc.php.

MemCachedClient::error  ) 
 

When a function returns FALSE, an error code is set. This funtion will return the error code. See error_string()

public

Returns:
int the value of the last error code

Definition at line 538 of file MemCachedClient.inc.php.

MemCachedClient::error_clear  ) 
 

Resets the error number and error string

public

Definition at line 562 of file MemCachedClient.inc.php.

MemCachedClient::error_string  ) 
 

Returns a string describing the error set in error() See error()

public

Returns:
int a string describing the error code given

Definition at line 551 of file MemCachedClient.inc.php.

MemCachedClient::forget_dead_hosts  ) 
 

remove all cached hosts that are no longer good

public

Definition at line 176 of file MemCachedClient.inc.php.

MemCachedClient::get key  ) 
 

Retrieves a key from the memcache. Returns the value (automatically unserialized, if necessary) or FALSE if it fails. The $key can optionally be an array, with the first element being the hash value, if you want to avoid making this module calculate a hash value. You may prefer, for example, to keep all of a given user's objects on the same memcache server, so you could use the user's unique id as the hash value. Possible errors set are: MC_ERR_GET_KEY

public

Parameters:
string $key the key to retrieve
Returns:
mixed the value of the key, FALSE on error

Definition at line 393 of file MemCachedClient.inc.php.

References _debug(), get(), get_multi(), and MC_ERR_GET_KEY.

Referenced by get().

MemCachedClient::get_multi keys  ) 
 

just like get(), but takes an array of keys, returns FALSE on error Possible errors set are: MC_ERR_NOT_ACTIVE

public

Parameters:
array $keys the keys to retrieve
Returns:
array the value of each key, FALSE on error

Definition at line 421 of file MemCachedClient.inc.php.

References $sock, _debug(), _load_items(), get_multi(), get_sock(), and MC_ERR_NOT_ACTIVE.

Referenced by get(), and get_multi().

MemCachedClient::get_sock key  ) 
 

retrieves the socket associated with a key Possible errors set are: MC_ERR_NOT_ACTIVE MC_ERR_GET_SOCK

private

Parameters:
string $key the key to retrieve the socket from
Returns:
resource the socket of the connection, else FALSE

Definition at line 672 of file MemCachedClient.inc.php.

References $i, $sock, _debug(), _hashfunc(), get_sock(), MC_ERR_GET_SOCK, and MC_ERR_NOT_ACTIVE.

Referenced by delete(), get_multi(), and get_sock().

MemCachedClient::incr key,
value = 1
 

Sends a command to the server to atomically increment the value for $key by $value, or by 1 if $value is undefined. Returns FALSE if $key doesn't exist on server, otherwise it returns the new value after incrementing. Value should be zero or greater. Overflow on server is not checked. Be aware of values approaching 2**32. See decr. ONLY WORKS WITH NUMERIC VALUES Possible errors set are: MC_ERR_NOT_ACTIVE MC_ERR_GET_SOCK MC_ERR_SOCKET_WRITE MC_ERR_SOCKET_READ

public

Parameters:
string $key the keys to increment
int $value the amount to increment the key bye
Returns:
int the new value of the key, else FALSE

Definition at line 502 of file MemCachedClient.inc.php.

References _incrdecr(), and incr().

Referenced by incr().

MemCachedClient::replace key,
val,
exptime = 0
 

Like set(), but only stores in memcache if the key already exists. returns TRUE on success else FALSE Possible errors set are: MC_ERR_NOT_ACTIVE MC_ERR_GET_SOCK MC_ERR_SOCKET_WRITE MC_ERR_SOCKET_READ MC_ERR_SET

public

Parameters:
string $key the key to set
mixed $val the value of the key
timestamp $exptime optional, the to to live of the key
Returns:
bool TRUE on success, else FALSE

Definition at line 348 of file MemCachedClient.inc.php.

References _set(), and replace().

Referenced by replace().

MemCachedClient::set key,
val,
exptime = 0
 

Unconditionally sets a key to a given value in the memcache. Returns true if it was stored successfully. The $key can optionally be an arrayref, with the first element being the hash value, as described above. Possible errors set are: MC_ERR_NOT_ACTIVE MC_ERR_GET_SOCK MC_ERR_SOCKET_WRITE MC_ERR_SOCKET_READ MC_ERR_SET

public

Parameters:
string $key the key to set
mixed $val the value of the key
timestamp $exptime optional, the to to live of the key
Returns:
bool TRUE on success, else FALSE

Definition at line 372 of file MemCachedClient.inc.php.

References _set(), and set().

Referenced by set().

MemCachedClient::set_compression setting = 1  ) 
 

temporarily sets compression on or off turning it off, and then back on will result in the compression threshold going back to the original setting from $options

Parameters:
int $setting setting of compression (0=off|1=on)

Definition at line 577 of file MemCachedClient.inc.php.

References set_compression().

Referenced by set_compression().

MemCachedClient::set_debug do_debug  ) 
 

if $do_debug is set to true, will print out debugging info, else debug is turned off

public

Parameters:
bool $do_debug set to true to turn debugging on, false to turn off

Definition at line 165 of file MemCachedClient.inc.php.

References set_debug().

Referenced by set_debug().

MemCachedClient::set_servers servers  ) 
 

sets up the list of servers and the ports to connect to takes an array of servers in the same format as in the constructor

public

Parameters:
array $servers array of servers in the format described in the constructor

Definition at line 151 of file MemCachedClient.inc.php.

References $servers, and set_servers().

Referenced by MemCachedClient(), and set_servers().

MemCachedClient::sock_to_host host  ) 
 

connects to a server The $host may either a string int the form of host:port or an array of the former and an integer weight value. (the default weight if unspecified is 1.) See the constructor for details Possible errors set are: MC_ERR_HOST_FORMAT MC_ERR_HOST_DEAD MC_ERR_SOCKET_CONNECT

private

Parameters:
mixed $host either an array or a string
Returns:
resource the socket of the new connection, else FALSE

Definition at line 606 of file MemCachedClient.inc.php.

References $cache_sock, $conn, $sock, _debug(), MC_ERR_HOST_DEAD, MC_ERR_HOST_FORMAT, MC_ERR_SOCKET_CONNECT, and sock_to_host().

Referenced by sock_to_host().


Member Data Documentation

MemCachedClient::$active
 

Definition at line 82 of file MemCachedClient.inc.php.

MemCachedClient::$bucket
 

array that contains parsed out buckets @ var array

Definition at line 108 of file MemCachedClient.inc.php.

MemCachedClient::$cache_sock
 

Definition at line 67 of file MemCachedClient.inc.php.

Referenced by sock_to_host().

MemCachedClient::$comp_active = 1
 

temp flag to turn compression on/off; defaults on @ var int

Definition at line 102 of file MemCachedClient.inc.php.

MemCachedClient::$compress = 1
 

size of val to force compression; 0 turns off; defaults 1 @ var int

Definition at line 97 of file MemCachedClient.inc.php.

MemCachedClient::$debug
 

Definition at line 72 of file MemCachedClient.inc.php.

MemCachedClient::$errno
 

Definition at line 87 of file MemCachedClient.inc.php.

Referenced by _load_items(), and _set().

MemCachedClient::$errstr
 

Definition at line 92 of file MemCachedClient.inc.php.

MemCachedClient::$host_dead
 

Definition at line 62 of file MemCachedClient.inc.php.

MemCachedClient::$servers
 

Definition at line 77 of file MemCachedClient.inc.php.

Referenced by set_servers().


The documentation for this class was generated from the following file:
Generated on Tue Jun 29 23:40:50 2004 for Mediawiki by doxygen 1.3.7