Installation of memcache and configuration and testing in YII framework

Source: Internet
Author: User

Installing the Php_memcache.dll Extension

1. First put the Php_memcache.dll file in the E:\server\php\ext directory

(php_memcache.dll:http://windows.php.net/downloads/pecl/releases/memcache/3.0.8/)
Be sure to download the appropriate php_memcache.dll,thread based on your PHP version and Thread safety safety
Phpinfo () view, enabled for TS version, or NTS version



2. Modify the php.ini file

First determine if the Extension_dir is consistent with the directory where the extension file is placed (that is, the Php_memcache.dll location), and then
Add Extension=php_memcache.dll, and finally restart Apache, you can see Memcache in Phpinfo.


3. CMD Open command

Enter as Administrator (can enter as Administrator in C:\Windows\System32\cmd.exe),
Put the memcached.exe in the root of your code and run it in a small black window:
D://Enter your Memcached.exe disk
Memcached.exe-d Install//Perform installation memcached
memcached.exe-d Start//Start command
Netstat-an//View open item

4. Place the following code in the YII framework common/main.php

' Components ' = [
' Cache ' = [
' Class ' = ' Yii\caching\memcache ',
' Servers ' = [
[
' Host ' = ' server1 ',
' Port ' = 11211,
' Weight ' = 100,
],
[
' Host ' = ' Server2 ',
' Port ' = 11211,
' Weight ' = 50,
],
],
],
],

5. Create the file in your project root directory, enter the following code

This is the controller inside to load

Use Yii\caching\memcache;

Public Function Actionindex ()
{
Echo Phpinfo ();

Instantiate the Memcache class
$memcache = new Memcache;
$memcache->set (' 123 ', ' 234 ');
echo $memcache->get (' 123 ');
}

If the output is as follows
234

Is installed correctly

Installation of memcache and configuration and testing in YII framework

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.