MediaWiki master
|
memcached client class implemented using (p)fsockopen() More...
Inherits Wikimedia\LightweightObjectStore\StorageAwareness.
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/decrement 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. | |
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) | |
serialize ( $value) | |
set ( $key, $value, $exp=0) | |
Unconditionally sets a key to a given value in the memcache. | |
set_compress_threshold ( $thresh) | |
Set the compression threshold. | |
set_debug ( $dbg) | |
Set the debug flag. | |
set_servers ( $list) | |
Set 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. | |
touch ( $key, $time=0) | |
Changes the TTL on a key from the server to $time. | |
unserialize ( $value) | |
Public Attributes | |
int | $_active |
int | $_bucketcount |
Total # of bit buckets we have. | |
array | $_buckets |
Our bit buckets. | |
array | $_cache_sock |
Cached Sockets that are connected. | |
bool | $_compress_enable |
Do we want to use compression? | |
int | $_compress_threshold |
At how many bytes should we compress? | |
$_connect_attempts | |
Number of connection attempts for each server. | |
$_connect_timeout | |
Connect timeout in seconds. | |
bool | $_debug |
Current debug status; 0 - none to 9 - profiling. | |
bool | $_have_zlib |
Is compression available? | |
array | $_host_dead |
Dead hosts, assoc array, 'host'=>'unixtime when ok to check again'. | |
int | $_last_cmd_status = self::ERR_NONE |
StorageAwareness:ERR_* constant of the last cache command. | |
bool | $_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. | |
int | $_timeout_microseconds |
Stream timeout in microseconds. | |
int | $_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 | INTVAL = 4 |
Flag: indicates data is an integer. | |
const | SERIALIZED = 1 |
Flag: indicates data is serialized. | |
Public Attributes inherited from Wikimedia\LightweightObjectStore\StorageAwareness | |
const | ATTR_DURABILITY = 2 |
Durability of writes; see QOS_DURABILITY_* (higher means stronger) | |
const | ATTR_EMULATION = 1 |
const | ERR_NO_RESPONSE = 1 |
Storage medium failed to yield a complete response to an operation. | |
const | ERR_NONE = 0 |
No storage medium error. | |
const | ERR_UNEXPECTED = 3 |
Storage medium operation failed due to usage limitations or an I/O error. | |
const | ERR_UNREACHABLE = 2 |
Storage medium could not be reached to establish a connection. | |
const | QOS_DURABILITY_DISK = 4 |
Data is saved to disk and writes do not usually block on fsync() | |
const | QOS_DURABILITY_NONE = 1 |
Data is never saved to begin with (blackhole store) | |
const | QOS_DURABILITY_RDBMS = 5 |
Data is saved to disk and writes usually block on fsync(), like a standard RDBMS. | |
const | QOS_DURABILITY_SCRIPT = 2 |
Data is lost at the end of the current web request or CLI script. | |
const | QOS_DURABILITY_SERVICE = 3 |
Data is lost once the service storing the data restarts. | |
const | QOS_UNKNOWN = INF |
Generic "unknown" value; useful for comparisons (always "good enough") | |
memcached client class implemented using (p)fsockopen()
Definition at line 81 of file MemcachedClient.php.
MemcachedClient::__construct | ( | $args | ) |
Memcache initializer.
array | $args | Associative array of settings |
Definition at line 265 of file MemcachedClient.php.
References set_servers().
MemcachedClient::_close_sock | ( | $sock | ) |
Close the specified socket.
string | $sock | Socket to close |
Definition at line 805 of file MemcachedClient.php.
MemcachedClient::_connect_sock | ( | & | $sock, |
$host ) |
Connects $sock to $host, timing out after $timeout.
int | $sock | Socket to connect |
string | $host | Host:IP to connect to |
Definition at line 823 of file MemcachedClient.php.
References _dead_host(), _error_log(), and _flush_read_buffer().
Referenced by sock_to_host().
MemcachedClient::_dead_host | ( | $host | ) |
string | $host |
Definition at line 881 of file MemcachedClient.php.
Referenced by _connect_sock(), and _dead_sock().
MemcachedClient::_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 873 of file MemcachedClient.php.
References _dead_host().
Referenced by _handle_error().
MemcachedClient::_debugprint | ( | $text | ) |
string | $text |
Definition at line 1244 of file MemcachedClient.php.
Referenced by _incrdecr(), _set(), delete(), get(), get_multi(), and touch().
MemcachedClient::_error_log | ( | $text | ) |
string | $text |
Definition at line 1251 of file MemcachedClient.php.
Referenced by _connect_sock(), and _handle_error().
MemcachedClient::_fgets | ( | $sock | ) |
Read a line from a stream.
If there is an error, mark the socket dead. The \r\n line ending is stripped from the response.
Resource | $sock | The socket |
Definition at line 1341 of file MemcachedClient.php.
References _handle_error().
Referenced by _incrdecr(), _load_items(), _set(), delete(), run_command(), and touch().
MemcachedClient::_flush_read_buffer | ( | $f | ) |
Flush the read buffer of a stream.
Resource | $f |
Definition at line 1370 of file MemcachedClient.php.
Referenced by _connect_sock().
MemcachedClient::_fread | ( | $sock, | |
$len ) |
Read the specified number of bytes from a stream.
If there is an error, mark the socket dead.
Resource | $sock | The socket |
int | $len | The number of bytes to read |
Definition at line 1310 of file MemcachedClient.php.
References _handle_error().
Referenced by _load_items().
MemcachedClient::_fwrite | ( | $sock, | |
$buf ) |
Write to a stream.
If there is an error, mark the socket dead.
Resource | $sock | The socket |
string | $buf | The string to write |
Definition at line 1262 of file MemcachedClient.php.
References _handle_error().
Referenced by _incrdecr(), _set(), delete(), get(), get_multi(), run_command(), and touch().
MemcachedClient::_handle_error | ( | $sock, | |
$msg ) |
Handle an I/O error.
Mark the socket dead and log an error.
Resource | $sock | |
string | $msg |
Definition at line 1289 of file MemcachedClient.php.
References _dead_sock(), and _error_log().
Referenced by _fgets(), _fread(), _fwrite(), and _load_items().
MemcachedClient::_hashfunc | ( | $key | ) |
Creates a hash integer based on the $key.
string | $key | Key to hash |
Definition at line 953 of file MemcachedClient.php.
Referenced by get_sock().
MemcachedClient::_incrdecr | ( | $cmd, | |
$key, | |||
$amt = 1 ) |
Perform increment/decrement on $key.
string | $cmd | Command to perform |
string | array | $key | Key to perform it on |
int | $amt | Amount to adjust |
Definition at line 973 of file MemcachedClient.php.
References _debugprint(), _fgets(), _fwrite(), and get_sock().
MemcachedClient::_load_items | ( | $sock, | |
& | $ret, | ||
& | $casToken = null ) |
Load items into $ret from $sock.
Resource | $sock | Socket to read from |
array | $ret | returned values |
float | $casToken | [optional] |
Definition at line 1029 of file MemcachedClient.php.
References _fgets(), _fread(), _handle_error(), and unserialize().
Referenced by get(), and get_multi().
MemcachedClient::_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 |
mixed | $val | What we need to store |
int | $exp | (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") |
float | $casToken | [optional] |
Definition at line 1117 of file MemcachedClient.php.
References _debugprint(), _fgets(), _fwrite(), get_sock(), and serialize().
MemcachedClient::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 |
int | $exp | (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 320 of file MemcachedClient.php.
References _set().
MemcachedClient::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.
float | $casToken | Current known value |
string | $key | Key to set value as |
mixed | $value | Value to set |
int | $exp | (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 732 of file MemcachedClient.php.
References _set().
MemcachedClient::decr | ( | $key, | |
$amt = 1 ) |
Decrease a value stored on the memcache server.
string | $key | Key to decrease |
int | $amt | (optional) amount to decrease |
Definition at line 337 of file MemcachedClient.php.
References _incrdecr().
MemcachedClient::delete | ( | $key, | |
$time = 0 ) |
Deletes a key from the server, optionally after $time.
string | $key | Key to delete |
int | $time | (optional) how long to wait before deleting |
Definition at line 354 of file MemcachedClient.php.
References _debugprint(), _fgets(), _fwrite(), and get_sock().
MemcachedClient::disconnect_all | ( | ) |
Disconnects all connected sockets.
Definition at line 442 of file MemcachedClient.php.
MemcachedClient::enable_compress | ( | $enable | ) |
Enable / Disable compression.
bool | $enable | True to enable, false to disable |
Definition at line 458 of file MemcachedClient.php.
MemcachedClient::forget_dead_hosts | ( | ) |
Forget about all of the dead hosts.
Definition at line 468 of file MemcachedClient.php.
MemcachedClient::get | ( | $key, | |
& | $casToken = null ) |
Retrieves the value associated with the key from the memcache server.
array | string | $key | key to retrieve |
float | $casToken | [optional] |
Definition at line 483 of file MemcachedClient.php.
References _debugprint(), _fwrite(), _load_items(), get_sock(), and serialize().
MemcachedClient::get_multi | ( | $keys | ) |
Get multiple keys from the server(s)
array | $keys | Keys to retrieve |
Definition at line 556 of file MemcachedClient.php.
References _debugprint(), _fwrite(), _load_items(), and get_sock().
MemcachedClient::get_sock | ( | $key | ) |
get_sock
string | $key | Key to retrieve value for; |
Definition at line 904 of file MemcachedClient.php.
References _hashfunc(), and sock_to_host().
Referenced by _incrdecr(), _set(), delete(), get(), get_multi(), and touch().
MemcachedClient::incr | ( | $key, | |
$amt = 1 ) |
Increments $key (optionally) by $amt.
string | $key | Key to increment |
int | $amt | (optional) amount to increment |
Definition at line 634 of file MemcachedClient.php.
References _incrdecr().
MemcachedClient::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 |
int | $exp | (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 654 of file MemcachedClient.php.
References _set().
MemcachedClient::run_command | ( | $sock, | |
$cmd ) |
Passes through $cmd to the memcache server connected by $sock; returns output as an array (null array if no output)
Resource | $sock | Socket to send command on |
string | $cmd | Command to run |
Definition at line 670 of file MemcachedClient.php.
MemcachedClient::serialize | ( | $value | ) |
mixed | $value |
Definition at line 292 of file MemcachedClient.php.
References serialize().
Referenced by _set(), get(), and serialize().
MemcachedClient::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 |
int | $exp | (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 710 of file MemcachedClient.php.
References _set().
MemcachedClient::set_compress_threshold | ( | $thresh | ) |
Set the compression threshold.
int | $thresh | Threshold to compress if larger than |
Definition at line 744 of file MemcachedClient.php.
MemcachedClient::set_debug | ( | $dbg | ) |
Set the debug flag.
bool | $dbg | True for debugging, false otherwise |
Definition at line 757 of file MemcachedClient.php.
MemcachedClient::set_servers | ( | $list | ) |
Set the server list to distribute key gets and puts between.
array | $list | Array of servers to connect to |
Definition at line 770 of file MemcachedClient.php.
Referenced by __construct().
MemcachedClient::set_timeout | ( | $seconds, | |
$microseconds ) |
Sets the timeout for new connections.
int | $seconds | Number of seconds |
int | $microseconds | Number of microseconds |
Definition at line 788 of file MemcachedClient.php.
MemcachedClient::sock_to_host | ( | $host | ) |
Returns the socket for the host.
string | $host | Host:IP to get socket for |
Definition at line 1210 of file MemcachedClient.php.
References _connect_sock().
Referenced by get_sock().
MemcachedClient::touch | ( | $key, | |
$time = 0 ) |
Changes the TTL on a key from the server to $time.
string | $key | |
int | $time | TTL in seconds |
Definition at line 400 of file MemcachedClient.php.
References _debugprint(), _fgets(), _fwrite(), and get_sock().
MemcachedClient::unserialize | ( | $value | ) |
string | $value |
Definition at line 300 of file MemcachedClient.php.
References unserialize().
Referenced by _load_items(), and unserialize().
int MemcachedClient::$_active |
int MemcachedClient::$_bucketcount |
array MemcachedClient::$_buckets |
array MemcachedClient::$_cache_sock |
Cached Sockets that are connected.
Definition at line 129 of file MemcachedClient.php.
bool MemcachedClient::$_compress_enable |
int MemcachedClient::$_compress_threshold |
At how many bytes should we compress?
Definition at line 169 of file MemcachedClient.php.
MemcachedClient::$_connect_attempts |
Number of connection attempts for each server.
Definition at line 243 of file MemcachedClient.php.
MemcachedClient::$_connect_timeout |
Connect timeout in seconds.
Definition at line 238 of file MemcachedClient.php.
bool MemcachedClient::$_debug |
Current debug status; 0 - none to 9 - profiling.
Definition at line 137 of file MemcachedClient.php.
bool MemcachedClient::$_have_zlib |
array MemcachedClient::$_host_dead |
Dead hosts, assoc array, 'host'=>'unixtime when ok to check again'.
Definition at line 145 of file MemcachedClient.php.
int MemcachedClient::$_last_cmd_status = self::ERR_NONE |
StorageAwareness:ERR_* constant of the last cache command.
Definition at line 246 of file MemcachedClient.php.
bool MemcachedClient::$_persistent |
array MemcachedClient::$_servers |
Array containing ip:port or array(ip:port, weight)
Definition at line 193 of file MemcachedClient.php.
string MemcachedClient::$_single_sock |
If only using one server; contains ip:port to connect to.
Definition at line 185 of file MemcachedClient.php.
int MemcachedClient::$_timeout_microseconds |
int MemcachedClient::$_timeout_seconds |
Stream timeout in seconds.
Applies for example to fread()
Definition at line 225 of file MemcachedClient.php.
array MemcachedClient::$stats |
const MemcachedClient::COMPRESSED = 2 |
Flag: indicates data is compressed.
Definition at line 96 of file MemcachedClient.php.
const MemcachedClient::COMPRESSION_SAVINGS = 0.20 |
Minimum savings to store data compressed.
Definition at line 108 of file MemcachedClient.php.
const MemcachedClient::INTVAL = 4 |
Flag: indicates data is an integer.
Definition at line 101 of file MemcachedClient.php.
const MemcachedClient::SERIALIZED = 1 |
Flag: indicates data is serialized.
Definition at line 91 of file MemcachedClient.php.