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. ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| 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 connectionMemcache::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 |
| |||
| 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 |
| |||
| 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 |
| |||
| 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’) ) ; |
| |||
| 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... |
| |||
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |