First, PHPAPC installation
Download and unzip the installation package:
Copy CodeThe code is as follows:
Wget-c http://pecl.php.net/get/APC-3.1.13.tgz
TAR-ZVXF apc-3.1.13.tgz
cdAPC-3.1.13
Compile and install:
Copy CodeThe code is as follows:
Wget-c http://pecl.php.net/get/APC-3.1.13.tgz
/usr/local/php/bin/phpize
./CONFIGURE--ENABLE-APC--enable-mmap--enable-apc-spinlocks--disable-apc-pthreadmutex--with-php-config=/usr/ Local/php/bin/php-config
Make
Sudomake Install
Modify PHP.ini Join:
Copy CodeThe code is as follows:
Extension= "apc.so";
; Apcsetting
Apc.enabled= 1
Apc.shm_segments= 1
Apc.shm_size= 64M
Apc.optimization= 1
apc.num_files_hint= 0
Apc.ttl= 0
Apc.gc_ttl= 3600
apc.cache_by_default= on
Restart Apache or/usr/local/php/sbin/php-fpmrestart
Second, PHPAPC configuration options
[APC]
; Alternative PHP cache for caching and optimizing PHP intermediate code
apc.cache_by_default= on
; whether buffering is enabled for all files by default.
; If set to off and used with the apc.filters instruction with the plus sign, the file is cached only when matching the filter.
apc.enable_cli= Off
If APC is enabled for the CLI version, this instruction is only opened for testing and debugging purposes.
apc.enabled= on
, whether APC is enabled, and if APC is statically compiled into PHP and wants to disable it, this is the only way.
apc.file_update_protection= 2
When you modify a file on a running server, you should perform atomic operations.
, which is to write a temporary file, then rename the file (MV) to the final name.
The text editor and Cp,tar programs do not work this way, resulting in the possibility of buffering incomplete files.
The default value of 2 means that the file is not buffered if it finds that the modification time is less than 2 seconds from the access time.
The unfortunate visitor may get incomplete content, but the bad effect is not amplified by the cache.
If you can ensure that all update operations are atomic, you can turn this feature off with 0.
If your system is slow to update due to a large number of IO operations, you need to increase this value.
apc.filters=
A comma-delimited list of POSIX extended regular expressions.
If the source file name matches any one of the patterns, the file is not cached.
Note that the filename used to match is the file name passed to Include/require, not the absolute path.
If the first character of a regular expression is "+" it means that any file matching the expression is cached.
If the first character is "-" then no match will be cached. "-" is the default value and can be omitted.
apc.ttl= 0
The number of seconds the cache entry is allowed to stay in the buffer. 0 means never time out. The recommended value is 7200~36000.
; set to 0 means that the buffer may be filled with old cache entries, resulting in the inability to cache new entries.
apc.user_ttl= 0
, similar to Apc.ttl, the recommended value is 7200~36000 for each user.
; set to 0 means that the buffer may be filled with old cache entries, resulting in the inability to cache new entries.
Apc.gc_ttl= 3600
The number of seconds that a cache entry can exist in the garbage collection table.
This value provides a security measure, even if a server process crashes while executing the cached source file.
, and the source file has been modified, and the memory allocated for the old version is not recycled until this TTL value is reached.
; set to zero disables this attribute.
apc.include_once_override= Off
Please keep it off, otherwise it may result in unexpected results.
Apc.max_file_size= 1M
Prohibit files larger than this size from being cached.
apc.mmap_file_mask=
If you have compiled MMAP support for APC using –ENABLE-MMAP (enabled by default),
The value here is the Mktemp-style file mask passed to the Mmap module (the recommended value is "/TMP/APC. XXXXXX ").
The mask is used to determine if the memory-mapped area is to be file-backed or sharedmemory backed.
For direct file-backed memory mapping, set to "/TMP/APC". XXXXXX "(exactly 6 x).
To use the POSIX-style shm_open/mmap, it needs to be set to "/apc.shm.xxxxxx".
You can also set the "/dev/zero" to use the kernel's "/dev/zero" interface for memory that is mapped anonymously.
; undefined this directive means that anonymous mappings are enforced.
apc.num_files_hint= 1000
; Approximate number of different source files that may be included or requested on the Web server (recommended value is 1024~4096).
If you are unsure, set to 0; This setting is used primarily for sites that have thousands of source files.
apc.optimization= 0
; Optimization level (recommended value is 0).
The positive integer value indicates that the optimizer is enabled, and the higher the value, the more aggressive the optimization is used.
Higher values may have a very limited speed boost, but are still being tested.
apc.report_autofilter= Off
Whether to log all scripts that are automatically not cached for early/latebinding reasons.
apc.shm_segments= 1
; The number of shared memory blocks allocated for the compiler buffer (recommended value is 1).
If APC runs out of shared memory, and the apc.shm_size instruction is set to the maximum allowed by the system,
; You can try increasing this value.
apc.shm_size= 30
; The size of each shared memory block (in megabytes, the recommended value is 128~256).
Some systems, including most BSD variants, have very few default shared memory block sizes.
apc.slam_defense= 0
;(against the use of the directive, it is recommended that the Apc.write_lock directive be used)
On a very busy server, whether it's starting a service or modifying a file,
, it is possible that a race condition is caused by multiple processes attempting to cache a file at the same time.
This directive is used to set the percentage of the process that skips cache steps when processing files that are not cached.
For example, set to 75 indicates that there is a 75% probability of not caching when a file is not cached, thus reducing the chance of collisions.
; encourage set to zero to disable this feature.
apc.stat= on
; whether to enable the script update check.
Change the command value to be very careful.
The default value on indicates that APC checks that the script is updated every time the script is requested.
, and automatically recompile and cache the compiled content if it is updated. But doing so has a detrimental effect on performance.
, if set to off means no checks, resulting in a significant performance gain.
But in order for the updated content to take effect, you must restart the Web server.
This command is also valid for Include/require files. But it's important to note that
If you are using a relative path, APC must check each time Include/require to locate the file.
, and the absolute path allows you to skip the check, so you are encouraged to use an absolute path for include/require operations.
apc.user_entries_hint= 100
, similar to the Num_files_hint directive, only for each different user.
If you are not sure, set to 0.
apc.write_lock= on
, whether write locks are enabled.
On a very busy server, whether it's starting a service or modifying a file,
, it is possible that a race condition is caused by multiple processes attempting to cache a file at the same time.
Enable this directive to avoid the appearance of competitive conditions.
apc.rfc1867= Off
After you open the directive, for each file field that happens to contain the
Three, PHP_APC function
Apc_add-Cache a variable to data store
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-Clear APC Cache
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-delete a variable from the user cache
apc_exists-Check if there is some or some key in APC
Apc_fetch-Remove stored variables from the cache
Apc_inc-Increment 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
Iv. Use of PHPAPC
Example using the APC cache (test_apc_cache.php):
Copy CodeThe code is as follows:
Error_reporting (E_all);
Classapcinit {
/**
*APC Cache-Set Cache
* Set cache Key,value and cache time
* @param string $key key value
* @param string $value value
* @param string $time cache time
*/
publicstatic function Set_cache ($key, $value, $time = 0) {
if ($time = = 0) $time = null; Null in the case of a permanent cache
Returnapc_store ($key, $value, $time);
}
/**
*APC Cache-Get Cache
* Get cached data from key
* @param string $key key value
*/
publicstatic function Get_cache ($key) {
Returnapc_fetch ($key);
}
/**
*APC Cache-Clears a cache
* Delete a cache from Memcache
* @param string $key key value
*/
publicstatic function Clear ($key) {
Returnapc_delete ($key);
}
/**
*APC Cache-Empty all caches
* It is not recommended to use this feature
* @return
*/
publicstatic function Clear_all () {
Returnapc_clear_cache (); Clear Cache
}
/**
* Check if APC cache exists
* @param string $key key value
*/
publicstatic function exists ($key) {
Returnapc_exists ($key);
}
/**
* Field self-increment-for counting
* @param string $key key value
* @param int $step New Step value
*/
Publicstatic Function Inc ($key, $step) {
Returnapc_inc ($key, (int) $step);
}
/**
* Field auto minus-for counting
* @param string $key key value
* @param int $step New Step value
*/
publicstatic function Dec ($key, $step) {
Returnapc_dec ($key, (int) $step);
}
/**
* Cache files
*/
publicstatic function Cache_file ($file) {
Returnapc_compile_file ($file);
}
/**
* Return APC Cache information
*/
publicstatic function info () {
Returnapc_cache_info ();
}
}
Apc_clear_cache ();
Apcinit::cache_file ("hessianutils.php");
Apcinit::cache_file ("hessian1parser.php");
Apcinit::cache_file ("hessian1writer.php");
Apcinit::cache_file ("hessianstream.php");
Apcinit::cache_file ("hessianparsing.php");
Apcinit::cache_file ("hessianexceptions.php");
Include_once "./hessianutils.php";
Include_once "./hessian1parser.php";
Include_once "./hessian1writer.php";
Include_once "./hessianstream.php";
Include_once "./hessianparsing.php";
Include_once "./hessianexceptions.php";
Header ("Content-type:text/html;charset=utf-8");
Header ("Cache-control:private,max-age=0,no-cache");
$HessianWriter = new Hessian1writer ();
$array = Array (1, 2, 3, Array (' SFF ', ' Zhang San '));
Parser
$resolver = new Hessianruleresolver ('./hessian1rules.php ');
Parse array
$parser _array= New Hessian1parser ($resolver, Newhessianstream ($HessianWriter->writevalue ($array)));
Print_r ($parser _array->parse ());
?>
v. PHPAPC Monitoring and Management
APC provides apc.php for monitoring and managing the APC cache. Put apc.php in the site directory, modify the account number, password, you can monitor and manage the APC cache through the browser.
Apc.php 41st, 42 line:
Copy CodeThe code is as follows:
Defaults (' Admin_username ', ' APC ');//ADMIN USERNAME
Defaults (' Admin_password ', ' PASSWORD '); Admin password-change this to ENABLE!!!
http://www.bkjia.com/PHPjc/327572.html www.bkjia.com true http://www.bkjia.com/PHPjc/327572.html techarticle First, PHPAPC installation download and unzip the installation package: Copy code code as follows: Wget-c http://pecl.php.net/get/APC-3.1.13.tgz tar-zvxf apc-3.1.13.tgz cdAPC-3.1.13 Compile and install: Copy code ...