SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2002
    Location
    Sydney, Australia
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Removing the use of memcache

    To cut a long story short, I've recently purchased a Facebook application because:

    1. I can see that I can add some more features and make it more popular, and

    2. treat it as a learning exercise for PHP and Facebook application design.

    Before purchase I checked that it was written in PHP5 with a MySQL database and that it was currently working in Facebook BUT because my PHP experience is almost nothing I didn't realise that the app uses memcache and my current hosting (bluehost) doesn't seem to use memcache installed in PHP

    So at this moment I'm wanting to get rid of the memcache dependency in the app, but how do I do that ? I've tried commenting out the memcache lines but that didn't fix it.

    Any advice would be great, I'm talking to the app author as well but he's (literally) on the other side of the world so contact is patchy.

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In theory, if memcache was used properly (that is, as a cache), having the function calls to it always return false/null should do the trick.
    HTML Purifier - Standards-Compliant HTML filtering

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2002
    Location
    Sydney, Australia
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I get an error when these lines are executed :

    $memcache = new Memcache;
    $memcache->connect($memcache_host, $memcache_port) or die ('Memcache connection failed');


    The error is:

    Fatal error: Class 'Memcache' not found in .... (filename & line) of the "new Memcache" statement.

  4. #4
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    365
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try add this code to the script
    PHP Code:
    <?php

    if(! class_exists('MemCache'false))
    {
        class 
    MemCache
        
    {
            
    //Add an item to the server
            
    function add  $key  $var  ,  $flag =  null ,  $expire =null  )
            {
            return 
    FALSE;
            }
        
            
    //Add a memcached server to connection pool
            
    function addServer$host  ,  $port 11211  ,  $persistent  null$weight null   ,  $timeout  1,  $retry_interval 15  ,  $status TRUE  ,  $failure_callback null )
            {
        
            }
        
            
    // Close memcached server connection
            
    function close()
            {
                return 
    TRUE;
            } 
            
            
    //Open memcached server connection
            
    function connect$host  ,  $port 11211 $timeout  1)
            {
                return 
    FALSE;
            }
            
    //Decrement item's value
            
    function decrement$key  $value   )
            {
                return 
    FALSE;
            }
            
            
    //Delete item from the server
            
    function delete(string $key  ,$timeout  null  )
            {
                return 
    TRUE;
            }
            
            
    //Flush all existing items at the server
            
    function flush() 
            {
                return 
    TRUE;
            }
        
            
    //Retrieve item from the server
            
    function get$key  ,  &$flags  null )
            {
                return 
    FALSE;
            }    
            
            
    //Get statistics from all servers in pool
            
    function getExtendedStats$type $slabid null int $limit  null )
            {
                return 
    FALSE;
            }
            
            
    //Returns server status
            
    function getServerStatus$host  $port 11211 )
            { 
                return 
    FALSE;
            }
            
            
    //Get statistics of the server
            
    function getStats$type null $slabid null$limit  null )
            {
                return 
    FALSE;
            }
            
            
    //Return version of the server
            
    function getVersion()
            {
                return 
    FALSE;
            }
        
            
    //Increment item's value
            
    function increment$key  $value =1  )
            {
                return 
    FALSE;
            }
            
            
    //Open memcached server persistent connection
            
    function pconnect($host  ,  $port 11211  ,  $timeout  )
            {
                return 
    FALSE;
            }
            
            
    //Replace value of the existing item
            
    function replace $key  ,  $var  $flag null  ,  $expire  null)
            {
                return 
    FALSE;
            }
            
            
    //Store data at the server
            
    function set($key  ,  $var  $flag null  ,  $expire  null  )
            {
                return 
    FALSE;
            }
            
            
    //Enable automatic compression of large values
            
    function setCompressThreshold$threshold  ,  $min_savings 0.2 )
            {
                return 
    FALSE;
            }
            
            
    //Changes server parameters and status at runtime
            
    function setServerParams$host  ,  $port 11211  ,  $timeout 1  $retry_interval 15  ,  $status TRUE $failure_callback  null )
            {
                return 
    FALSE;
            }
        
        }
        
        
        
    define("MEMCACHE_COMPRESSED",0);
        
    define("MEMCACHE_HAVE_SESSION",0);
        
        
    // Turn debug output on/off
        
    function memcache_debug$on_off )
        {
            return 
    FALSE;
        }

    }
    ?>

  5. #5
    SitePoint Zealot
    Join Date
    Apr 2002
    Location
    Sydney, Australia
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That worked , but I had to comment out the "to die ....." from the next line.

    Since posting here, I've been talking (more) to Bluehost about the problem and they have said that I can install the memcache Perl module and that will solve the problem. Sounds semi-feasible, but they have over 50 modules when you search for memcache. When I install them I also have to add it to php.ini

    So I'm getting there .. slowly

  6. #6
    SitePoint Zealot
    Join Date
    Apr 2002
    Location
    Sydney, Australia
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I've found the reason why memcache has been used

    I'm now getting an error on this statement:

    session_start();

    the error is:

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent


    If I can get some help on getting memcache working (syntax needed within php.ini) that would be great, I'm finding a lot of information in Google but I don't understand most of it

  7. #7
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    365
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The session error has nothing to do with memcache.. it usually means you are starting to output data before session_start is called.. Make sure there is no errors or whitespace in any files before session-start (did it give you a file and line number?)

  8. #8
    SitePoint Zealot
    Join Date
    Apr 2002
    Location
    Sydney, Australia
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah yes, the dreaded whitespace issue ... I'd heard about it and that was the problem here. I've removed the whitespace I had and I don't get any errors now ... but I don't get any output either .

    Oh well, thanks for the help, back to getting the rest of the code working .....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •