Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
397 views
in Technique[技术] by (71.8m points)

memcached - How to use memcache with php

I am new to this memcache stuff. I read that it saves lot of time of page load time by caching the database key. I have my php application and I want to use memcache as it takes too much time for my application to retrieve the whole set of results from database.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Steps to take: Prerequisite: read the manual (at least a bit): http://php.net/manual/en/book.memcache.php and make sure you've got memcached installed.

1 Start the memcached program so there is a server that actually stores the key-value pairs.

2 Make a memcache object

3 Store a value for a key

4 Retrieve your key.

$memcache = new Memcache; //point 2. 
$memcache->set($yourUniqueKey,  $yourValue, false, 3600); //point 3
//later:
$memcache->get($yourUniqueKey); //point 4.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...