Inherited by MemCachedClientforWiki.
Public Member Functions | |
__construct ($args) | |
Memcache initializer. | |
add ($key, $val, $exp=0) | |
Adds a key/value to the memcache server if one isn't already set with that key. | |
decr ($key, $amt=1) | |
Decriment a value stored on the memcache server. | |
delete ($key, $time=0) | |
Deletes a key from the server, optionally after $time. | |
disconnect_all () | |
Disconnects all connected sockets. | |
enable_compress ($enable) | |
Enable / Disable compression. | |
forget_dead_hosts () | |
Forget about all of the dead hosts. | |
get ($key) | |
Retrieves the value associated with the key from the memcache server. | |
get_multi ($keys) | |
Get multiple keys from the server(s). | |
incr ($key, $amt=1) | |
Increments $key (optionally) by $amt. | |
replace ($key, $value, $exp=0) | |
Overwrites an existing value for key; only works if key is already set. | |
run_command ($sock, $cmd) | |
Passes through $cmd to the memcache server connected by $sock; returns output as an array (null array if no output). | |
set ($key, $value, $exp=0) | |
Unconditionally sets a key to a given value in the memcache. | |
set_compress_threshold ($thresh) | |
Sets the compression threshold. | |
set_debug ($dbg) | |
Sets the debug flag. | |
set_servers ($list) | |
Sets the server list to distribute key gets and puts between. | |
set_timeout ($seconds, $microseconds) | |
Sets the timeout for new connections. | |
_close_sock ($sock) | |
Close the specified socket. | |
_connect_sock (&$sock, $host) | |
Connects $sock to $host, timing out after $timeout. | |
_dead_sock ($sock) | |
Marks a host as dead until 30-40 seconds in the future. | |
_dead_host ($host) | |
get_sock ($key) | |
get_sock | |
_hashfunc ($key) | |
Creates a hash integer based on the $key. | |
_incrdecr ($cmd, $key, $amt=1) | |
Perform increment/decriment on $key. | |
_load_items ($sock, &$ret) | |
Load items into $ret from $sock. | |
_set ($cmd, $key, $val, $exp) | |
Performs the requested storage operation to the memcache server. | |
sock_to_host ($host) | |
Returns the socket for the host. | |
_debugprint ($str) | |
_safe_fwrite ($f, $buf, $len=false) | |
Write to a stream, timing out after the correct amount of time. | |
_flush_read_buffer ($f) | |
Flush the read buffer of a stream. | |
Public Attributes | |
const | SERIALIZED = 1 |
Flag: indicates data is serialized. | |
const | COMPRESSED = 2 |
Flag: indicates data is compressed. | |
const | COMPRESSION_SAVINGS = 0.20 |
Minimum savings to store data compressed. | |
$stats | |
$_cache_sock | |
$_debug | |
$_host_dead | |
$_have_zlib | |
$_compress_enable | |
$_compress_threshold | |
$_persistant | |
$_single_sock | |
$_servers | |
$_buckets | |
$_bucketcount | |
$_active | |
$_timeout_seconds | |
$_timeout_microseconds | |
$_connect_timeout | |
Connect timeout in seconds. | |
$_connect_attempts | |
Number of connection attempts for each server. |
More information is available at http://www.danga.com/memcached/
Usage example:
require_once 'memcached.php';
$mc = new MWMemcached(array( 'servers' => array('127.0.0.1:10000', array('192.0.0.1:10010', 2), '127.0.0.1:10020'), 'debug' => false, 'compress_threshold' => 10240, 'persistant' => true));
$mc->add('key', array('some', 'array')); $mc->replace('key', 'some random string'); $val = $mc->get('key');
Definition at line 73 of file memcached-client.php.
MWMemcached::__construct | ( | $ | args | ) |
Memcache initializer.
array | $args Associative array of settings |
Definition at line 246 of file memcached-client.php.
References $wgMemCachedTimeout, and set_servers().
MWMemcached::_close_sock | ( | $ | sock | ) |
Close the specified socket.
string | $sock Socket to close |
Definition at line 647 of file memcached-client.php.
Referenced by _load_items().
MWMemcached::_connect_sock | ( | &$ | sock, | |
$ | host | |||
) |
Connects $sock to $host, timing out after $timeout.
integer | $sock Socket to connect | |
string | $host Host:IP to connect to |
Definition at line 665 of file memcached-client.php.
References $i, and _debugprint().
Referenced by sock_to_host().
MWMemcached::_dead_host | ( | $ | host | ) |
Definition at line 705 of file memcached-client.php.
Referenced by _dead_sock(), and sock_to_host().
MWMemcached::_dead_sock | ( | $ | sock | ) |
Marks a host as dead until 30-40 seconds in the future.
string | $sock Socket to mark as dead |
Definition at line 700 of file memcached-client.php.
References _dead_host().
Referenced by _incrdecr(), _set(), delete(), get(), and get_multi().
MWMemcached::_debugprint | ( | $ | str | ) |
Reimplemented in MemCachedClientforWiki.
Definition at line 983 of file memcached-client.php.
References print.
Referenced by _connect_sock(), _load_items(), _set(), delete(), get(), and get_multi().
MWMemcached::_flush_read_buffer | ( | $ | f | ) |
Flush the read buffer of a stream.
Definition at line 1027 of file memcached-client.php.
References $n.
Referenced by get_sock().
MWMemcached::_hashfunc | ( | $ | key | ) |
Creates a hash integer based on the $key.
string | $key Key to hash |
Definition at line 774 of file memcached-client.php.
Referenced by get_sock().
MWMemcached::_incrdecr | ( | $ | cmd, | |
$ | key, | |||
$ | amt = 1 | |||
) |
Perform increment/decriment on $key.
string | $cmd Command to perform | |
string | $key Key to perform it on | |
integer | $amt Amount to adjust |
Definition at line 794 of file memcached-client.php.
References _dead_sock(), _safe_fwrite(), and get_sock().
MWMemcached::_load_items | ( | $ | sock, | |
&$ | ret | |||
) |
Load items into $ret from $sock.
resource | $sock Socket to read from | |
array | $ret Returned values |
Definition at line 829 of file memcached-client.php.
References $n, _close_sock(), and _debugprint().
Referenced by get(), and get_multi().
MWMemcached::_safe_fwrite | ( | $ | f, | |
$ | buf, | |||
$ | len = false | |||
) |
Write to a stream, timing out after the correct amount of time.
Definition at line 1015 of file memcached-client.php.
Referenced by _incrdecr(), _set(), delete(), get(), get_multi(), and run_command().
MWMemcached::_set | ( | $ | cmd, | |
$ | key, | |||
$ | val, | |||
$ | exp | |||
) |
Performs the requested storage operation to the memcache server.
string | $cmd Command to perform | |
string | $key Key to act on | |
mixed | $val What we need to store | |
integer | $exp When it should expire |
Definition at line 892 of file memcached-client.php.
References _dead_sock(), _debugprint(), _safe_fwrite(), and get_sock().
MWMemcached::add | ( | $ | key, | |
$ | val, | |||
$ | exp = 0 | |||
) |
Adds a key/value to the memcache server if one isn't already set with that key.
string | $key Key to set with data | |
mixed | $val Value to store | |
integer | $exp (optional) Time to expire data at |
Definition at line 279 of file memcached-client.php.
References _set().
MWMemcached::decr | ( | $ | key, | |
$ | amt = 1 | |||
) |
Decriment a value stored on the memcache server.
string | $key Key to decriment | |
integer | $amt (optional) Amount to decriment |
Definition at line 294 of file memcached-client.php.
References _incrdecr().
MWMemcached::delete | ( | $ | key, | |
$ | time = 0 | |||
) |
Deletes a key from the server, optionally after $time.
string | $key Key to delete | |
integer | $time (optional) How long to wait before deleting |
Definition at line 309 of file memcached-client.php.
References $res, _dead_sock(), _debugprint(), _safe_fwrite(), and get_sock().
MWMemcached::disconnect_all | ( | ) |
MWMemcached::enable_compress | ( | $ | enable | ) |
Enable / Disable compression.
boolean | $enable TRUE to enable, FALSE to disable |
Definition at line 361 of file memcached-client.php.
MWMemcached::forget_dead_hosts | ( | ) |
MWMemcached::get | ( | $ | key | ) |
Retrieves the value associated with the key from the memcache server.
string | $key Key to retrieve |
Definition at line 385 of file memcached-client.php.
References _dead_sock(), _debugprint(), _load_items(), _safe_fwrite(), get_sock(), wfProfileIn(), and wfProfileOut().
MWMemcached::get_multi | ( | $ | keys | ) |
Get multiple keys from the server(s).
array | $keys Keys to retrieve |
Definition at line 436 of file memcached-client.php.
References $keys, _dead_sock(), _debugprint(), _load_items(), _safe_fwrite(), and get_sock().
MWMemcached::get_sock | ( | $ | key | ) |
get_sock
string | $key Key to retrieve value for; |
Definition at line 723 of file memcached-client.php.
References $i, _flush_read_buffer(), _hashfunc(), and sock_to_host().
Referenced by _incrdecr(), _set(), delete(), get(), and get_multi().
MWMemcached::incr | ( | $ | key, | |
$ | amt = 1 | |||
) |
Increments $key (optionally) by $amt.
string | $key Key to increment | |
integer | $amt (optional) amount to increment |
Definition at line 498 of file memcached-client.php.
References _incrdecr().
MWMemcached::replace | ( | $ | key, | |
$ | value, | |||
$ | exp = 0 | |||
) |
Overwrites an existing value for key; only works if key is already set.
string | $key Key to set value as | |
mixed | $value Value to store | |
integer | $exp (optional) Experiation time |
Definition at line 514 of file memcached-client.php.
References _set().
MWMemcached::run_command | ( | $ | sock, | |
$ | cmd | |||
) |
Passes through $cmd to the memcache server connected by $sock; returns output as an array (null array if no output).
NOTE: due to a possible bug in how PHP reads while using fgets(), each line may not be terminated by a
. More specifically, my testing has shown that, on FreeBSD at least, each line is terminated only with a
. This is with the PHP flag auto_detect_line_endings set to falase (the default).
resource | $sock Socket to send command on | |
string | $cmd Command to run |
Definition at line 537 of file memcached-client.php.
References $res, and _safe_fwrite().
MWMemcached::set | ( | $ | key, | |
$ | value, | |||
$ | exp = 0 | |||
) |
Unconditionally sets a key to a given value in the memcache.
Returns true if set successfully.
string | $key Key to set value as | |
mixed | $value Value to set | |
integer | $exp (optional) Experiation time |
Definition at line 572 of file memcached-client.php.
References _set().
MWMemcached::set_compress_threshold | ( | $ | thresh | ) |
Sets the compression threshold.
integer | $thresh Threshold to compress if larger than |
Definition at line 584 of file memcached-client.php.
MWMemcached::set_debug | ( | $ | dbg | ) |
Sets the debug flag.
boolean | $dbg TRUE for debugging, FALSE otherwise |
Definition at line 598 of file memcached-client.php.
MWMemcached::set_servers | ( | $ | list | ) |
Sets the server list to distribute key gets and puts between.
array | $list Array of servers to connect to |
Definition at line 612 of file memcached-client.php.
Referenced by __construct().
MWMemcached::set_timeout | ( | $ | seconds, | |
$ | microseconds | |||
) |
Sets the timeout for new connections.
integer | $seconds Number of seconds | |
integer | $microseconds Number of microseconds |
Definition at line 630 of file memcached-client.php.
MWMemcached::sock_to_host | ( | $ | host | ) |
Returns the socket for the host.
string | $host Host:IP to get socket for |
Definition at line 957 of file memcached-client.php.
References _connect_sock(), and _dead_host().
Referenced by get_sock().
MWMemcached::$_active |
Definition at line 205 of file memcached-client.php.
MWMemcached::$_bucketcount |
Definition at line 197 of file memcached-client.php.
MWMemcached::$_buckets |
Definition at line 189 of file memcached-client.php.
MWMemcached::$_cache_sock |
Definition at line 117 of file memcached-client.php.
MWMemcached::$_compress_enable |
Definition at line 149 of file memcached-client.php.
MWMemcached::$_compress_threshold |
Definition at line 157 of file memcached-client.php.
MWMemcached::$_connect_attempts |
MWMemcached::$_connect_timeout |
MWMemcached::$_debug |
Definition at line 125 of file memcached-client.php.
MWMemcached::$_have_zlib |
Definition at line 141 of file memcached-client.php.
MWMemcached::$_host_dead |
Definition at line 133 of file memcached-client.php.
MWMemcached::$_persistant |
Definition at line 165 of file memcached-client.php.
MWMemcached::$_servers |
Definition at line 181 of file memcached-client.php.
MWMemcached::$_single_sock |
Definition at line 173 of file memcached-client.php.
MWMemcached::$_timeout_microseconds |
Definition at line 221 of file memcached-client.php.
MWMemcached::$_timeout_seconds |
Definition at line 213 of file memcached-client.php.
MWMemcached::$stats |
Definition at line 106 of file memcached-client.php.
const MWMemcached::COMPRESSED = 2 |
const MWMemcached::COMPRESSION_SAVINGS = 0.20 |
const MWMemcached::SERIALIZED = 1 |