In php, memcache is a cache function that can improve data access performance and reduce machine load. Here I will introduce the memcache Optimization Method in php. In php, memcache is a cache function that can improve data access performance and reduce machine load. Here I will introduce the memcache Optimization Method in php.
Script ec (2); script
Memcache support |
Enabled |
Active persistent connections |
0 |
Revision |
$ Revision: 1.92 $ |
Directive |
Local Value |
Master Value |
Memcache. allow_failover |
1 |
1 |
Memcache. chunk_size |
8192 |
8192 |
Memcache. default_port |
11211 |
11211 |
Memcache. hash_function |
Crc32 |
Crc32 |
Memcache. hash_strategy |
Standard |
Standard |
Memcache. max_failover_attempts |
20 |
20 |
Find some information about the optimization of the php memcache module on the Internet and paste it out.
The Code is as follows: |
|
Vi/etc/php. d/memcache. ini [Memcache] ; Enable memcache extension module Extension = memcache. so Memcache. allow_failover = "1" Memcache. max_failover_attempts = "20" Memcache. chunk_size = "8192" Memcache. default_port = "11211" Memcache. hash_strategy = "standard" Memcache. hash_function = "crc32" |
Ps:
The Code is as follows: |
|
Memcache. allow_failover = "1" |
A boolean value used to control whether the Memcache extension fails over to other servers when a connection error occurs. The default value is 1 (true ).
The Code is as follows: |
|
Memcache. max_failover_attempts = "20" |
An integer value used to limit the number of servers connected to persistent data or retrieved data. If memcache. allow_failover is false, this parameter is ignored. The default value is 20.
The Code is as follows: |
|
Memcache. chunk_size = "8192"
|
An integer value used to control the data transmission size. The default value is 8192 bytes (8 KB), but if it is set to 32768 (32 KB), it can achieve better performance.
The Code is as follows: |
|
Memcache. default_port = "11211" |
Another integer value is used to set the TCP port used to connect to Memcache. The default value is unprivileged high port 11211 unless you modify it.
The Code is as follows: |
|
Memcache. hash_strategy = "standard" |
Hash policy. Currently there are standard and consistent modes. standard modes are actually %, that is, modulo. and consistent, which is more complicated. memcache. hash_function = "crc32"
Controls which hrated function is applied to key ing to the server. The default value "crc32" uses the CRC32 algorithm, while "fnv" indicates that the FNV-1a algorithm is used.
Test memcache
The Code is as follows: |
|
$ Mc = new Memcache; $ Mc-> connect ("127.0.0.1", 11211 ); $ Item = $ mc-> get ('item '); If (! Is_array ($ item )){ Echo "Add item to memcache "; $ Mc-> add ('item', array ('item ')); } $ Item = $ mc-> get ('item '); Var_dump ($ item ); ?> |
Finally, we wish you success in improving the server performance and improving website operations.