Home  >  Article  >  php教程  >  How to configure and use memcached cache in Yii

How to configure and use memcached cache in Yii

高洛峰
高洛峰Original
2016-12-30 16:38:441460browse

The example in this article describes how to configure and use memcached cache in Yii. Share it with everyone for your reference, the details are as follows:

1. Download the memcached software package, unzip it, and put memcached.exe in any place, such as: d:/memcached/.

2. Start->Run->Enter cmd, open memcached.exe on the command line, in the folder where it is located, enter: memcached.exe -d install Installation

3. Enter memcached. exe -d start Start

4. Add extension=php_memcache.dll.

5. Open the yii configuration file: config/main.php, and add under components:

'memcache'=>array(
    'class'=>'CMemCache',
    'servers'=>array(
      array(
        'host'=>'127.0.0.1',
        'port'=>11211,
        'weight'=>60,
      ),
      array(
        'host'=>'127.0.0.1',
        'port'=>11211,
        'weight'=>40,
      ),
    ),
 ),

6. Use:

Yii::app()->memcache->get(id);
Yii::app()->memcache->set(id,value,time);

I hope this article will help everyone based on Yii Frameworks for PHP programming help.

For more articles related to Yii configuration and using memcached cache, please pay attention to the PHP Chinese website!

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