IT Community - Software Programming, Web Development and Technical Support

memcache in PHP

This is a discussion on memcache in PHP within the PHP Programming forums, part of the Web Development category; Guys, Can any one explain how to use memcache in PHP? I would need installation procedures too. Thanks in advance. ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-16-2007, 06:27 AM
DuraiBabu DuraiBabu is offline
Super Moderator
 
Join Date: Feb 2007
Posts: 2
DuraiBabu is on a distinguished road
Question memcache in PHP

Guys,
Can any one explain how to use memcache in PHP? I would need installation procedures too.

Thanks in advance.

Durai.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-16-2007, 06:49 AM
raj raj is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 89
raj is on a distinguished road
Default Re: memcache in PHP

hi all,

memcached is a high-performance, distributed memory object caching system.

used to store and retrieve cached data from distributed cached servers.

It can connect to a memcache server from a list of servers to store and retrieve cached data.

The memcache server that it connects depends on identifier of the key use to access each cached data item. So, data items are cached in different servers to distribute the load.


memcache methods:

Memcache::add -- Add an item to the server
Memcache::close -- Close memcached server connection
Memcache::connect -- Open memcached server connection
memcache_debug -- Turn debug output on/off
Memcache::decrement -- Decrement item's value
Memcache::delete -- Delete item from the server
Memcache::flush -- Flush all existing items at the server
Memcache::get -- Retrieve item from the server
Memcache::getStats -- Get statistics of the server
Memcache::getVersion -- Return version of the server
Memcache::increment -- Increment item's value
Memcache:connect -- Open memcached server persistent connection
Memcache::replace -- Replace value of the existing item
Memcache::set -- Store data at the server


eg code:

//create instance for memcache
$memcache = memcache_connect('host', 11211);

// to store value to memcache
$memcache->set("str_key", "String to store in memcached");

// to get the stored value from memcache
$vFromCache = $memcache->get('str_key');


Installation in command line option:

# ./memcached -d -m 2048 -l 10.0.0.40 -p 11211
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-16-2007, 07:08 AM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,162
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: memcache in PHP

hi raj,
this article is very nice and very useful to reduce the weight of the web server to load more items to be displayed at same time
it seems that memchache is used as virtual memory or memory mediator.
am i correct?
can we have to connect some 5 memcache servers with one web server?

is there any api is to be installed for enabling this?
__________________
With,
J. Jeyaseelan

Everything Possible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-16-2007, 07:19 AM
raj raj is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 89
raj is on a distinguished road
Default Re: memcache in PHP

hi,

1. we can use more than 5 servers for memcache.

$options["servers"] => we can give number of memcache servers by an array

eg:

$options["servers"] = array("10.0.0.15:11000","10.0.0.16:11001");
$memc = new MemCachedClient($options);

$memc = new MemCachedClient($options);


2. we need to install API memcache.

-> Api & More information you can see from this site

memcached: a distributed memory object caching system
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-18-2007, 12:54 AM
senraj senraj is offline
D-Web Master
 
Join Date: Jul 2007
Posts: 418
senraj is on a distinguished road
Post Re: memcache in PHP

Memcache main purpose decrease database load in dynamic web applications.

Example:

Site viewed by more than 100 users simultaneously, a lot of memory
will be loosed for saving the search results as arrays, and you need to execute the database query again and again.

If you can save the intermediate array after the queriying and execution for a particular period of time, you can reuse this array for further queries for a particular period. The php function memcache is using for this purpose.

$a = array(1,2,3,4,5);

$mmc = new Memcache;

$mmc->connect(’127.0.0.1′ ,11211 ) or die (”Could not Connect”);

echo $mmc->getVersion();

$mmc->set(’myarray’,$a, false, 60); // the value will be saved with key
array for 60 seconds
print_r ( $mmc->get(’myarray’) ) ;
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 07-18-2007, 01:17 AM
Sabari Sabari is offline
D-Web Genius
 
Join Date: Jul 2007
Posts: 1,008
Sabari is on a distinguished road
Default Re: memcache in PHP

here i listed the memcached installation steps ....

#!/bin/sh

##
# Install memcached and dependencies smoothly on Mac OS X.
#
# Newer versions of these libraries are available and may work better on Mac OS X.
#
# See also http://topfunky.net/svn/shovel/memca...ached-linux.sh
#
# USE AT YOUR OWN RISK.
#
# AUTHOR: Geoffrey Grosenbach Nuby on Rails | Ruby on Rails for Newbies
#
# Some fixes are from Fast memcached on OS X
#
# AFTER RUNNING THIS SCRIPT:
#
# Set the environment variable EVENT_NOKQUEUE to 1
# * csh and derivatives: setenv EVENT_NOKQUEUE 1
# * sh and derivatives (like bash): export EVENT_NOKQUEUE=1
#
# You may also need to add /usr/local to your PATH.
#

PREFIX=/usr/local

mkdir src
cd src

# Install libevent dependency
curl -O http://www.monkey.org/~provos/libevent-1.1b.tar.gz
tar xfz libevent-1.1b.tar.gz
cd libevent-1.1b
./configure --prefix=${PREFIX} && make
sudo make install
cd ..

# Install memcached and fixes
curl -O http://www.danga.com/memcached/dist/...-1.1.12.tar.gz
tar xfz memcached-1.1.12.tar.gz
cd memcached-1.1.12
./configure --prefix=${PREFIX}

# in Makefile
# LDFLAGS = -L/lib
# LDFLAGS = -L${libdir}
sed -e 's/-L\/lib/-L${libdir}/' Makefile > Makefile.new
mv Makefile.new Makefile

# also in Makefile
# CFLAGS = -g -O2 -I/include
# CFLAGS = -g -O2 -I${includedir}
sed -e 's/-I\/include/-I${includedir}/' Makefile > Makefile.new
mv Makefile.new Makefile

# insert in memcached.c...
# #undef TCP_NOPUSH
# #ifdef TCP_NOPUSH
curl -O http://topfunky.net/svn/shovel/memca...memcached_c.rb
ruby fixmemcached_c.rb > memcached.c.new
mv memcached.c.new memcached.c

make
sudo make install
cd ../..

echo "Installation complete. Please add EVENT_NOKQUEUE=1 to your shell environment."
__________________
Thanks & Regards
Sabari...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 07-18-2007, 01:43 AM
raj raj is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 89
raj is on a distinguished road
Default Re: memcache in PHP

hi,


Refer this link:

Installing memcached | Development, Analysis And Research
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to delete memcache? Kamalakannan PHP Programming 11 10-26-2007 12:30 AM
memcache commands and behavior prasath Database Support 4 09-27-2007 01:04 AM
Phpaccelerator & Memcache sivaramakrishnan PHP Programming 0 08-31-2007 08:59 AM
Memcache with Mysql write2ashokkumar Database Support 0 08-02-2007 03:41 AM


All times are GMT -7. The time now is 06:37 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0