PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, November 13, 2022

[FIXED] How to store an object in Memcache and how to retrieve it using PHP

 November 13, 2022     memcached, php     No comments   

Issue

I am doing a project using MVC architecture. I am maintaining all the values in session. One of my senior developer tell me that it is not a right procedure to do and he suggest me store all the values in cache.

Is he right? If yes, how can I do that using php...


Solution

Memcache is not the answer for everything, but can dramatically increase page loads for web applications that have lots of load.

The concept is to store your data as key-value pairs in memory (a memcache) and retrieve the data using a key whenever necessary.

Here is a quick example of setting and retrieving data from memcache in PHP:

$memcache = new Memcache;
$memcache->connect('192.168.1.2', 11211) or die ("Unable to connect");
$memcache->set(‘key1’, 'value1');   // Set some data
$memcache->get('key1');  // Get some data

Read up on some of this:

http://papermashup.com/using-memcache-with-php/

http://fschiettecatte.wordpress.com/2008/05/15/to-use-or-not-to-use-memcached-that-is-the-question/

http://www.majordojo.com/2007/03/memcached-howto.php

Good luck, let me know if you have any more questions



Answered By - Philoxopher
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing