php5.4 Distributed Cache Memcache (windows7 installation configuration)

Source: Internet
Author: User
Tags add command line header ini connect sql version port number


I. Installation of Memcache


memcached installation problem on Windows7 now install package: http://www.jb51.net/softs/44843.html Memcache installation package error: Access to D:\webEve\ via cmd command line memcached (Download the extract directory) run memcached.exe-d install error "Failed to install service or service already installed" solution: Www.2cto . COM Administrator Identity installation, first find Cmd.exe the original file right click to run as an administrator, then OK (Win7 users under the real trouble).
Memcache installation under Windows: 1. Download Memcache's Windows stable version, unzip it under a disk, for example, at D:\webEve\memcached 2. In the terminal (also known as the cmd Command interface), enter ' D:\webEve\memcached\memcached.exe-d Install ' installation 3. Re-enter: "D:\webEve\memcached\memcached.exe-d start" started. Note: Later memcached will start automatically every time a service is powered on as windows. This way the server side is already installed. 4. Download Php_memcache.dll, please find the corresponding PHP version of the file 5. In php.ini, add a line of ' Extension=php_memcache.dll ' 6. Restart Apache, and then look at the phpinfo, if there is memcache, then the installation is successful! Basic settings for memcached:-P-Listening Port-L-connected IP address, default is native-D-Start memcached service-D Restart Restart memcached service-D stopshutdown shutdown running Memcache D Service-D install install memcached service www.2cto.com-d Uninstall Uninstall memcached Service----you run as (only when run as root)-m maximum memory usage, in MB. The default 64mb-m returns an error when memory runs out instead of deleting item-C maximum simultaneous connections, default is 1024-f block size growth factor, default is 1.25-n minimum allocation space, key+value+flags default is 48-h display Help


Php_memcached.dll CSDN Resources



Php_memcached.dll CSDN Resources


Second, installs the memcache to carry on the memcached in the PHP extension configuration


Php_memcached.dll CSDN Resources


Paste opening extension in php.ini and place this file in Ext extension file now memcache OK can use, to try!
-->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 "
";

Var_dump ($test _key);

echo "
";
echo "";
$sql = MD5 ($sql);
$mem = new Memcache; Instantiating a Memcache object
$mem->connect ("192.168.1.134", 11211); Connection to local IP 11211 is the memcache port number
$mem->set ($sql, $test _key, memcache_compressed, 600); The $test_key array is stored in the key value of $sql Note: memcache cache good data, there is the time to live, the default will be a child expired, of course, you can set an expiration time, 600 is $sql this key value corresponding to the survival time
echo "
";

Print_r ($mem->get ($sql));                      Gets the value of the key value of $sql

echo "
";

?>

Case TWO:
-->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 (); Empty cached data
$mem->add ("hehe", "Memcahce"); Set value of hehe for key value is Memcache
echo $mem->get ("hehe"), ""; To read a value with a key value of hehe
echo "
";



echo "
";
?>


At this point, memcache you can basically use, how to apply to your site?


first, the encapsulation of a memcache instantiation class, and then make the call, the Web site to , the Advanced Memcache cache read, if read, that is, the use of read data, display to the page, this time does not operate the database, save a lot of time Ah! If you do not read the data from the cache, that is, manipulate the database fetch!
That is, first and memcache to the data, if not to read the database, pay attention to read, immediately saved to the Memcache


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.