Note that zend guard must be used to encrypt the PHP file before it is uploaded to the server. If apc is used, it is unnecessary. For Messages seen from Wikipedia, apc will be built into php6, so apc is worth learning.
1. Install Extension
In ubuntu 12.04, you can directly install the apc extension through apt-get install php-apc.
For windows systems, I have installed apc in windows before, but the operation is unstable. I don't know if it is solved now. In windows, you can use wincache to replace apc. It is very stable and developed by Microsoft.
Tips: After the installation is complete, remember to restart the web server.
2. Download apc. php
: Apc_php.zip
The apc. php script can be used to view the usage of apc. The interface is as follows:
There are two tabs for you to pay attention:
1 System Cache Entries: This indicates that the System Cache option is used to Cache the intermediate codes of some PHP files.
2 User Cache Entries: indicates the Cache of User data. In encoding, User data can be cached to apc. To view the user data cache, you must first modify the access account and password. Open the apc. php file and find the following two lines of code to modify it:
Copy codeThe Code is as follows:
Ults ('admin _ username', 'apc '); // ADMIN USERNAME
Ults ('admin _ password', 'Password'); // admin password-change this to enable !!!
3. apc example
Apc is easy to use. See the following examples for adding, querying, modifying, and deleting.
Add a cache, valid for 3600 seconds
Copy codeThe Code is as follows:
Apc_add ('name', 'Tom, 3600 );
Run the code and view the User Cache Entries. You can see that the Cache data with a key value of name is added:
Including the number of hits, size, expiration time, and so on.
Query Cache
Copy codeThe Code is as follows:
Apc_add ('name', 'Tom, 3600 );
Print apc_fetch ('name'); // output tom
Modify Cache
Copy codeThe Code is as follows:
Apc_store ('name', 'anny ', 3600 );
Print apc_fetch ('name'); // output anny
Delete Cache
Copy codeThe Code is as follows:
Apc_delete ('name ');
Var_dump (apc_fetch ('name'); // output bool (false)
Progressively decreasing number
If the cached content is a number, you can use apc _ inc to auto-increment 1 and apc_dec to auto-increment 1.
Copy codeThe Code is as follows:
Apc_add ('num', 10 );
Apc_inc ('num ');
Print apc_fetch ('num'); // output 11
Apc_dec ('num ');
Print apc_fetch ('num'); // output 10
Determine whether the cache exists
Copy codeThe Code is as follows:
Apc_add ('name', 'Tom, 3600 );
Var_dump (apc_exists ('name'); // output bool (true)
Var_dump (apc_exists ('age'); // bool (false)