About APC
APC, known as alternative PHP cache, is an open source PHP plugin for caching PHP code or user data.
APC Cache of PHP code
APC can get rid of PHP dynamic parsing and compile time, PHP script can execute faster. Here's a good illustration of why APC can make PHP scripts run faster.
PHP is a dynamic scripting language, so in order for the user to see the page content in the browser, the server must parse the PHP code to generate the HTML code it wants to use. As can be seen from the above figure, in the absence of APC, the user on the PHP page every request, the server needs to be parsed, compiled and executed PHP, but many times, as long as the PHP code has not changed, PHP's execution logic will not change, This means that the parsing and compiling process can be omitted, executed directly and then returned to the result. This is the work of APC, which caches PHP's executable code, eliminating parsing and compiling, and speeding up the execution of PHP scripts.
The APC caches the user data and
In addition to caching PHP code, APC can also be used to cache user data, but because the APC capacity is very small, so the cached data is best for those long time unchanged data, unchanged units should be in the space units. So if the data is changing very frequently and the amount of data is large, then do not use APC, you can use Memcache or Redis.
Here is a comparison test experiment with APC and Redis to see the efficiency comparisons between APC and Redis.
function Gettimestamp () { $timestr = Microtime (); $timestrary = Explode (' ', $timestr); $result = Intval ($timestrary [1]) *1000 + intval (floatval ($timestrary [0]) *1000); return $result;} $redis = new Redis (), $redis->connect (' 127.0.0.1 ', 6379), $key = ' key '; $value = ' value '; $redis->set ($key, $value); C4/>apc_store ($key, $value, 1); $begin = Gettimestamp (); for ($i = 0; $i < 100000; $i = $i + 1) { $result = Apc_fetch ($key);} $cost = Gettimestamp () -$begin; Var_dump ($cost); $begin = Gettimestamp (); for ($i = 0; $i < 100000; $i = $i + 1) { $result = $redis->get ($key);} $cost = Gettimestamp ()-$begin; Var_dump ($cost); $redis->close ();
are simple to take data operations, respectively, 100,000 times, the unit is milliseconds. The final result of the operation is REDIS10 read in 4-5 seconds, and APC has 100,000 reads only about 50 milliseconds. You can see that if you are simply caching some data, and the data does not change and hits, APC can bring some efficiency gains.
When installing APC, there will be a apc.php page where you can view the APC hits from this page. Such as
Configuration of APC
Examples of configuration are as follows:
extension= apc.so Apc.enabled=1apc.shm_segments=1 apc.shm_size=64m; The size of the APC memory, the final size needs to multiply the number of segments, so there is a total of APC assigned 64M apc.ttl=7200 Apc.user_ttl=7200apc.enable_cli=1; If this is not enabled, APC can only be operated on the Web page and cannot be operated via the CLI.
reference
HTTP://WWW.INMOTIONHOSTING.COM/SUPPORT/WEBSITE/WHAT-IS/SPEED-UP-PHP-WITH-APC
http://bbs.phpchina.com/thread-202432-1-1.html
Copyright notice: This article is a blogger original article, not No reprint is permitted by the blogger.
The above describes the PHP APC cache and the comparison with Redis, including aspects of the content, you want to be interested in PHP tutorial friends helpful.