MediaWiki
REL1_22
|
This is the PHP client for memcached - a distributed memory cache daemon. More...
Public Member Functions | |
__construct ($args) | |
Memcache initializer. | |
_close_sock ($sock) | |
Close the specified socket. | |
_connect_sock (&$sock, $host) | |
Connects $sock to $host, timing out after $timeout. | |
_dead_host ($host) | |
_dead_sock ($sock) | |
Marks a host as dead until 30-40 seconds in the future. | |
_debugprint ($text) | |
_error_log ($text) | |
_fgets ($sock) | |
Read a line from a stream. | |
_flush_read_buffer ($f) | |
Flush the read buffer of a stream. | |
_fread ($sock, $len) | |
Read the specified number of bytes from a stream. | |
_fwrite ($sock, $buf) | |
Write to a stream. | |
_handle_error ($sock, $msg) | |
Handle an I/O error. | |
_hashfunc ($key) | |
Creates a hash integer based on the $key. | |
_incrdecr ($cmd, $key, $amt=1) | |
Perform increment/decriment on $key. | |
_load_items ($sock, &$ret, &$casToken=null) | |
Load items into $ret from $sock. | |
_set ($cmd, $key, $val, $exp, $casToken=null) | |
Performs the requested storage operation to the memcache server. | |
add ($key, $val, $exp=0) | |
Adds a key/value to the memcache server if one isn't already set with that key. | |
cas ($casToken, $key, $value, $exp=0) | |
Sets a key to a given value in the memcache if the current value still corresponds to a known, given value. | |
decr ($key, $amt=1) | |
Decrease 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, &$casToken=null) | |
Retrieves the value associated with the key from the memcache server. | |
get_multi ($keys) | |
Get multiple keys from the server(s) | |
get_sock ($key) | |
get_sock | |
incr ($key, $amt=1) | |
Increments $key (optionally) by $amt. | |
lock ($key, $timeout=0) | |
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. | |
sock_to_host ($host) | |
Returns the socket for the host. | |
unlock ($key) | |
Public Attributes | |
integer | $_active |
# of total servers we have | |
integer | $_bucketcount |
Total # of bit buckets we have. | |
array | $_buckets |
Our bit buckets. | |
array | $_cache_sock |
Cached Sockets that are connected. | |
boolean | $_compress_enable |
Do we want to use compression? | |
integer | $_compress_threshold |
At how many bytes should we compress? | |
$_connect_attempts | |
Number of connection attempts for each server. | |
$_connect_timeout | |
Connect timeout in seconds. | |
boolean | $_debug |
Current debug status; 0 - none to 9 - profiling. | |
boolean | $_have_zlib |
Is compression available? | |
array | $_host_dead |
Dead hosts, assoc array, 'host'=>'unixtime when ok to check again'. | |
boolean | $_persistent |
Are we using persistent links? | |
array | $_servers |
Array containing ip:port or array(ip:port, weight) | |
string | $_single_sock |
If only using one server; contains ip:port to connect to. | |
integer | $_timeout_microseconds |
Stream timeout in microseconds. | |
integer | $_timeout_seconds |
Stream timeout in seconds. | |
array | $stats |
Command statistics. | |
const | COMPRESSED = 2 |
Flag: indicates data is compressed. | |
const | COMPRESSION_SAVINGS = 0.20 |
Minimum savings to store data compressed. | |
const | SERIALIZED = 1 |
Flag: indicates data is serialized. |
This is the PHP client for memcached - a distributed memory cache daemon.
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, 'persistent' => true));
$mc->add( 'key', array( 'some', 'array' ) ); $mc->replace( 'key', 'some random string' ); $val = $mc->get( 'key' );
Definition at line 76 of file MemcachedClient.php.
MWMemcached::__construct | ( | $ | args | ) |
Memcache initializer.
array | $args | Associative array of settings |
Definition at line 233 of file MemcachedClient.php.
References array(), and set_servers().
MWMemcached::_close_sock | ( | $ | sock | ) |
Close the specified socket.
string | $sock | socket to close |
Definition at line 698 of file MemcachedClient.php.
MWMemcached::_connect_sock | ( | &$ | sock, |
$ | host | ||
) |
Connects $sock to $host, timing out after $timeout.
$sock | Integer: socket to connect | |
string | $host | Host:IP to connect to |
Definition at line 716 of file MemcachedClient.php.
MWMemcached::_dead_host | ( | $ | host | ) |
$host |
Definition at line 765 of file MemcachedClient.php.
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 757 of file MemcachedClient.php.
MWMemcached::_debugprint | ( | $ | text | ) |
$text | string |
Definition at line 1090 of file MemcachedClient.php.
MWMemcached::_error_log | ( | $ | text | ) |
$text | string |
Definition at line 1097 of file MemcachedClient.php.
MWMemcached::_fgets | ( | $ | sock | ) |
Read a line from a stream.
If there is an error, mark the socket dead. The
line ending is stripped from the response.
$sock | The socket |
Definition at line 1184 of file MemcachedClient.php.
Flush the read buffer of a stream.
$f | Resource |
Definition at line 1213 of file MemcachedClient.php.
References $result.
MWMemcached::_fread | ( | $ | sock, |
$ | len | ||
) |
Read the specified number of bytes from a stream.
If there is an error, mark the socket dead.
$sock | The socket |
$len | The number of bytes to read |
Definition at line 1153 of file MemcachedClient.php.
MWMemcached::_fwrite | ( | $ | sock, |
$ | buf | ||
) |
Write to a stream.
If there is an error, mark the socket dead.
$sock | The socket |
$buf | The string to write |
Definition at line 1108 of file MemcachedClient.php.
References wfDebugLog().
MWMemcached::_handle_error | ( | $ | sock, |
$ | msg | ||
) |
Handle an I/O error.
Mark the socket dead and log an error.
Definition at line 1132 of file MemcachedClient.php.
MWMemcached::_hashfunc | ( | $ | key | ) |
Creates a hash integer based on the $key.
string | $key | key to hash |
Definition at line 833 of file MemcachedClient.php.
MWMemcached::_incrdecr | ( | $ | cmd, |
$ | key, | ||
$ | amt = 1 |
||
) |
Perform increment/decriment on $key.
string | $cmd | command to perform |
string | array | $key | key to perform it on |
$amt | Integer amount to adjust |
Definition at line 853 of file MemcachedClient.php.
Referenced by delete().
MWMemcached::_load_items | ( | $ | sock, |
&$ | ret, | ||
&$ | casToken = null |
||
) |
Load items into $ret from $sock.
$sock | Resource: socket to read from | |
array | $ret | returned values |
$casToken[optional] | Float |
Definition at line 894 of file MemcachedClient.php.
MWMemcached::_set | ( | $ | cmd, |
$ | key, | ||
$ | val, | ||
$ | exp, | ||
$ | casToken = null |
||
) |
Performs the requested storage operation to the memcache server.
string | $cmd | command to perform |
string | $key | key to act on |
$val | Mixed: what we need to store | |
$exp | Integer: (optional) Expiration time. This can be a number of seconds to cache for (up to 30 days inclusive). Any timespans of 30 days + 1 second or longer must be the timestamp of the time at which the mapping should expire. It is safe to use timestamps in all cases, regardless of exipration eg: strtotime("+3 hour") | |
$casToken[optional] | Float |
Definition at line 986 of file MemcachedClient.php.
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 |
$val | Mixed: value to store | |
$exp | Integer: (optional) Expiration time. This can be a number of seconds to cache for (up to 30 days inclusive). Any timespans of 30 days + 1 second or longer must be the timestamp of the time at which the mapping should expire. It is safe to use timestamps in all cases, regardless of expiration eg: strtotime("+3 hour") |
Definition at line 269 of file MemcachedClient.php.
MWMemcached::cas | ( | $ | casToken, |
$ | key, | ||
$ | value, | ||
$ | exp = 0 |
||
) |
Sets a key to a given value in the memcache if the current value still corresponds to a known, given value.
Returns true if set successfully.
$casToken | Float: current known value | |
string | $key | key to set value as |
$value | Mixed: value to set | |
$exp | Integer: (optional) Expiration time. This can be a number of seconds to cache for (up to 30 days inclusive). Any timespans of 30 days + 1 second or longer must be the timestamp of the time at which the mapping should expire. It is safe to use timestamps in all cases, regardless of exipration eg: strtotime("+3 hour") |
Definition at line 623 of file MemcachedClient.php.
MWMemcached::decr | ( | $ | key, |
$ | amt = 1 |
||
) |
Decrease a value stored on the memcache server.
string | $key | key to decrease |
$amt | Integer: (optional) amount to decrease |
Definition at line 284 of file MemcachedClient.php.
MWMemcached::delete | ( | $ | key, |
$ | time = 0 |
||
) |
Deletes a key from the server, optionally after $time.
string | $key | key to delete |
$time | Integer: (optional) how long to wait before deleting |
Definition at line 299 of file MemcachedClient.php.
References $key, and _incrdecr().
Disconnects all connected sockets.
Definition at line 358 of file MemcachedClient.php.
MWMemcached::enable_compress | ( | $ | enable | ) |
Enable / Disable compression.
$enable | Boolean: TRUE to enable, FALSE to disable |
Definition at line 374 of file MemcachedClient.php.
Forget about all of the dead hosts.
Definition at line 384 of file MemcachedClient.php.
MWMemcached::get | ( | $ | key, |
&$ | casToken = null |
||
) |
Retrieves the value associated with the key from the memcache server.
array | string | $key | key to retrieve |
$casToken[optional] | Float |
Definition at line 399 of file MemcachedClient.php.
References array().
MWMemcached::get_multi | ( | $ | keys | ) |
Get multiple keys from the server(s)
array | $keys | keys to retrieve |
Definition at line 458 of file MemcachedClient.php.
MWMemcached::get_sock | ( | $ | key | ) |
get_sock
string | $key | key to retrieve value for; |
Definition at line 784 of file MemcachedClient.php.
MWMemcached::incr | ( | $ | key, |
$ | amt = 1 |
||
) |
Increments $key (optionally) by $amt.
string | $key | key to increment |
$amt | Integer: (optional) amount to increment |
Definition at line 525 of file MemcachedClient.php.
MWMemcached::lock | ( | $ | key, |
$ | timeout = 0 |
||
) |
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 |
$value | Mixed: value to store | |
$exp | Integer: (optional) Expiration time. This can be a number of seconds to cache for (up to 30 days inclusive). Any timespans of 30 days + 1 second or longer must be the timestamp of the time at which the mapping should expire. It is safe to use timestamps in all cases, regardless of exipration eg: strtotime("+3 hour") |
Definition at line 545 of file MemcachedClient.php.
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)
$sock | Resource: socket to send command on | |
string | $cmd | command to run |
Definition at line 561 of file MemcachedClient.php.
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 |
$value | Mixed: value to set | |
$exp | Integer: (optional) Expiration time. This can be a number of seconds to cache for (up to 30 days inclusive). Any timespans of 30 days + 1 second or longer must be the timestamp of the time at which the mapping should expire. It is safe to use timestamps in all cases, regardless of exipration eg: strtotime("+3 hour") |
Definition at line 601 of file MemcachedClient.php.
MWMemcached::set_compress_threshold | ( | $ | thresh | ) |
Sets the compression threshold.
$thresh | Integer: threshold to compress if larger than |
Definition at line 635 of file MemcachedClient.php.
MWMemcached::set_debug | ( | $ | dbg | ) |
Sets the debug flag.
$dbg | Boolean: TRUE for debugging, FALSE otherwise |
Definition at line 649 of file MemcachedClient.php.
MWMemcached::set_servers | ( | $ | list | ) |
Sets the server list to distribute key gets and puts between.
array | $list | of servers to connect to |
Definition at line 663 of file MemcachedClient.php.
Referenced by __construct().
MWMemcached::set_timeout | ( | $ | seconds, |
$ | microseconds | ||
) |
Sets the timeout for new connections.
$seconds | Integer: number of seconds |
$microseconds | Integer: number of microseconds |
Definition at line 681 of file MemcachedClient.php.
MWMemcached::sock_to_host | ( | $ | host | ) |
Returns the socket for the host.
string | $host | Host:IP to get socket for |
Definition at line 1061 of file MemcachedClient.php.
MWMemcached::unlock | ( | $ | key | ) |
integer MWMemcached::$_active |
integer MWMemcached::$_bucketcount |
array MWMemcached::$_buckets |
array MWMemcached::$_cache_sock |
Cached Sockets that are connected.
Definition at line 117 of file MemcachedClient.php.
boolean MWMemcached::$_compress_enable |
integer MWMemcached::$_compress_threshold |
At how many bytes should we compress?
Definition at line 152 of file MemcachedClient.php.
MWMemcached::$_connect_attempts |
Number of connection attempts for each server.
Definition at line 218 of file MemcachedClient.php.
MWMemcached::$_connect_timeout |
Connect timeout in seconds.
Definition at line 213 of file MemcachedClient.php.
boolean MWMemcached::$_debug |
Current debug status; 0 - none to 9 - profiling.
Definition at line 124 of file MemcachedClient.php.
boolean MWMemcached::$_have_zlib |
array MWMemcached::$_host_dead |
Dead hosts, assoc array, 'host'=>'unixtime when ok to check again'.
Definition at line 131 of file MemcachedClient.php.
boolean MWMemcached::$_persistent |
array MWMemcached::$_servers |
Array containing ip:port or array(ip:port, weight)
Definition at line 173 of file MemcachedClient.php.
string MWMemcached::$_single_sock |
If only using one server; contains ip:port to connect to.
Definition at line 166 of file MemcachedClient.php.
integer MWMemcached::$_timeout_microseconds |
integer MWMemcached::$_timeout_seconds |
Stream timeout in seconds.
Applies for example to fread()
Definition at line 201 of file MemcachedClient.php.
array MWMemcached::$stats |
const MWMemcached::COMPRESSED = 2 |
Flag: indicates data is compressed.
Definition at line 91 of file MemcachedClient.php.
const MWMemcached::COMPRESSION_SAVINGS = 0.20 |
Minimum savings to store data compressed.
Definition at line 98 of file MemcachedClient.php.
const MWMemcached::SERIALIZED = 1 |
Flag: indicates data is serialized.
Definition at line 86 of file MemcachedClient.php.