The XCache project is headed by MOo, who is also one of LIGHTTPD's development members. LIGHTTPD is one of the fastest Web server applications and transcends Apache as well as many other Web servers. XCache try to achieve a similar effect.
The latest version is XCache 3.2.0, which is php5 full range of support, official website: http://xcache.lighttpd.net/
If the English bad friend, can point to the right switch language for Chinese.
First download the latest version: Http://xcache.lighttpd.net/pub/Releases/3.2.0/Remember to choose the correct version.
After the download decompression, put it under the Ext directory under PHP, and then open php.ini add extension = Php_xcache.dll
The package also has a Chinese version of the XCache php.ini demonstration, there is a view of xcache and information procedures.
Note that Xcache.admin.pass is encrypted with MD5 and stored
Xcache.count can be set according to the number of your CPU, the default is 1
Xcache.slots cached File/variable hash reference value, depending on your actual situation can be set
When you are done, restart the Apache service.
Copy Code code as follows:
;; This document is just an example, please set in php.ini to take effect
[Xcache-common]
;; Non-Windows examples:
Extension = xcache.so
;; Windows System Example:
; Extension = Php_xcache.dll
[Xcache.admin]
Xcache.admin.enable_auth = On
Xcache.admin.user = "MOo"
; Xcache.admin.pass = MD5 ($ your password)
; Login using the password below $your _password please use MD5 to fill in the inside
Xcache.admin.pass = ""
[XCache]
; Most of the options here can only be modified in INI, and here are the default values, unless otherwise stated
; Select the underlying memory sharing implementation scenario
Xcache.shm_scheme = "Mmap"
; Disabling: xcache.size=0
; Enable: xcache.size=64m (any >0 value) Please also note that your system mmap upper limit
Xcache.size = 60M
; Recommended set to CPU number (Cat/proc/cpuinfo |GREP-C processor)
Xcache.count = 1
; Just a hash reference value, the actual storage project (PHP script/variable) can exceed this number
Xcache.slots = 8K
; The TTL for the cached item, 0 = Permanent
Xcache.ttl = 0
; Time interval for scanning expired items, 0 = Not scanned, other values in seconds
Xcache.gc_interval = 0
; Ditto, just for variable caching settings
Xcache.var_size = 4M
Xcache.var_count = 1
Xcache.var_slots = 8K
; Default value for Xcache_* () function ttl parameter
Xcache.var_ttl = 0
; Limit xcache_* () function TTL parameter does not exceed this setting. 0= not Limited
Xcache.var_maxttl = 0
Xcache.var_gc_interval = 300
; Invalid when/dev/zero
Xcache.readonly_protection = Off
; For *nix Systems, Xcache.mmap_path is a file path and not a directory. (Auto Create/overwrite)
; If you expect to enable readonlyprotection, you must avoid using "/dev/*" and you can use a similar "/tmp/xcache"
; Different PHP process groups do not share the same/tmp/xcache
; For the WIN32 system, the xcache.mmap_path= anonymous map name, not the file path. Suggest using XCache Word to avoid conflict with other software
Xcache.mmap_path = "/dev/zero"
; Useful only when XCache exceptions. Set to null (disabled) or similar to "/tmp/phpcore/" (can be written to PHP files)
Xcache.coredump_directory = ""
; For Windows only. Unless the XCache developer tells you otherwise, keep the default value
Xcache.coredump_type = 0
; Automatically disable caching when exceptions
Xcache.disable_on_crash = Off
; Enable experimental features (if any)
Xcache.experimental = Off
; Here is the Request level can be changed. Can Ini_set,. htaccess, etc.
Xcache.cacher = On
Xcache.stat = On
Xcache.optimizer = Off
[Xcache.coverager]
; This feature is turned on to reduce the running performance
; This feature is enabled only if Xcache.coverager = = on && xcache.coveragedump_directory = "Non-null value"
; Per request settings. Can Ini_set,. htaccess, etc.
; Enable code flow coverage information collection and functions such as Xcache_coverager_start/stop/get/clean ()
Xcache.coverager = Off
Xcache.coverager_autostart = On
; Set in PHP INI file only
; Please make sure this catalog is readable by the Coverage Viewer script (note open_basedir)
Xcache.coveragedump_directory = ""
Then check phpinfo to see if XCache is in effect. The following figure
Now create a new directory in the Web publishing directory like XCache, put the Lib and htdocs directory inside the official ZIP package,
In the browser input http://127.0.0.1/xcache/htdocs/, will pop up a login Account password dialog box, input, you can see the XCache environment and configuration, variables and so on.
But in fact xcache not only can cache variables, but also can cache PHP files, if your PHP environment is configured with XCache extensions, it will automatically every time you access the PHP file automatically cached. No additional changes to the code, very convenient and quick, the following figure I only visited the Phpmyadmin,xcache official package can detect the phpMyAdmin cache list.
The code is simple, with a single case pattern, can be used directly in the application environment, the code in the php5.5.12 perfect test pass.
Copy Code code as follows:
$c =new Cache_xcache ();
$c->set (' key ', ' aaaa123 ');
echo $c->get (' key ');
Cache_xcache::getinstance ()->set (' Key1 ', ' 999999999999999 ');
Echo cache_xcache::getinstance ()->get (' Key1 ');
/**------------------------------Code starts----------------------------------**/
Class Cache_xcache {
/**
* Singleton mode instantiation of this class
*
* @var Object
*/
protected static $_instance = NULL;
/**
* Default Caching policy
*
* @var Array
*/
Protected $_defaultoptions = Array (' expire ' => 900);
/**
* Construction Method
*
* @access Public
* @return Boolean
*/
Public Function __construct () {
Analyze XCache Extension Module if (!extension_loaded (' XCache ')) {
Die (' The xcache extension to be loaded before use! ');
}
return true;
}
/**
* Write Cache
*
* @access Public
*
* @param string $key cache key
* @param mixted $value Cache value
* @param integer $expire life cycle
*
* @return Boolean
*/
Public function set ($key, $value, $expire = null) {
Parameter analysis if (! $key) {
return false;
}
$expire = Is_null ($expire)? $this->_defaultoptions[' expire ']: $expire;
Return Xcache_set ($key, $value, $expire);
}
/**
* Read cache, False when failed or cached scatter invalid
*
* @access Public
*
* @param string $key cache key
*
* @return mixted
*/
Public function Get ($key) {
Parameter analysis if (! $key) {
return false;
}
Return Xcache_isset ($key)? Xcache_get ($key): false;
}
/**
* Cache A variable to the data store
*
* @access Public
*
* @param string $key Data key
* @param mixed $value data value
* @param int $expire cache time (seconds)
*
* @return Boolean
*/
Public function Add ($key, $value, $expire = null) {
Parameter analysis if (! $key) {
return false;
}
$expire = Is_null ($expire)? $this->_defaultoptions[' expire ']: $expire;
Return!xcache_isset ($key)? $this->set ($key, $value, $expire): false;
}
/**
* Delete the specified cache
*
* @access Public
*
* @param string $key cache key
*
* @return Boolean
*/
Public Function Delete ($key) {
Parameter analysis if (! $key) {
return false;
}
Return Xcache_unset ($key);
}
/**
* Empty all cached variables
*
* @access Public
* @return Boolean
*/
Public Function Clear () {
Return Xcache_clear_cache (Xc_type_var, 0);
}
/**
* Single case mode
*
* Singleton mode (singleton) instantiation for this class
*
* @access Public
* @return Object
*/
public static function getinstance () {
if (!self::$_instance) {
Self::$_instance = new self ();
}
return self::$_instance;
}
}