- self::$cache = new Memcache();
-
- if (is_array($servers)) {
- foreach($servers as $server) {
- self::$cache->addServer($server);
+ if (class_exists('Memcache')) {
+ self::$cache = new Memcache();
+
+ // If we're a parent command-line process we need
+ // to be able to close out the connection after
+ // forking, so disable persistence.
+ //
+ // We'll turn it back on again the second time
+ // through which will either be in a child process,
+ // or a single-process script which is switching
+ // configurations.
+ $persist = php_sapi_name() != 'cli' || self::$cacheInitialized;
+ if (is_array($servers)) {
+ foreach($servers as $server) {
+ self::$cache->addServer($server, 11211, $persist);
+ }
+ } else {
+ self::$cache->addServer($servers, 11211, $persist);