EllisLab text mark
Advanced Search
     
CI 2.0 missing memcache config file
Posted: 02 February 2011 03:17 PM
Joined: 2011-02-02
5 posts

The user guide says the there should be a config file for memcache located in the application/config/ directory but there is not one there.

Is it located somewhere else?

 
Posted: 02 February 2011 08:32 PM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2010-04-12
97 posts

You gotta create it yourself.

 Signature 

http://www.vmichnowicz.com/

 
Posted: 02 February 2011 10:16 PM   [ # 2 ]   [ Rating: 0 ]
Joined: 2011-02-02
5 posts

http://ellislab.com/codeigniter/user-guide/libraries/caching.html#memcached says its located in the config directory but it is not. If I am supposed to create it myself the docs give no details on what the caching class expects in terms of a config array to pass it.

 
Posted: 02 February 2011 11:17 PM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2010-04-12
97 posts

Yeah, I assumed it was in there as well. I think something like this would go in your memcached.php config file (I have not tested this):

<?php

$config[
'memcached'= array(
    
'server_1' => array(
        
'host' => '127.0.0.1',
        
'port'        => 11211,
        
'weight'    => 1
    
),
    
'server_2' => array(
        
'host' => '127.0.0.2',
        
'port'        => 11211,
        
'weight'    => 1
    
),
    
'server_3' => array(
        
'host' => '127.0.0.3',
        
'port'        => 11211,
        
'weight'    => 1
    
)
); 

You also gotta remember that memcached is different than memcache. That got me for a while… I created (really just search/replaced) a memcache driver if you are interested. It seems to work well for me.

 Signature 

http://www.vmichnowicz.com/

 
Posted: 05 February 2011 09:09 PM   [ # 4 ]   [ Rating: 0 ]
Joined: 2011-02-02
5 posts

Hmm I tried the config file you gave me and it’s not working. The weird thing is if I connect to memcached directly using just the memcached ext everything connects and works fine.

 
Posted: 08 February 2011 11:25 AM   [ # 5 ]   [ Rating: 0 ]
Joined: 2011-02-02
5 posts

bump

 
Posted: 08 February 2011 01:47 PM   [ # 6 ]   [ Rating: 0 ]
Joined: 2006-06-29
4 posts

I’d really like to know what to do with this ...
Any help would be greatly appreciated

 
Posted: 08 February 2011 03:52 PM   [ # 7 ]   [ Rating: 0 ]
Joined: 2010-02-04
2 posts

I think the memcached.php config file has to be like this

<?php
$config[
'memcached'= array(
        
'hostname' => '127.0.0.1',
        
'port'        => 11211,
        
'weight'    => 1
); 

At least that worked for me.
Also keep in mind what elvicmic mentioned.
Memcached and memcache are different extensions. Check your php.ini which extension is loaded.

 
Posted: 09 February 2011 10:43 AM   [ # 8 ]   [ Rating: 0 ]
Joined: 2011-02-09
4 posts

Yeah same as m3du54, my memcached.php file

<?php

  
if (!defined('BASEPATH')) exit('No direct script access allowed');

  
$config['memcached'= array(
          
'hostname' => '127.0.0.1',
          
'port'        => 11211,
          
'weight'    => 1
  
);

?> 
 
Posted: 09 February 2011 10:44 AM   [ # 9 ]   [ Rating: 0 ]
Joined: 2011-02-02
5 posts

Yes this works. Thanks everyone!

 
Posted: 17 August 2011 06:02 PM   [ # 10 ]   [ Rating: 0 ]
Joined: 2006-12-01
46 posts

Does anyone know how to configure multiple servers? Regards.

 
Posted: 17 August 2011 06:37 PM   [ # 11 ]   [ Rating: 0 ]
Joined: 2006-12-01
46 posts

Shouldn’t it be like:

$config['memcached'= array(

    
'default' => array(

            
'hostname'        => 'localhost',
            
'port'            => '11211',
            
'weight'        => '1'        
    
)
); 
 
Posted: 24 October 2011 01:48 PM   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2007-03-11
27 posts
Patman - 17 August 2011 06:37 PM

Shouldn’t it be like:

$config['memcached'= array(

    
'default' => array(

            
'hostname'        => 'localhost',
            
'port'            => '11211',
            
'weight'        => '1'        
    
)
); 


Taking a look at the Cache_memcache class

it has the following

'default' => array(
 
'default_host'  => '127.0.0.1',
 
'default_port'  => 11211,
 
'default_weight' => 1
); 

then if you look at

/**
  * Setup memcached.
  */
 
private function _setup_memcached()
 
{
  
// Try to load memcached server info from the config file.
  
$CI =& get_instance();
  if (
$CI->config->load('memcached'TRUETRUE))
  
{
   
if (is_array($CI->config->config['memcached']))
   
{
    $this
->_memcache_conf NULL;

    foreach (
$CI->config->config['memcached'as $name => $conf)
    
{
     $this
->_memcache_conf[$name] $conf;
    
}    
   }   
  }
  
  $this
->_memcached = new Memcached();

  foreach (
$this->_memcache_conf as $name => $cache_server)
  
{
   
if ( ! array_key_exists('hostname'$cache_server))
   
{
    $cache_server[
'hostname'$this->_default_options['default_host'];
   
}
 
   
if ( ! array_key_exists('port'$cache_server))
   
{
    $cache_server[
'port'$this->_default_options['default_port'];
   
}
 
   
if ( ! array_key_exists('weight'$cache_server))
   
{
    $cache_server[
'weight'$this->_default_options['default_weight'];
   
}
 
   $this
->_memcached->addServer(
     
$cache_server['hostname']$cache_server['port']$cache_server['weight']
   
);
  
}
 } 

The array key you give each server is not really used, or relevant. So your config should just be a multidimensional array like so:

$config= array(
    
'server_1' => array(
        
'host' => '127.0.0.1',
        
'port'        => 11211,
        
'weight'    => 1
    )
,
    
'server_2' => array(
        
'host' => '127.0.0.2',
        
'port'        => 11211,
        
'weight'    => 1
    
),
    
'server_3' => array(
        
'host' => '127.0.0.3',
        
'port'        => 11211,
        
'weight'    => 1
    
)
); 

 

 
Posted: 06 March 2012 06:39 AM   [ # 13 ]   [ Rating: 0 ]
Joined: 2006-12-01
46 posts

Actually, this worked:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

// --------------------------------------------------------------------------
// Servers
// --------------------------------------------------------------------------

$config['memcached'= array(
    
'hostname' => '10.0.11.5',
    
'port' => '11211',
    
'weight' => '1',
);

$config['memcached'= array(
    
'hostname' => '10.0.11.5',
    
'port' => '11212',
    
'weight' => '1',
);

/* End of file memcached.php */
/* Location: ./system/application/config/memcached.php */ 

Of course with your own paramaters.

 
Posted: 25 July 2013 03:56 AM   [ # 14 ]   [ Rating: 0 ]
Joined: 2013-07-25
1 posts

But this setup has just one server. Even if you would have different setting with the second array it would overwrite the first. So I guess it will work but always use just one mencached server.

Anja