下一章 上一章 目录 设置
8、第 8 章 ...
-
Alternative PHP Cache(可选PHP缓存)
■简介
■安装/配置
■需求
■安装
■运行时配置
■资源类型
■预定义常量
■APC 函数
■apc_add — 缓存一个变量到数据存储
■apc_bin_dump — Get a binary dump of the given files and user variables
■apc_bin_dumpfile — Output a binary dump of cached files and user variables to a file
■apc_bin_load — Load a binary dump into the APC file/user cache
■apc_bin_loadfile — Load a binary dump from a file into the APC file/user cache
■apc_cache_info — Retrieves cached information from APC's data store
■apc_cas — Updates an old value with a new value
■apc_clear_cache — 清除APC缓存
■apc_compile_file — Stores a file in the bytecode cache, bypassing all filters.
■apc_dec — Decrease a stored number
■apc_define_constants — Defines a set of constants for retrieval and mass-definition
■apc_delete_file — Deletes files from the opcode cache
■apc_delete — Removes a stored variable from the cache
■apc_exists — 检查APC中是否存在某个或者某些key
■apc_fetch — 从缓存中取出存储的变量
■apc_inc — Increase a stored number
■apc_load_constants — Loads a set of constants from the cache
■apc_sma_info — Retrieves APC's Shared Memory Allocation information
■apc_store — Cache a variable in the data store
■APCIterator — The APCIterator class
■APCIterator::__construct — Constructs an APCIterator iterator object
■APCIterator::current — Get current item
■APCIterator::getTotalCount — Get total count
■APCIterator::getTotalHits — Get total cache hits
■APCIterator::getTotalSize — Get total cache size
■APCIterator::key — Get iterator key
■APCIterator::next — Move pointer to next item
■APCIterator::rewind — Rewinds iterator
■APCIterator::valid — Checks if current position is valid
--------------------------------------------------------------------------------
影响 PHP 行为的扩展简介影响 PHP 行为的扩展
在线手册:中文英文PHP手册
用户评论:
umut dot kirgoz at gmail dot com (26-Sep-2011 03:32)
Since APC 3.1.3, there is a bug (http://pecl.php.net/bugs/bug.phpid=16814) which produces warnings like "Potential Cache Slam Averted for Key" when slam defense is on and you're trying to write a key that already exists.
These is not a fix right now for this, but you can change the APC settings from php.ini file like below if possible:
apc.write_lock = 1
apc.slam_defense = 0
ddascalescu+php dot net at gmail dot com (20-Jun-2011 05:57)
On Debian/Ubuntu, there is a ready-made APC package:
sudo aptitude install php-apc
bugzilla33 at gmail dot com (06-Sep-2010 04:25)
Attention:
APC 3.1.4 does not work with files in PHAR archives.
phar:// stream wrappers including by require funcion are not cached.
hello at haroonahmad dot co dot uk (16-Jun-2009 06:57)
Disclaimer: i do not guarantee it will work for you so you better use it at your own risk. It works for me.
* I am using # symbol for all shell commands
I am posting a quick step-by-step guide to install APC on servers (dedicated or VPS) with cpanel/whm working.
First login as a root to your server/vps and make a directory to work with this plugin,
#mkdir /home/APC-php
#cd /home/APC-php
now here we will first download the APC with following command
#wget http://pecl.php.net/get/APC-3.0.14.tgz
you can check for the latest version
now you can use gzip and tar separately or tar -xzvf to unzip this file
#tar -xzvf APC-3.0.14.tgz
now you will have a APC-3.0.14 folder.
#cd APC-3.0.14
now you have to make php configuration files by following command
#phpize
after this use following three commands
#./configure --enable-apc --enable-apc-mmap --with-apxs --with-php-config=/usr/bin/php-config
*if you do not know the php path then execute ( which php ) command it will display the path. on a typical cpanel vps it could be /usr/bin/php-config or /usr/local/bin/php-config but you better check it before executing the above command)
#make
#make test
#make install
NOTE: if you are using suPHP then skip --with-apxs
*one more thing, if you use
#make test
command it shows 3 tests failed then do not worry, it showed at least to me but worked with the final steps.
the (make install) command will return the apc.so module path, note down that with you as you will have to feed it in the php.ini file in the next step.
check your php.ini location by
#php -i | grep php.ini
then open it with your favorite editor. mine was at
#vi /usr/local/lib/php.ini
and go to the last line and paste the following
extension="apc.so"
now there is a catch in it, if you have other modules installed and their extension directory is different than the one MAKE INSTALL showed for APC so you have to move your apc.so to that directory so that all modules are in the same directory. in my case my APC directory was
/usr/lib/php/extensions/no-debug-non-zts-20060613/
but i moved apc.so from this location to my other location where my other extensions.so files were.
you can check that path in php.ini sectiion of
extension_dir = ""
after this restart your apache, for different servers it may vary mine worked with
#service httpd restart
if everything works fine it will restart apache without showing any error. in case of any error, roll back your php.ini changes and restart apache and discuss your problem in some forum or email me at hello@haroonahmad.co.uk
now check the phpinfo() output in your browser and it will display APC version information etc. for command line you might do
php -i | grep apc
I hope it helps.
Haroon Ahmad