PHP Cache Tool XCache Installation and Use Method Detailed Explanation

  • 2021-09-20 19:43:15
  • OfStack

In this paper, the installation and use of PHP cache tool XCache are described as examples. Share it for your reference, as follows:

XCache is another Opcode caching tool used in PHP. Like APC1, XCache stores Opcode in shared memory and uses cached Opcode to respond to requests for PHP footsteps.

Installing XCache on an Windows system

1. Download the corresponding software package according to your PHP version at http://xcache.lighttpd.net/pub/ReleaseArchive.

2. Copy php_xcache. dll to the ext directory after unzipping

3. Add in the PHP. ini file


[XCache]
Zend_extension_ts=php_xcache.dall

Installing XCache on Liunx system


wget http://xcache.lighttpd.net/pub/Releases/1.3.2/xcache-1.3.2.tar.gz
tar -zxvf xcache-1.3.2.tar.gz
cd xcache-1.3.2
phpize
./configure --enable-xcache
make
make install doc.codesky.net

Open the php. ini file and add the following code:


[xcache-common]
; change me - 64 bit php => /usr/lib64/php/modules/xcache.so
; 32 bit php => /usr/lib/php/modules/xcache.so
zend_extension = /usr/lib64/php/modules/xcache.so
[xcache.admin]
xcache.admin.auth = On
xcache.admin.user = "mOo"
; xcache.admin.pass = md5($your_password)
xcache.admin.pass = ""
[xcache]
xcache.shm_scheme =    "mmap"
xcache.size =        32M
xcache.count =         1
xcache.slots =        8K
xcache.ttl  =       3600
xcache.gc_interval =     300
; Same as aboves but for variable cache
; If you don't know for sure that you need this, you probably don't
xcache.var_size =      0M
xcache.var_count =       1
xcache.var_slots =      8K
xcache.var_ttl  =       0
xcache.var_maxttl  =     0
xcache.var_gc_interval =   300
; N/A for /dev/zero
xcache.readonly_protection = Off
xcache.mmap_path =  "/dev/zero"
xcache.cacher =        On
xcache.stat  =        On

Note that zend_extension = /usr/lib64/php/modules/xcache. so is modified to the correct path.

XCache Settings

xcache. admin. user (String) admin authentication user name. Default setting "mOo"
xcache. admin. pass (String) manages authentication passwords. The default setting is " < empty string > ". This value should be MD5 (your password)
xcache. admin. enable_auth (String) enables or disables authentication for administrative sites. Default value "on"
xcache. test (String) Enables or disables testing
xcache. coredump_dir (String) The directory where the core dump is placed in the event of a failure. Must be an PHP writable directory. Leave blank with table disabled
xcache. cacher (Boolean) Enables or disables Opcode caching. Open by default
xcache. size (int) Size of all shared caches. If 0, the cache will not be available
xcache. count (int) caches the number of "blocks" that are split. Default value 1
xcache. slots hash table hint. The larger the number, the faster the search speed in the hash table. The higher this value, the more memory is required
xcache. ttl (int) Opcode file lifetime. 0 = indefinite cache
xcache. gc_interval (seconds) The interval at which garbage collection is triggered. Default 0
xcache.var_size (int) variable size
xcache. var_count (int) Number of variables
xcache.var_slots Variable Data Slot Settings
xcache. var_ttl (seconds) Time to live for variable data, default setting is 0
xcache. var_maxttl (seconds) Maximum time to live when processing variables
xcache. var_gc_interval (seconds) Time to live for garbage collection
xcache. readonly_protection (Boolean) is available when ReadonlyProtection is enabled.
xcache. mmap_path (String) is the file path for read-only protection. This restricts two PHP groups from sharing the same the/tmp/cache directory
xcache. optimizer (Boolean) Enables or disables tuning default disable
xcache. coverager (Boolean) enables coverage data sets.
xcache. coveragerdump_directory (String) Directory location where data collection information is placed. Default usage directory/tmp/pcovis

Instances

Reference to www. initphp. com Framework Xcache Class


<?php
if (!defined('IS_INITPHP')) exit('Access Denied!');
/*********************************************************************************
 * InitPHP 2.0  Domestic PHP Development framework  Dao-XCACHE Cache 
 *-------------------------------------------------------------------------------
 *  Copyright reserved : CopyRight By initphp.com
 *  You are free to use the source code, but please keep the author information during use. Respecting the fruits of others' labor means respecting yourself 
 *-------------------------------------------------------------------------------
 * $Author:zhuli
 * $Dtime:2011-10-09
***********************************************************************************/
class xcacheInit {
  /**
   * Xcache Cache - Setting cache 
   *  Setting cache key , value And cache time 
   * @param string $key  KEY Value 
   * @param string $value  Value 
   * @param string $time  Cache time 
   */
  public function set_cache($key, $value, $time = 0) {
    return xcache_set($key, $value, $time);;
  }
  /**
   * Xcache Cache - Get the cache 
   *  Pass KEY Get cached data 
   * @param string $key  KEY Value 
   */
  public function get_cache($key) {
    return xcache_get($key);
  }
  /**
   * Xcache Cache - Clear 1 Cache 
   *  From memcache Delete in 1 Bar cache 
   * @param string $key  KEY Value 
   */
  public function clear($key) {
    return xcache_unset($key);
  }
  /**
   * Xcache Cache - Empty all caches 
   *  This feature is not recommended 
   * @return
   */
  public function clear_all() {
    $tmp['user'] = isset($_SERVER['PHP_AUTH_USER']) ? null : $_SERVER['PHP_AUTH_USER'];
    $tmp['pwd'] = isset($_SERVER['PHP_AUTH_PW']) ? null : $_SERVER['PHP_AUTH_PW'];
    $_SERVER['PHP_AUTH_USER'] = $this->authUser;
    $_SERVER['PHP_AUTH_PW'] = $this->authPwd;
    $max = xcache_count(XC_TYPE_VAR);
    for ($i = 0; $i < $max; $i++) {
      xcache_clear_cache(XC_TYPE_VAR, $i);
    }
    $_SERVER['PHP_AUTH_USER'] = $tmp['user'];
    $_SERVER['PHP_AUTH_PW'] = $tmp['pwd'];
    return true;
  }
  /**
   * Xcache Verify whether it exists 
   * @param string $key  KEY Value 
   */
  public function exists($key) {
    return xcache_isset($key);
  }
}

For more readers interested in PHP related contents, please check the topics on this site: "Summary of php Cache Technology", "Introduction to php Object-Oriented Programming", "Introduction to PHP Basic Grammar", "Encyclopedia of PHP Array (Array) Operation Skills", "Summary of php String (string) Usage", "Introduction to php+mysql Database Operation" and "Summary of php Common Database Operation Skills"

I hope this paper is helpful to everyone's PHP programming.


Related articles: