This time I will bring you an analysis of the installation and use cases of the PHP caching tool XCache. What are the precautions for the installation and use of the PHP caching tool
XCache is another Opcode caching tool used in PHP. Like APC, XCache stores opcodes in shared memory and uses the cached opcodes to respond to requests for PHP scripts.
Install XCache on Windows system
1. At http://xcache.lighttpd.net/pub/ReleaseArchive according to your PHP version, download the corresponding software package.
2. After decompression, copy php_xcache.dll to the ext directory
3. Add
[XCache] Zend_extension_ts=php_xcache.dall
to the PHP.ini file on the Liunx system Install XCache
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 the modificationzend_extension = /usr/lib64/php/modules/xcache. so is the correct path.
XCache settings
xcache.admin.user (String) Management authentication user name. The default setting is "mOo"
xcache.admin.pass (String) management authentication password. The default setting is "
xcache.admin.enable_auth (String) Enables or disables authentication for the admin site. The default value is "on"
xcache.test (String) Enable or disable the test function
xcache.coredump_dir (String) The directory where the core dump is placed when a failure is encountered. Must be a directory writable by PHP. Leave empty with table disabled
xcache.cacher (Boolean) Enable or disable Opcode cache. Enabled by default
xcache.size (int) The size of all shared caches. If 0, the cache will not be able to use
xcache.count (int) The number of "chunks" the cache is divided into. Default value 1
xcache.slots Hash table hint. The larger the number, the faster the search occurs within the hash table. The higher this value is, the more memory is required
xcache.ttl (int) The survival time of the Opcode file. 0=Indefinite cache
xcache.gc_interval (seconds) The time interval for triggering garbage collection. 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) Survival of variable data Time, default setting 0
xcache.var_maxttl (seconds) Maximum survival time when processing variables
xcache.var_gc_interval (seconds) Lifetime of garbage collection
xcache.readonly_protection (Boolean) Available when ReadonlyProtection is enabled.
xcache.mmap_path (String) File path for read-only protection. This will restrict two PHP groups from sharing the same /tmp/cache directory
xcache.optimizer (Boolean) Enable or disable optimization Disabled by default
xcache.coverager (Boolean) Enable coverage Dataset combine.
xcache.coveragerdump_directory (String) The directory location where the data collection information is placed. The default directory /tmp/pcovis
Instance
reference www.initphp.com framework Xcache class
<?php if (!defined('IS_INITPHP')) exit('Access Denied!'); /********************************************************************************* * InitPHP 2.0 国产PHP开发框架 Dao-XCACHE缓存 *------------------------------------------------------------------------------- * 版权所有: CopyRight By initphp.com * 您可以自由使用该源码,但是在使用过程中,请保留作者信息。尊重他人劳动成果就是尊重自己 *------------------------------------------------------------------------------- * $Author:zhuli * $Dtime:2011-10-09 ***********************************************************************************/ class xcacheInit { /** * Xcache缓存-设置缓存 * 设置缓存key,value和缓存时间 * @param string $key KEY值 * @param string $value 值 * @param string $time 缓存时间 */ public function set_cache($key, $value, $time = 0) { return xcache_set($key, $value, $time);; } /** * Xcache缓存-获取缓存 * 通过KEY获取缓存数据 * @param string $key KEY值 */ public function get_cache($key) { return xcache_get($key); } /** * Xcache缓存-清除一个缓存 * 从memcache中删除一条缓存 * @param string $key KEY值 */ public function clear($key) { return xcache_unset($key); } /** * Xcache缓存-清空所有缓存 * 不建议使用该功能 * @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验证是否存在 * @param string $key KEY值 */ public function exists($key) { return xcache_isset($key); } }
believe it After reading the case in this article, you have mastered the method. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
Detailed explanation of PHP mongoDB database operation steps
Querying the PHP string to contain the specified data
The above is the detailed content of PHP caching tool XCache installation and use case analysis. For more information, please follow other related articles on the PHP Chinese website!