Distributed cache memcache for php5.4 (installation and configuration under windows 7)_PHP tutorial

WBOY
Release: 2016-07-13 10:22:51
Original
820 people have browsed it

Distributed cache memcache of php5.4 (installation and configuration under windows 7)

1. Install memcache

Memcached installation problems on windows7 Now install the package: http://www.jb51.net/softs/44843.html memcache installation package mistake: Enter D:webEvememcached (the decompressed directory after downloading) through the cmd command line Run memcached.exe -d install Error "failed to install service or service already installed" Solution: www.Bkjia.com To install as an administrator, first find the original file of cmd.exe Right-click and run as administrator, then OK (users under win7 are really troublesome).
Memcache installation under Windows: 1. Download the Windows stable version of memcache, unzip it and put it under a certain disk, such as D:webEvememcached 2. Enter ‘D:webEvememcachedmemcached.exe -d install’ in the terminal (i.e. cmd command interface) to install 3. Then enter: 'D:webEvememcachedmemcached.exe -d start' to start. NOTE: In the future, memcached will be automatically started as a service of Windows every time you boot up. The server side has now been installed. 4. Download php_memcache.dll, please find the corresponding php version file yourself. 5. Add a line ‘extension=php_memcache.dll’ to php.ini 6. Restart Apache, and then check phpinfo. If there is memcache, it means the installation is successful! Basic settings of memcached: -p listening port -l The IP address of the connection, the default is the local machine -d start starts the memcached service -d restart restarts the memcached service -d stop|shutdown shut down the running memcached service -d install install memcached service www.Bkjia.com -d uninstall uninstall memcached service -u Run as (only valid when running as root) -m Maximum memory usage, in MB. Default 64MB -M Return an error when memory is exhausted instead of deleting items -c Maximum number of simultaneous connections, default is 1024 -f block size growth factor, default is 1.25 -n minimum allocated space, key+value+flags defaults to 48 -h show help

php_memcached.dll csdn resource

php_memcached.dll csdn resource

2. Install memcache and configure memcached extension in php

php_memcached.dll csdn resource

Paste in php.ini to enable the extension and put this file into the ext extension file. Now memcache is ok and can be used. Let’s try it!
header("Content-type:text/html;charset=utf-8");
$host = '127.0.0.1:3306';
$user = 'root';
$passwd = '';
$db = 'test';
$conn = mysql_connect($host,$user,$passwd);
mysql_select_db($db,$conn);
mysql_query("set names utf8",$conn);
$sql = 'select * from syl_rollback order by id desc';
$result = mysql_query($sql,$conn);
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)){
$test_key[] = $row;
}
echo "
";<br>
var_dump($test_key);<br>
echo "
Copy after login
";
echo "
";
$sql = md5($sql);
$mem = new Memcache; //Instantiate memcache object
$mem->connect("192.168.1.134", 11211); //Connect to local ip 11211 is the port number of memcache
$mem->set($sql,$test_key, MEMCACHE_COMPRESSED, 600); //Store the $test_key array in the key value $sql. Note: Memcache cached data has a survival time and will expire in one hour by default. Of course You can set an expiration time yourself. 600 is the survival time corresponding to the key value $sql
echo "
";<br>
print_r($mem->get($sql));                      //获取键&#20540;为$sql的&#20540;<br>
echo "
Copy after login
";

?>

Example 2:
header("Content-type:text/html;charset=utf8");

$sql = 'select * from syl_rollback order by id desc';

$sql = md5($sql);
$mem = new Memcache;
$mem->connect("192.168.1.134", 11211);
//$mem->flush(); //Clear the cached data
$mem->add("hehe","memcahce"); //Set the value of the key value hehe to memcache
echo $mem->get("hehe"),"
"; //Read the value with the key value hehe
echo "
";<br>
print_r($mem->get($sql)); <br>
echo "
Copy after login
";
?>

At this point, you can basically use memcache. How to apply it to your website?

First, encapsulate a memcache instantiated class, and then make a call. When obtaining data from the website, it is read from the advanced memcache cache. If it is read, the read data is used to display it on the page. This There is no need to operate the database at this time, which saves a lot of time! If there is no need to read the data from the cache, operate the database to obtain it!


That is to say, you need to ask memcache for data first. If you don’t go to the database to read it, pay attention to saving it to memcache immediately after reading it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/845439.htmlTechArticleDistributed cache memcache for php5.4 (installation configuration under windows7) 1. Install memcache Installation of memcached on windows7 The problem is to install the package now: http://www.jb51.net/softs/44843.html mem...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!