I 've been trying to test memcache a few days ago, but I can't spare any time. In fact, I am very lazy and don't want to get it... last night, I started to work on the server. I had a hard time trying to solve the problem. Because memcached was not installed, I could not connect to it. I installed it in my notebook. gg said that memcache needs to be loaded. dll extension, it is difficult to connect. I asked in the group today and solved the problem after I went to GG. the conclusion is that you should not try it out when you are in an impetuous mood.ProgramIn this way, it is difficult to solve the problem. You need to calm down and the problem will be solved soon.
Windows installation method, reference source: http://www.ccvita.com/258.html this brotherArticleVery good is the result of practice... very admired ....
Install memcache in Windows:
1. Download the stable version of memcache for Windows and decompress it to a disk, for example, in c: \ memcached
2. Enter 'C: \ memcached \ memcached.exe-D install' on the terminal (that is, the CMD command interface) to install
3. Enter 'C: \ memcached \ memcached.exe-D start' to start. Note: in the future, memcached will be used as a Windows Service and will be automatically started every time it is started. In this way, the server has been installed.
4. Download php_memcache.dll. Find the corresponding PHP version file by yourself.
5. Add a line 'extension = php_memcache.dll 'to c: \ winnt \ PHP. ini'
6. Restart Apache and check phpinfo. If memcache exists, the installation is successful!
Basic settings of memcached:
-P Listening port
-L The IP address to connect to. The default value is local.
-D start: Start the memcached service.
-D restart: restart the memcached service.
-D stop | Shutdown the running memcached Service
-D install the memcached Service
-D uninstall memcached Service
-U To (Only valid when running as root)
-M Maximum memory usage, in MB. The default value is 64 MB.
-An error is returned when M memory is used up, instead of deleting items.
-C Maximum number of simultaneous connections. The default value is 1024.
-F Block Size growth factor. The default value is 1.25.
-N Minimum allocation space. The default value of key + value + flags is 48.
-H Show Help
Test the memcache Environment:
Run the following PHP file. If this is a test! Is output !, Indicates that the environment is successfully set up. Start to appreciate the charm of memcache!
<? PHP
$ Mem = New Memcache;
$ Mem -> Connect (" 127.0 . 0.1 ″ , 11211 );
$ Mem -> Set (' Key ' , 'This is a test ! ' , 0 , 60 );
$ Val = $ Mem -> Get (' Key ');
Echo $ Val ;
?>
Here I did the test and used the TP Framework Version 2.0.
Test code
Header ( ' Content-Type: text/html; charset = UTF-8 ' );
Debug_start ( ' A ' );
$ Cache = Cache :: Getinstance ( ' Memcache ' );
// Obtain data
If ( ! $ Cache -> Get ( ' District ' ))
{
$ M = M ( ' District ' );
$ Result = $ M -> Limit ( ' 4000 ' ) -> Select ();
// Write Cache
$ Cache -> Set ( ' District ' , $ Result , 0 ,- 1 );
// Dump ('setok ');
}
$ Results = $ Cache -> Get ( ' District ' );
// Dump ($ results );
Debug_end ( ' A ' );
Time when 4 K data entries are loaded
Process A: Times 0.427078 s memories 5,979 K
Use cached
Process A: Times 0.211823 s memories 2,765 K
The processing performance is still improved. You need to set the management of all the caches to replace the File Cache. problems are found during use. If the amount of data exceeds 5000, the set will not be included.
Information Source http://blog.myspace.cn/e/401447849.htm.
Some results can be calculated based on the content and parameter settings described above:
1. There is no software limit on the number of items that can be saved in memcached. In the past, my 1 million statement was incorrect.
2. Assume that the newhashAlgorithmUniform collision. The number of cycles for searching items is the total number of items divided by the hashtable size (determined by hashpower), which is linear.
3. memcached limits the maximum acceptable item to be 1 MB. Data larger than 1 MB is ignored.
4. memcached's space utilization is closely related to the data characteristics, and also to the dont_prealloc_slabs constant. In the worst case, 198 slab will be wasted (all items are concentrated in one slab, and 199 IDs are fully allocated ).
Other articles about memcached
Http://tech.idv2.com/2008/07/10/memcached-001/
Http://www.ooso.net/archives/558
Http://blog.myspace.cn/e/401447849.htm
Http://blog.csdn.net/binger819623/archive/2008/12/10/3489062.aspx