# MemCacheServer

> MemCacheServer represents the configuration data for a single memcache or memcached server.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [caching](/docs/api/yii/caching/index.md) › MemCacheServer

| class | `yii\caching\MemCacheServer` |
| --- | --- |
| Extends | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/caching/MemCacheServer.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/caching/MemCacheServer.php#L22) |

MemCacheServer represents the configuration data for a single memcache or memcached server.

See [PHP manual](https://www.php.net/manual/en/memcache.addserver.php) for detailed explanation
of each configuration property.

For more details and usage information on Cache, see the [guide article on caching](/docs/guide/caching-overview/index.md).

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| [`$failureCallback`](#property-failureCallback) | [`Closure`](https://www.php.net/manual/en/class.closure.php) | This callback function will run upon encountering an error. Default: `null`. | `MemCacheServer` |
| <span id="property-host"></span>`$host` | `string` | Memcache server hostname or IP address Default: `null`. | `MemCacheServer` |
| [`$persistent`](#property-persistent) | `bool` | Whether to use a persistent connection. Default: `true`. | `MemCacheServer` |
| <span id="property-port"></span>`$port` | `int` | Memcache server port Default: `11211`. | `MemCacheServer` |
| [`$retryInterval`](#property-retryInterval) | `int` | How often a failed server will be retried (in seconds). Default: `15`. | `MemCacheServer` |
| [`$status`](#property-status) | `bool` | If the server should be flagged as online upon a failure. Default: `true`. | `MemCacheServer` |
| [`$timeout`](#property-timeout) | `int` | Timeout in milliseconds which will be used for connecting to the server. Default: `1000`. | `MemCacheServer` |
| <span id="property-weight"></span>`$weight` | `int` | Probability of using this server among all servers. Default: `1`. | `MemCacheServer` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/baseobject/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/baseobject/index.md#method-__get) | Returns the value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/baseobject/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/baseobject/index.md#method-__set) | Sets value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/baseobject/index.md#method-__unset) | Sets an object property to null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/baseobject/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/baseobject/index.md#method-hasProperty) | Returns a value indicating whether a property is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-init"></span>[`init()`](/docs/api/yii/base/baseobject/index.md#method-init) | Initializes the object. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |

## Property details

### $failureCallback <span id="property-failureCallback"></span>

```php
public Closure $failureCallback = null
```

This callback function will run upon encountering an error.

The callback is run before fail over is attempted. The function takes two parameters,
the [`$host`](/docs/api/yii/caching/memcacheserver/index.md#property-host) and the [`$port`](/docs/api/yii/caching/memcacheserver/index.md#property-port) of the failed server.
This is used by memcache only.

### $persistent <span id="property-persistent"></span>

```php
public bool $persistent = true
```

Whether to use a persistent connection.

This is used by memcache only.

### $retryInterval <span id="property-retryInterval"></span>

```php
public int $retryInterval = 15
```

How often a failed server will be retried (in seconds).

This is used by memcache only.

### $status <span id="property-status"></span>

```php
public bool $status = true
```

If the server should be flagged as online upon a failure.

This is used by memcache only.

### $timeout <span id="property-timeout"></span>

```php
public int $timeout = 1000
```

Timeout in milliseconds which will be used for connecting to the server.

This is used by memcache only. For old versions of memcache that only support specifying
timeout in seconds this will be rounded up to full seconds.