Memcache library is in PECL (PHP Extension Community Library), the cardinal character is to establish large-capacity memories temporary data warehouse space, reflected in the character of distributed quite explicit when, or not recommended. memcache data width is aided to 524288 (512K), the memories storage is concerned, this length is ample because the
in memcached: peccadillo while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory
by:
sudo ln-s / usr/local/lib/libevent-1.4.so.2 / usr/lib/libevent-1.4.so.2
can fix this BUG
was established via the new
the memcached module to setup php, cancellation / etc/php5/conf.d/memcached.ini inside the
implementation:
/ usr / local / binary / memcached-d-m 10-u root-l 127.0.0.1-p 11211-c 256-P / tmp / memcached.pid
memcached service was officially launched
Basic Options
attention
-p hearing TCP port (default: 11211)
-d to run in daemon mode Memcached
-u list running Memcached, non-root consumer
-m largest memory method, the unit is MB, the default is 64 MB
Soft
-c the number of connections, default is 1024
-v Output omens and error messages
-vv print client's apply and return information
-h Print assist information
-i print memcached and libevent license information
run Memcached
goal: using 11211 port, hualiangxie users, the largest occupation of 512M memory, 1024 soft-connected, the output client requests to run in daemon mode to run the port
Memcache:: add - add a value,
Supra Skytop II Shoes, if it already exists, it returns artificial
Memcache:: addServer - join a waiter address available
Memcache:: close - close a Memcache object
Memcache:: join - to create a Memcache thing
memcache_debug - control debugging
Memcache:: reduction - a key to the preservation of the values in the subtraction operation
Memcache:: delete - Delete a key value
Memcache:: flush - Clears all cached data
Memcache:: get - to get a key value
Memcache:: getExtendedStats - Get entire processes running in the pond process system statistics
Memcache:: getServerStatus - the parameters for running the server
Memcache:: getStats - return the server to flee some statistical information
Memcache:: getVersion - Return version information to run the Memcache
Memcache:: increment - a opener in the conservation The merit adding operation
Memcache:: pconnect - create a persistent connection Memcache object
Memcache:: replace - R on one existing key to override the operation
Memcache:: set - add a value If yet exists, overwrite
Memcache:: setCompressThreshold - larger than a certain size of data compression
Memcache:: setServerParams - modify the server at run-time parameters
intended object-oriented reach to test the library:
view plainprint?
connect ('localhost', 11211) or die (version = $ memcache-> getVersion (); echo
Memcache:: getStats method is used to return some of the server operating statistics. Memcache:: getStats method has 3 parameters, the first parameter indicates the type necessitated to return to: reset, malloc, maps,
Supra TK Society Shoes, cachedump, slabs, items, sizes; the second argument and third contention is the first parameter is set to Memcache:: getExtendedStats method is used for all processes running in the pool process system statistics.
view plainprint?
connect ('localhost', 11211) or die (not connect [pid] => 8052
* [uptime] => 9205
* [period] => 1205898428
* [version] => 1.2.5
* [pointer_size] => 32
* [rusage_user] => 0.008000
* [rusage_system] => 0.000000
* ; [curr_items] => 1
* [total_items] => 17
* [ ,],[> * [connection_structures] => 3
* [cmd_get] => 9
* [cmd_set] => 23
* [get_hits] => 5
* [get_misses] = > 4
* [evictions] => 0
* [bytes_read] => 671
* ; [bytes_written] => 850
* [limit_maxbytes] => 10485760
* ; [threads] => 1
*)
* /
?>
connect ('localhost', 11211) or die (> 8052 * [uptime] => 9205 * [time] => 1205898428 * [version] => 1.2.5 * [pointer_size] => 32 * [rusage_user] => 0.008000 * [rusage_system] => 0.000000 * [curr_items] => 1 * [total_items] => 17 * [bytes] => 57 * [curr_connections] => 2 * [total_connections] => 15 * [connection_structures] => 3 * [cmd_get] => 9 * [cmd_set] => 23 * [get_hits] => 5 * [get_misses] => 4 * [evictions] => 0 * [bytes_read] => 671 * [bytes_written] => 850 * [limit_maxbytes] => 10485760 * [threads] => 1 *) * /?>
Memcache:: connect method is used to create a Memcache object. Memcache:: pconnect method is used to create a persistent linkage Memcache object. Memcache:: near method is used to near a Memcache object.
Memcache:: set method is used to add a value, Memcache:: set method has four parameters, the first parameter is the key, the second parameter is the value, the optional third parameter to indicate whether to constrict save, The fourth parameter is optional, is used to set an expiratiin season to self-destruct. Memcache:: add methods of the role and Memcache:: set is alike, besides that if the Memcache:: add method return value is false, that the key already exists, and Memcache:: set method is instantly overwritten. Memcache:: get method is used to win a key value, Memcache:: get method has a parameter that represents the key. Memcache:: replace method is used for a key to override the existing operation, Memcache:: replace method has 4 parameters, roles and Memcache:: set method is the same. Memcache:: delete method is used to delete a key value, Memcache:: delete method has two parameters, first parameter indicates the key, the second parameter is optional, that removed the lag.
view plainprint?
replace ('name', 'lion', 0, 300);
echo $ memcache-> get ('name');
$ memcache-> cancel ('name', 5);
?>
connect ('localhost', 11211) or die (, 'susan', 0, 30)) echo 'susan is exist';; $ memcache-> replace ('name', 'lion', 0,
Supra Cruizer Shoes, 300); echo $ memcache-> get ('name'); $ memcache-> delete ('name', 5);?>
memcache_debug () function is apt control the debugging traits, catered that at compile php When to use the enable-debug discretion, otherwise this feature will not go.
Memcache:: addServer method is used to add an available server address, Memcache:: addServer method has 8 parameters, but the first parameter events, others are optional, the first parameter indicates the server address The second parameter indicates the port,
Supra Shoes UK, the third parameter indicates whether a persistent connection,
Women's Supra Skytop II, the fourth argument that this server on all servers in the heaviness, the fifth parameter indicates the duration of the connection, the sixth parameter indicates the connection retry interval, the default is 15, set to -1 means no retry, the seventh parameter is used to control the server's online status, 8 parameter allows you to set out a behind function to knob the error message.
Memcache:: setServerParams method is used at runtime to modify the server parameters, Memcache:: setServerParams method has 6 parameters, Memcache:: addServer method lacking the third and fourth parameters. Memcache:: getServerStatus method is used for running the server parameters, two parameters characterize the address and port.
view plainprint?
setServerParams ('192 .168.1.116 ', 11211, 1,
Supra Bullet Shoes, 15, true,' _callback_memcache_failure ');
echo $ memcache-> getServerStatus (' 192.168.1.116 ', 11211);
?>
getServerStatus ('192 .168.1.116 ', 11211);?>
Memcache:: flush method is used to clear all cached data, but not will be slashing the use of memory space.
Memcache:: increment method is used in the preservation of the values of a key addition operation, Memcache:: decremen method is used for the protection of an of the key values in the subtraction operation.
view plainprint?
connect ('localhost', 11211);
$ memcache-> set ('test_item', 8);
$ memcache-> increment ('test_item', 4);
echo $ memcache-> ; decrement ('test_item', 7);
/ / Show 5
?>
connect ('localhost', 11211); $ memcache-> set ('test_item', 8); $ memcache-> increment ('test_item', 4); echo $ memcache-> decrement ('test_item' , 7); / / show 5?>
setCompressThreshold usage namely secondhand is larger than a decisive size of data compression. setCompressThreshold method has 2 parameters, the first parameter indicates the size of the fussy point of processing data, and the second parameter indicates the ratio of compression, the default is 0.2.
view plainprint?
addServer ('memcache_host', 11211);
$ memcache-> setCompressThreshold (20000, 0.2);
?>
addServer (' memcache_host ', 11211); $ memcache-> setCompressThreshold (20000, 0.2);?>
intranet access
best to visit is between two servers within the network manner, usually with the Memcache server Web server. There are generally two network cards server, a point to the Internet, a point within the network, then let the Web server via the network card to access a Memcache server, we started on the server Memcache to monitor the network when the IP address and port, the interconnection of the visit will mainly prevent other illegal access.
# memcached-d-m 1024-u root-l 192.168.0.200-p 11211-c 1024-P / tmp / memcached.pid
Memcache server monitoring via the network to set the ip of 192.168.0.200 11211 port, take 1024MB memory, and allows maximum of 1024 concurrent connections
firewall
firewall is easy and forcible way, and if it is either servers are hanging ashore the net, and absence to way the external web IP Memcache, then consider using a firewall or agent to percolate the unlawful program access.
in general we can use iptables beneath Linux or FreeBSD ipfw to specify the number under the rules to discourage illegal access, case in point we tin set merely permit us to access our Web server Memcache server, while preventing additional access.
# iptables-F
# iptables-P INPUT DROP
# iptables-A INPUT-p tcp-s 192.168.0.2 dport 11211-j ACCEPT
# iptables-A INPUT-p udp - s 192.168.0.2 dport 11211-j ACCEPT
on iptables rules that allow only Web server on 192.168.0.2 which sets Memcache server access, can effectively prevent the illegal access, the corresponding can too boost the number of other rules to enhance security, this can be done according to their needs.