• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Multiple Memcache Servers Config File Setting

Brent W

Well-known member
#1
How should I configure my config.php file to point to more than one memcached server?

Currently have one setup but want to create another so that the forums can fall back to it in case one fails.
 

Slavik

XenForo moderator
Staff member
#2
I believe it would be as follows.

Code:
$config['cache']['backend'] = 'Memcached';
$config['cache']['backendOptions'] = array(
    'compression' => false,
    'servers' => array(
        array(
            // your memcached server IP /address
            'host' => 'localhost',
           
            // memcached port
            'port' => 11211,
        )
    )
    'servers' => array(
        array(
            // your memcached server IP /address
            'host' => 'localhost',
           
            // memcached port
            'port' => 11211,
        )
    )
);
If that doesn't work

Code:
$config['cache']['backend'] = 'Memcached';
$config['cache']['backendOptions'] = array(
    'compression' => false,
    'servers' => array(
        array(
            // your memcached server IP /address
            'host' => 'localhost',
           
            // memcached port
            'port' => 11211,
        )
       array(
            // your memcached server IP /address
            'host' => 'localhost',
           
            // memcached port
            'port' => 11211,
        )
    )
);
 

Slavik

XenForo moderator
Staff member
#4
Thanks I will give those a try. Should I miss with the weight option between the servers?
I don't thinkso, this way the data *should* be identically copied and served to and from each server, and should one fail the other will carry on without issue...

thats the theory at least...
 

MattW

Well-known member
#6
I believe it would be as follows.

Code:
$config['cache']['backend'] = 'Memcached';
$config['cache']['backendOptions'] = array(
    'compression' => false,
    'servers' => array(
        array(
            // your memcached server IP /address
            'host' => 'localhost',
       
            // memcached port
            'port' => 11211,
        )
    )
    'servers' => array(
        array(
            // your memcached server IP /address
            'host' => 'localhost',
       
            // memcached port
            'port' => 11211,
        )
    )
);
If that doesn't work

Code:
$config['cache']['backend'] = 'Memcached';
$config['cache']['backendOptions'] = array(
    'compression' => false,
    'servers' => array(
        array(
            // your memcached server IP /address
            'host' => 'localhost',
       
            // memcached port
            'port' => 11211,
        )
      array(
            // your memcached server IP /address
            'host' => 'localhost',
       
            // memcached port
            'port' => 11211,
        )
    )
);
I've tried both of these to get my primary server to use the second install of memcache on my second server, and neither work

I get this error
Code:
Parse error: syntax error, unexpected T_ARRAY, expecting ')' in /home/z22se/public_html/forum/library/config.php on line 31
Example:
Code:
$config['cache']['backendOptions']=array(
        'compression'=>false,
        'servers' => array(
                array(
                        'host'=>'localhost',
                        'port'=>11211,
                )     
                array(        #This is line 31
                        'host'=>'IP ADDRESS',
                        'port'=>11211,
                )
               
        )
);

Code:
Parse error: syntax error, unexpected T_ARRAY, expecting ')' in /home/z22se/public_html/forum/library/config.php on line 32
Code:
$config['cache']['backendOptions']=array(
        'compression'=>false,
        'servers' => array(
                array(
                        'host'=>'localhost',
                        'port'=>11211,
                )     
        )     
        'servers' => array( # This is line 32
                array(
                'host'=>'IP ADDRESS',
                'port'=>11211,
                )
        )
);
 

MattW

Well-known member
#7
Think I've fixed it.

It was missing a comma between the two arrays

Code:
$config['cache']['backendOptions']=array(
        'compression'=>false,
        'servers' => array(
                array(
                        'host'=>'localhost',
                        'port'=>'11211'
                ),
                array(
                        'host'=>'IP ADDRESS',
                        'port'=>'11211'
                )
        )
);