Home >Backend Development >PHP Tutorial >Detailed tutorial on adding and setting up php extension xcache in win7

Detailed tutorial on adding and setting up php extension xcache in win7

WBOY
WBOYOriginal
2016-07-25 08:52:291104browse
Regarding the method of adding and setting the xcache extension for PHP in the win7 system, the installation and configuration tutorial of xcache, the file/variable hash reference value of the xcache.slots cache, you can set it according to your actual situation, and friends who need it can refer to it. xcache 3.2.0, which is supported by the full range of php5, official website: http://xcache.lighttpd.net/

If you are not good at English, you can click on the right to switch the language to Chinese.

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

Download and unzip it and put it in the ext directory under php, then open php.ini and add extension = php_xcache.dll

The compressed package also contains a demonstration of the Chinese version of xcache's php.ini, and a program to view xcache and information.

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, you can set it according to your actual situation

Once completed, restart the apache service.

;; This file is just an example, please set it in php.ini for it to take effect [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) ; Log in using $your_password. Please encrypt the password with md5 and fill it in. xcache.admin.pass = "" [xcache] ; Most of the options here can only be modified in the ini. The default values ​​listed here are unless otherwise stated. ; Select the underlying memory sharing implementation solution xcache.shm_scheme = "mmap" ; Disabled: xcache.size=0 ; Enable: xcache.size=64m and the like (any value >0) Also please pay attention to your system mmap upper limit xcache.size = 60m ; It is recommended to set it to the number of cpu (cat /proc/cpuinfo |grep -c processor) xcache.count = 1 ; It's just a hash reference value, the actual storage items (php scripts/variables) can exceed this number xcache.slots = 8k ; ttl of cached items, 0=permanent xcache.ttl = 0 ; The time interval for scanning expired items, 0=no scanning, other values ​​are in seconds xcache.gc_interval = 0 ; Same as above, only for variable cache settings xcache.var_size = 4m xcache.var_count = 1 xcache.var_slots = 8k ; Default value of xcache_*() function ttl parameter xcache.var_ttl = 0 ; Limit xcache_*() function ttl parameters to no more than this setting. 0=No limit 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 rather than a directory. (Automatically created/overwritten) ; If you wish to enable readonlyprotection, you must avoid using "/dev/*" and use something like "/tmp/xcache" ; Different php process groups will not share the same /tmp/xcache ; For win32 systems, xcache.mmap_path=anonymous map name, not file path. It is recommended to use the word xcache to avoid conflicts with other software xcache.mmap_path = "/dev/zero" ; Only useful when xcache exceptions occur. Set to empty (disabled) or similar to "/tmp/phpcore/" (can be written to files by php) 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 exception occurs xcache.disable_on_crash = off ; Enable experimental features (if any) xcache.experimental=off ; The following are request-level settings that can be changed. Can be ini_set, .htaccess, etc. xcache.cacher = on xcache.stat = on xcache.optimizer = off [xcache.coverager] ; This function will reduce operating performance after it is turned on. ; This feature will only be enabled when xcache.coverager == on && xcache.coveragedump_directory == "non-null value" ; per request settings. Can be ini_set, .htaccess, etc. ; Enable code process coverage information collection and functions such as xcache_coverager_start/stop/get/clean() xcache.coverager = off xcache.coverager_autostart = on ; Only set within php ini files ; Please ensure that this directory can be read by the coverage viewer script (note open_basedir) xcache.coveragedump_directory = ""

Then check phpinfo to see if xcache has taken effect. As shown below

Now create a new directory such as xcache in the web publishing directory, and put the lib and htdocs directories in the official compressed package inside,

Enter http://127.0.0.1/xcache/htdocs/ in the browser, and a login account and password dialog box will pop up. After entering it, you can see the xcache environment and configuration, variables, etc. .

But in fact, xcache can not only cache variables, but also cache php files. If the xcache extension is configured in your php environment, it will automatically cache every php file you access. There is no need to modify the code, it is very convenient and fast. As shown in the picture below, I only accessed phpmyadmin, and the official xcache package can detect the cache list of phpmyadmin.

The code is very simple, with singleton mode and can be used directly in the application environment. The code has been 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 starts------------------ ----------------**/ class cache_xcache { /*** Instantiate this class in singleton mode * * @var object*/ protected static $_instance = null; /***Default caching strategy * * @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 mixed $value cache value * @param integer $expire lifetime * * @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 the cache and return false if it fails or the cache is invalid. * * @access public * * @param string $key cache key * * @return mixed*/ public function get($key) { //Parameter analysis if (!$key) { return false; } return xcache_isset($key) ? xcache_get($key) : false; } /*** Cache a variable to data storage * * @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); } /*** Clear all cache variables * * @access public * @return boolean*/ public function clear() { return xcache_clear_cache(xc_type_var, 0); } /*** Singleton mode * * Used for singleton instantiation of this class * * @access public * @return object*/ public static function getinstance() { if (!self::$_instance) { self::$_instance = new self(); } return self::$_instance; } }


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn