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 Installation:
Copy Code code 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 Code code 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 to enable buffering for all files by default.
If set to off and used with a apc.filters instruction that starts with a plus sign, the file is cached only when the filter is matched.
apc.enable_cli= off
Whether the APC feature is enabled for the CLI version and is opened for testing and debugging purposes only.
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 an atomic operation.
To write a temporary file, then rename the file (MV) to the final name.
, text editors and Cp,tar programs do not do this, resulting in the possibility of buffering the defective file.
; The default value of 2 indicates that when the file is accessed, no buffer is found if the modified time distance is less than 2 seconds.
, the unfortunate visitor may get the incomplete content, but the bad effect will not be magnified through the cache.
If you can ensure that all update operations are atomic, you can turn off this attribute 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 schemas, the file is not cached.
Note that the file name that is used to match is the filename passed to Include/require, not the absolute path.
If the first character of the regular expression is "+" means that any file that matches the expression is cached.
If the first character is "-", no matches are cached. "-" is the default value and can be omitted.
apc.ttl= 0
The number of seconds the cache entry allowed to linger in the buffer. 0 means never times out. The recommended value is 7200~36000.
; set to 0 means that the buffer is likely to 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 is likely to be filled with old cache entries, resulting in the inability to cache new entries.
Apc.gc_ttl= 3600
The number of seconds the 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 will not be reclaimed until this TTL value is reached.
; set to zero disables this attribute.
apc.include_once_override= off
, keep off, or you may cause unexpected results.
apc.max_file_size= 1M
; Prevents files larger than this size from being cached.
apc.mmap_file_mask=
If you have compiled MMAP support for APC using –ENABLE-MMAP (default enabled),
The value here is the Mktemp-style file mask passed to the Mmap module (the recommended value is "/TMP/APC.") XXXXXX ").
The mask used to determine whether the memory-mapped area is to be file-backed or sharedmemory backed.
For direct file-backed memory mappings, set to/TMP/APC. XXXXXX "appearance (exactly 6 x).
To use POSIX-style shm_open/mmap, you need to set it to "/apc.shm.xxxxxx."
You can also set the "/dev/zero" to use the kernel's "/dev/zero" interface for anonymous mapped memory.
; This directive is not defined to force the use of anonymous mappings.
apc.num_files_hint= 1000
; The approximate number of different source files that may be included or requested on the Web server (the recommended value is 1024~4096).
If you are unsure, set to 0; This setting is primarily used for sites that have thousands of source files.
apc.optimization= 0
; Optimization level (recommended value is 0).
; A positive integer value indicates that the optimizer is enabled, and the higher the value, the more aggressive optimization is used.
Higher values may have very limited speed increases, 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 (the recommended value is 1).
If the APC runs out of shared memory and the Apc.shm_size directive is set to the maximum allowed by the system,
; You can try to increase 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 a very small default shared memory block size.
apc.slam_defense= 0
;(objected to the use of the directive and suggested that the Apc.write_lock directive be used)
; On a very busy server, whether you start a service or modify a file,
may result in competitive conditions because multiple processes attempt to cache a single file at the same time.
This directive is used to set the percentage of steps that the process skips when processing files that are not cached.
, for example, set to 75 means that there is a 75% probability of not caching when the file is encountered, thereby reducing the collision probability.
Encourage setting to 0来 disable this feature.
apc.stat= on
; Whether to enable script update checking.
Change the instruction value to be very careful.
; The default value on means that the APC checks whether the script is updated each time the script is requested.
, and the compiled content is automatically recompiled and cached if it is updated. But doing so has a detrimental effect on performance.
If set to OFF, the performance is significantly improved by not checking.
, but you must restart the Web server to make the updated content effective.
; This directive is also valid for Include/require files. But it should be noted that
If you are using a relative path, the APC must check every time include/require to locate the file.
While using absolute paths you can skip checks, so you are encouraged to use absolute paths for include/require operations.
apc.user_entries_hint= 100
; Similar to the Num_files_hint directive, just for each individual user.
If you are unsure, set to 0.
apc.write_lock= on
Whether write locks are enabled.
; On a very busy server, whether you start a service or modify a file,
may result in competitive conditions because multiple processes attempt to cache a single file at the same time.
To enable this directive to avoid the emergence of competitive conditions.
apc.rfc1867= off
; After you open the directive, for each containing exactly the same before the file field
Three, PHP_APC function
Apc_add-Cache A variable to the 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-Remove a variable from the user cache
apc_exists-Check the APC for the presence of one or some key
Apc_fetch-Take the stored variables out of the cache
Apc_inc-Increments a stored number
apc_load_constants-loads a set of constants from the cache
Apc_sma_info-retrieves APC Shared Memory allocation information
Apc_store-cache a variable in the data store
Iv. Use of PHPAPC
Example of using APC caching (test_apc_cache.php):
Copy Code code as follows:
<?php
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; Permanent cache in case of NULL
Returnapc_store ($key, $value, $time);
}
/**
*APC Cache-Get Cache
* Get cached data through key
* @param string $key key value
*/
publicstatic function Get_cache ($key) {
Returnapc_fetch ($key);
}
/**
*APC Cache-Clears a cache
* Remove a cache from the 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 for APC cache presence
* @param string $key key value
*/
publicstatic function exists ($key) {
Returnapc_exists ($key);
}
/**
* Field self-used for counting
* @param string $key key value
* @param int $step The new step value
*/
Publicstatic Function Inc ($key, $step) {
Returnapc_inc ($key, (int) $step);
}
/**
* Field self-minus-for counting
* @param string $key key value
* @param int $step The 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 ', ' John '));
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. Apc.php will be placed in the site directory, modify the account number, password, you can monitor and manage the APC cache through the browser.
Apc.php Line 41st and 42:
Copy Code code as follows:
Defaults (' Admin_username ', ' APC ');/ADMIN USERNAME
Defaults (' Admin_password ', ' PASSWORD '); Admin password-change this to ENABLE!!!