Win7 Adding and setting up PHP extensions XCache tutorial

Source: Internet
Author: User
For Win7 system to add and set XCache extension method for PHP, XCache installation and configuration tutorial, xcache.slots cache file/variable hash reference value, according to their actual situation can be set, the need for friends reference. XCache 3.2.0, it is php5 full range of support, the official website: http://xcache.lighttpd.net/

If the English is not good friends, you can click on the right to switch languages to Chinese.

First, download the latest version: Http://xcache.lighttpd.net/pub/releases/3.2.0/Remember to choose the correct version.

Download the unzip and put it under the Ext directory under PHP, then open php.ini add extension = Php_xcache.dll

The compression package also has a Chinese version of the XCache php.ini demonstration, there is a view xcache and information procedures.

Note xcache.admin.pass is stored with MD5 encryption

Xcache.count can be set according to the number of your CPU, default is 1

Xcache.slots cached File/variable hash reference value, according to their actual situation can be set

When you are finished, restart the Apache service.

;; This document is only an example, please set it in php.ini for entry into force [Xcache-common];; Non-windows example: 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 $your _password The following password please use MD5 encryption after filling in Xcache.admin.pass = "" [XCache]; Most of the options here can be modified only in the INI, the default values are listed here, unless otherwise stated; Select the underlying memory sharing implementation scheme Xcache.shm_scheme = "mmap"; Disabled: xcache.size=0; Enable: xcache.size=64m (value of any >0) Also note that your system mmap upper limit xcache.size = 60m; Recommended set to number of CPUs (Cat/proc/cpuinfo |grep-c processor) Xcache.count = 1; Just a hash reference value, the actual storage item (PHP script/variable) can exceed this number xcache.slots = 8k; Cache item TTL, 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 the variable cache setting Xcache.var_size = 4m Xcache.var_count = 1 xcache.var_slots = 8k; The default value of the Xcache_* () function ttl parameter is Xcache.var_ttl = 0; The limit xcache_* () function TTL parameter does not exceed this setting. 0= does not limit xcache.var_maxttl = 0 Xcache.var_gc_interval = 300; /dev/zero invalid xcache.readonly_protection = off; For *nix Systems, Xcache.mmap_path is the file path andis not a directory. (Automatically created/overwritten); If you expect to enable readonlyprotection, you must avoid using "/dev/*", which can use similar "/tmp/xcache"; Different PHP process groups will not share the same/tmp/xcache; For the Win32 system, xcache.mmap_path= anonymous map name, not the file path. It is recommended to use XCache Word to avoid conflicts with other software Xcache.mmap_path = "/dev/zero"; Useful only when XCache an exception. Set to null (disabled) or similar to "/tmp/phpcore/" (can be written to the file by PHP) xcache.coredump_directory = ""; For Windows only. Leave the default value Xcache.coredump_type = 0 unless the XCache developer tells you; Automatically disable cache Xcache.disable_on_crash = off when exception occurs; Enable experimental functionality (if any) xcache.experimental = off; The following are the request level settings that can be changed. Can be ini_set,. htaccess, etc. xcache.cacher = on xcache.stat = on xcache.optimizer = off [Xcache.coverager]; When the function is turned on, it reduces the running performance; This function is only enabled when Xcache.coverager = = on && xcache.coveragedump_directory = = "Non-null value"; Per request settings. Can Ini_set,. htaccess, etc.; Enable code flow coverage information acquisition and Xcache_coverager_start/stop/get/clean () functions Xcache.coverager = off xcache.coverager_autostart = on; Set only within the PHP INI file; Please ensure that this directory can be read by Coverage Viewer script (note open_basedir) xcache.coveragedump_directory = ""

Then check phpinfo to see if XCache is already in effect. Such as

Now create a new directory in the Web publishing directory such as XCache, the official compressed package in the Lib and Htdocs directory inside,

In the browser input http://127.0.0.1/xcache/htdocs/, will pop up a login password dialog box, entered, 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 you configure the PHP environment XCache extension, it will automatically every time you access the PHP file automatically cached. No need to modify the code, it is very convenient and fast, such as I only visit the Phpmyadmin,xcache official package can detect the phpMyAdmin cache list.

The code is simple, with a singleton pattern that can be used directly in the application environment, and the code is perfectly tested in php5.5.12.

$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 start----------------------------------**/class Cache_xcache {/** * Singleton pattern Instantiation of this class * * @ var object */protected static $_instance = NULL; /** * Default Cache policy * * @var array */protected $_defaultoptions = Array (' expire ' = 900); /** * Construction Method * * @access Public * @return Boolean */Public function __construct () {//Parse XCache extension if (!extension_loaded (' X Cache ') {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_nu LL ($expire)? $this->_defaultoptions[' expire '): $expire; Return Xcache_set ($key, $value, $expire); } /** * Read cache, failure or cache scatter fails to return FALSE * * @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 datastore * * @acce SS Public * * @param string $key Data key * @param mixed $value data value * @param int $expire cache time (seconds) * @return Boolean */Publi C 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 Parse if (! $key) {return false;} return Xcache_unset ($key); /** * Empty All cache variables * * @access public * @return Boolean */Public Function clear () {return Xcache_clear_cache (Xc_type_var, 0); }/** * Singleton mode * * for singleton mode (singleton) instantiation of this class * * @access Public * @return Object */public static FUnction getinstance () {if (!self::$_instance) {self::$_instance = new self ();} return self::$_instance;}}
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.