Memcache library is in PECL (PHP Extension Community Library), the main role is to establish large-capacity memory transient data warehouse area, reflected in the role of dispensed quite clear while, or not suggested. memcache data width is aided to 524288 (512K), the memories cache is concerned, this width is adequate for the
in memcached: error meantime 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 built through the new
the memcached module to install php,
Supra Shoes UK, cancellation / etc/php5/conf.d/memcached.ini inside the
implementation:
/ usr / regional / bin / memcached-d-m 10-u root-l 127.0.0.1-p 11211-c 256-P / tmp / memcached.pid
memcached service was officially fired
Basic Options
attention
-p listening TCP port (default: 11211)
-d to run in daemon mode Memcached
-u account running Memcached, non-root user
-m largest memory usage,
Supra Pilot Shoes, the element is MB, the default is 64 MB
Soft
-c the number of connections, default is 1024
-v Output warnings and error messages
-vv print client's apply and return information
-h Print assist information
-i publish memcached and libevent license message
run Memcached
goal: using 11211 port, hualiangxie consumers, the largest occupation of 512M memory, 1024 soft-connected, the output consumer requests to run in daemon mode to run the port
Memcache:: add - add a value, if it already exists, it returns false
Memcache:: addServer - add a server address available
Memcache:: close - close a Memcache object
Memcache:: connect - to create a Memcache object
memcache_debug - control debugging
Memcache:: decrement - a key to the preservation of the merits in the subtraction action
Memcache:: delete - Delete a key value
Memcache:: flush - Clears all cached data
Memcache:: get - to get a key value
Memcache:: getExtendedStats - Get all processes running in the pond process system statistics
Memcache:: getServerStatus - the parameters for running the server
Memcache:: getStats - return the server to run some statistical information
Memcache:: getVersion - Return version information to run the Memcache
Memcache:: increment - a key in the preservation The value addition operation
Memcache:: pconnect - create a persistent connection Memcache object
Memcache:: replace - R on an existing key to override the operation
Memcache:: set - add a value If already exists, overwrite
Memcache:: setCompressThreshold - larger than a certain size of data compression
Memcache:: setServerParams - modify the server at run-time parameters
proposed object-oriented reach to test the library:
view plainprint?
connect ('localhost',
Supra Trainers, 11211) or die (not connect ;
?>
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 three parameters, the first parameter indicates the type required to return to: reset, malloc, maps, cachedump, slabs, items, sizes; the second argument and third argument 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 dead (> 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 establish a Memcache thing. Memcache:: pconnect method is used to create a consistent connection Memcache object. Memcache:: close method is used to close a Memcache object.
Memcache:: set method is used to multiplication a value,
2011 Supra Shoes, Memcache:: set method has 4 parameters, the premier parameter is the key, the second parameter is the value, the optional third parameter to denote whether to abbreviate retention, The fourth parameter is optional, is used to set an expiration time to self-destruct. Memcache:: add methods of the character and Memcache:: set is alike, except namely if the Memcache:: add method return value is artificial, that the key yet exists, and Memcache:: set method is directly overwritten. Memcache:: obtain method is used to get a key value, Memcache:: get method has a parameter namely 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 2 parameters, premier parameter indicates the key, the second parameter is optional, that cleared the lag.
view plainprint?
replace ('name', 'lion', 0, 300);
reverberate $ memcache-> get ('name');
$ memcache-> delete ('name', 5);
?>
connect ('localhost', 11211) or die (, 'susan', 0, 30)) echo 'susan is exist';; $ memcache-> replace ('name',
Supra Skytop II Shoes, 'lion', 0, 300); echo $ memcache-> get ('name'); $ memcache-> delete ('name', 5);?>
memcache_debug () function is to control the debugging traits, catered that at compile php When to use the enable-debug option, otherwise this function will not go.
Memcache:: addServer method is used to add an obtainable server residence, Memcache:: addServer method has 8 parameters, but the first parameter accidents, others are optional, the first parameter indicates the server residence The second parameter indicates the port, the third parameter indicates whether a persistent connection, the fourth controversy that this server on all servers in the heaviness, the fifth parameter indicates the period of the connection, the sixth parameter indicates the connection retry interval, the default is 15, set to -1 method not retry, the seventh parameter is used to control the server's online status, 8 parameter allows you to set out a behind feature to deal the misdeed message.
Memcache:: setServerParams method is used at runtime to adjust the server parameters, Memcache:: setServerParams method has 6 parameters, Memcache:: addServer method missing the third and fourth parameters. Memcache:: getServerStatus method is used for running the server parameters, two parameters represent the address and port.
view plainprint?
setServerParams ('192 .168.1.116 ', 11211, 1, 15, true,' _callback_memcache_failure ');
echo $ memcache-> getServerStatus (' 192.168.1.116 ',
Supras, 11211);
?>
getServerStatus ('192 .168.1.116 ', 11211);?>
Memcache:: flush method is used to remove always stored data, but not ambition be slashing the use of memory space.
Memcache:: increment usage is secondhand in the preservation of the values of a key increase operation, Memcache:: decremen means is accustom for the maintenance of one 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 method is used is larger than a certain size of data compression. setCompressThreshold method has two parameters, the first parameter indicates the size of the critical point of processing data, and the second parameter indicates the percentage 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 among two servers among the network fashion, commonly 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 through the network card to access a Memcache server, we began on the server Memcache to monitor the network when the IP address and port, the interconnection of the visit will effectively discourage additional 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 highest of 1024 simultaneous connections
firewall
firewall is simple and telling path, and whether it is both servers are hanging on the net, and absence to access the outer network IP Memcache, then think using a firewall alternatively surrogate to percolate the illegal program way.
in common we can use iptables under Linux or FreeBSD ipfw to specify the number under the rules to prevent illegal access, for instance we can set only allow us to access our Web server Memcache server, while preventing other 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
above iptables rules that permit merely Web server on 192.168.0.2 which sets Memcache server access, can effectively prevent the illegal access, the corresponding can too addition the number of other rules to enhance security, this can be done according to their needs.