Ejemplo n.º 1
0
 public function get($key)
 {
     if (!isset($this->_configuration[$key])) {
         throw $this->_exception_format('Unknown service \'%s\'', $key);
     }
     if (!isset($this->_cons[$key]) || is_null($this->_cons[$key])) {
         $cfg =& $this->_configuration[$key];
         switch ($cfg['type']) {
             default:
                 throw $this->_exception_format('Unknown type \'%s\' for service \'%s\'', $cfg['type'], $key);
             case 'mysql':
             case 'maria':
                 $con = h\db\open($cfg);
                 break;
             case 'facebook':
             case 'fb':
                 $con = new \facebook($cfg);
                 break;
             case 'memcache':
             case 'memcached':
                 $con = new memcache();
                 $con->connect($cfg);
                 break;
         }
         $this->_cons[$key] = $con;
     }
     return $this->_cons[$key];
 }
Ejemplo n.º 2
0
 public function get_china_dest_by_parent_id($parent_id)
 {
     $memcache = new memcache();
     $memcache->connect($this->config->item('localMemcache_ip'), $this->config->item('localMemcache_port'));
     $dest = $memcache->get('china_dest' . $parent_id);
     if ($dest !== array()) {
         $cond = array('table' => 'china_dest', 'fields' => '*', 'where' => array('parent_id' => $parent_id));
         $dest = $this->get_all($cond);
         $memcache->set('china_dest' . $parent_id, $dest, FALSE, 1800);
     }
     return $this->get_all($cond);
 }
Ejemplo n.º 3
0
 /**
  * Initializes the Memcache Module
  *
  */
 public final function initialize()
 {
     $this->_ensureModuleExistence();
     $this->memcache = new Memcache();
     // support multiple hosts using semicolon to separate hosts
     $hosts = explode(";", $this->host);
     // different ports for each hosts the same way
     $ports = explode(";", $this->port);
     if (count($hosts) > 1) {
         if (count($ports) < 1) {
             $ports = array_fill(0, count($hosts), self::DEFAULT_PORT);
         } elseif (count($ports) == 1) {
             // if we have just one port, use it for all hosts
             $_p = $ports[0];
             $ports = array_fill(0, count($hosts), $_p);
         }
         foreach ($hosts as $i => $host) {
             $this->memcache->addServer($host, $ports[$i]);
         }
     } else {
         // just connect to the single host
         $this->memcache->connect($hosts[0], $ports[0]);
     }
 }
Ejemplo n.º 4
0
 protected function getMemcache()
 {
     try {
         $memcache = new memcache();
         if ($memcache) {
             $memcache->connect(self::$config['host'], self::$config['port']);
             return $memcache;
         } else {
             return false;
         }
     } catch (Exception $e) {
         Log::write($e->getMessage(), "ERR", 3, "memcache");
         return false;
     }
 }
Ejemplo n.º 5
0
Archivo: mem.php Proyecto: 0xlen/fbchat
<?php

