Basic PHP-APC Usage
Jul 16, 2015
apc
is an in memory cache for PHP applications. It is similar to memcached
.
Installing php-apc
-
Install Alternative PHP Cache
apt-get install php-apc
-
Edit the apc configuration file
nano /etc/php5/conf.d/20-apc.ini
You can increase the shm_size to something like 128 if you have enough memory.
extension=apc.so
apc.enabled=1
apc.shm_size=16
apc.write_lock=1
- Restart php-fpm
/etc/init.d/php5-fpm restart
Code http://www.php.net/manual/en/ref.apc.php
<?php
apc_store('key', 'value');
var_dump(apc_fetch('key'));
?>
How about an array?
<?php
apc_store('key', array('value 1', 'value 2'));
var_dump(apc_fetch('key'));
?>
Clearing the cache.
apc_clear_cache();
Or delete a specific key.
apc_delete('key');