: This article mainly introduces how to use Memcache to cache files rather than directly using File files ?, If you are interested in the PHP Tutorial, refer. Use a local environment to test 0.1 million and 1 million cached reads and writes. the test environment and results are as follows.
Environment
Win7 x64 AMD7750 dual-core memory 8 GApache 2.4.9PHP 5.5.12 ts vc11 memcache 2.2.7
Code
Connect ('2017. 0.0.1 ', 11211); $ data = $ mem-> get ($ key); if (empty ($ data )) {$ data = date ('Y-m-d H: I: s'); $ mem-> set ($ key, $ data);} return $ data ;} $ t1 = microtime (true); $ I = 0; $ limit = 1000*100; // 0.1 million times $ data = null; while ($ I <$ limit) {// $ data = cacheFile ($ I); $ data = cacheMem ($ I); $ I ++ ;}$ timeUse = microtime (true)-$ t1; $ arr = ['cost' => sprintf ('%. 7fs ', $ timeUse), 'mem' => convert (memory_get_usage ()]; var_dump ($ arr );
Result 10 thousand times
Time-consuming memory: File 1.9sec250kbMemcache 11sec250kb
Result 0.1 million times
Time-consuming memory File94s 251.18 KBMemcache timeout 120 s error
Memcache failed to perform the test for 0.1 million times. The error message is as follows:
Warning: Memcache::connect(): in D:\localhost\speed.php online37Warning: Memcache::get(): No servers added to memcache connection in D:\localhost\speed.phpWarning: Memcache::set(): No servers added to memcache connection in D:\localhost\speed.php online41Fatal error: Maximum execution timeof120seconds exceeded in D:\localhost\speed.php online38
Conclusion
memcache
The cache is used for caching but File files are not directly cached. the reason for this test is that during the interview, I replied that I did not use this memcache for caching, directly use the File cache (a single server), and the result is directly recognizedCainiao
. But I passed this test, although it is under win, why is Memcahe performance inferior to File?
Or is there an error in my testing method? Solving default.fu@foxmail.com
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
As mentioned above, why is Memcache better than direct File cache ?, Including some content, hope to be helpful to friends who are interested in PHP tutorials.