$mem = new memcache();
$mem->connect('localhost', 11211);
Ejemplo n.º 6
0
}
$dbh = mysql_connect(DB_SERVER . ':' . DB_PORT, DB_USERNAME, DB_PASSWORD);
if (!$dbh) {
    echo "<h3>Unable to connect to database. Please check details in configuration file.</h3>";
    exit;
}
mysql_selectdb(DB_NAME, $dbh);
mysql_query("SET NAMES utf8");
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET COLLATION_CONNECTION = 'utf8_general_ci'");
$usertable = TABLE_PREFIX . DB_USERTABLE;
$usertable_username = DB_USERTABLE_NAME;
$usertable_userid = DB_USERTABLE_USERID;
if (MEMCACHE == 1 && class_exists('memcache')) {
    $memcache = new memcache();
    $memcache->connect(MC_SERVER, MC_PORT);
} elseif (MEMCACHE == 3 && file_exists(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "MemcacheSASL.php")) {
    include_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "MemcacheSASL.php";
    $memcache = new MemcacheSASL();
    $memcache->addServer(MC_SERVER, MC_PORT);
    $memcache->setSaslAuthData(MC_USERNAME, MC_PASSWORD);
}
if (empty($_SESSION['token'])) {
    $_SESSION['token'] = sha1(microtime());
}
$body = '';
if (!empty($_POST['username'])) {
    $_SESSION['cometchat']['cometchat_admin_user'] = $_POST['username'];
}
if (!empty($_POST['password'])) {
    $_SESSION['cometchat']['cometchat_admin_pass'] = $_POST['password'];
Ejemplo n.º 7
0
function updatecaching()
{
    checktoken();
    global $cookiePrefix;
    $conn = 1;
    $memcachierAuth = 0;
    $errorCode = 0;
    if ($_POST['cachingType'] == 1 && isset($_POST['usememcachier']) && $_POST['usememcachier'] == 'on') {
        $conn = 0;
        $_POST['cachingType'] = '3';
        include_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "MemcacheSASL.php";
        $memcache = new MemcacheSASL();
        @$memcache->addServer($_POST['MC_SERVER'], $_POST['MC_PORT']);
        if ($memcachierAuth = @$memcache->setSaslAuthData($_POST['MC_USERNAME'], $_POST['MC_PASSWORD'])) {
            @$memcache->add('auth', 'ok');
            if (!($conn = @$memcache->get('auth'))) {
                $errorCode = 3;
            }
            @$memcache->delete('auth');
        } else {
            $errorCode = 3;
        }
    } elseif ($_POST['cachingType'] == 1 && !isset($_POST['usememcachier'])) {
        $conn = 0;
        if (class_exists('memcache')) {
            $memcache = new memcache();
            @$memcache->connect($_POST['MC_SERVER'], $_POST['MC_PORT']);
            @$memcache->set('auth', '1');
            if (!($conn = $memcache->get('auth'))) {
                $errorCode = 1;
            }
            @$memcache->delete('auth');
        }
    } elseif ($_POST['cachingType'] == 2) {
        $file = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'filecache_test.txt';
        @($handle = fopen($file, 'w'));
        if (@(!fwrite($handle, "1"))) {
            $errorCode = 2;
            @unlink(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'filecache_test.txt');
        }
        @fclose($handle);
    }
    if ($conn && !$errorCode) {
        $data = 'define(\'MEMCACHE\',\'' . $_POST['cachingType'] . '\');' . "\t\t\t\t// Set to 0 for disable caching, 1 for memcaching, 2 for file caching, 3 for memcachier\r\n";
        $data .= 'define(\'MC_SERVER\',\'' . $_POST['MC_SERVER'] . '\');' . "\t// Set name of your memcache  server\r\n";
        $data .= 'define(\'MC_PORT\',\'' . $_POST['MC_PORT'] . '\');' . "\t\t\t// Set port of your memcache  server\r\n";
        $data .= 'define(\'MC_USERNAME\',\'' . $_POST['MC_USERNAME'] . '\');' . "\t\t\t\t\t\t\t// Set username of memcachier  server\r\n";
        $data .= 'define(\'MC_PASSWORD\',\'' . $_POST['MC_PASSWORD'] . '\');' . "\t\t\t// Set password your memcachier  server";
        configeditor('MEMCACHE', $data, 0);
        $_SESSION['cometchat']['error'] = 'Caching details updated successfully.';
    } else {
        if ($errorCode == 3) {
            $_SESSION['cometchat']['error'] = 'Failed to update caching details. Please check your memchachier server details';
        } elseif ($errorCode == 2) {
            $_SESSION['cometchat']['error'] = 'Please check file permission of your cache directory. Please try 755/777/644';
        } else {
            $_SESSION['cometchat']['error'] = 'Failed to update caching details. Please check your memcache server configuration.';
        }
    }
    header("Location:?module=settings&action=caching");
}
Ejemplo n.º 8
0
        $xmlString = file_get_contents('http://www.billboard.com/rss/charts/hot-100');
        $cache->set('top', $xmlString, 0, 8600);
    }
    $xml = new SimpleXMLElement($xmlString);
    $results = $xml->channel[0]->item;
    $app->render('layout.php', ['page' => 'main', 'results' => $results]);
});
// Search route
$app->get('/:query.html', function ($query) use($app) {
    $query = urlclean($query);
    // Save request
    $client = new \Sokil\Mongo\Client(MONGO_DSN);
    $collection = $client->getDatabase(MONGO_DBNAME)->getCollection(MONGO_COLLECTION);
    if (!$collection->find(['request' => $query])->count()) {
        $collection->insert(['request' => $query, 'created' => new MongoDate(), 'views' => 1]);
    } else {
        $collection->getMongoCollection()->update(['request' => $query], ['$inc' => ['views' => 1]]);
    }
    // Search from Vk or memcache
    $cache = new memcache();
    $cache->connect('localhost');
    // Поиск в ВК и отправка пользователю
    if (($results = $cache->get($query)) === false) {
        // Search from Vk or memcache
        $http = new dHttp\Client('https://api.vk.com/method/audio.search.json?access_token=096fb2d19fc28da6694e9db15f47ff9561c36628f5485fbcd642f7edc6185ea413ab2f2fa4a5c1789cb79&q=' . urlencode($query));
        $results = json_decode($http->get()->getBody(), true);
        $cache->set($query, json_decode($http->get()->getBody(), true), 0, 72000);
    }
    $app->render('layout.php', ['page' => 'search', 'results' => $results, 'query' => $query]);
})->conditions(['query' => '.+']);
$app->run();