コード例 #1
0
ファイル: destination_model.php プロジェクト: qiuai/qieyou
 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);
 }
コード例 #2
0
ファイル: Memcached.php プロジェクト: serby/Atrox
 /**
  * (non-PHPdoc)
  * @see Atrox/Core/Cache/Atrox_Core_Caching_ICacheManager#getFileContents($filename, $expire, $context)
  */
 public function getFileContents($filename, $expire = false, $context = null)
 {
     $key = $this->keyPrefix . "__File:" . md5($filename);
     if ($data = $this->memcache->get($key)) {
         return $data;
     } else {
         try {
             $data = @file_get_contents($filename, 0, $context);
             $this->memcache->set($key, $data, false, $expire);
         } catch (Exception $e) {
             echo $e->getMessage();
             throw new Atrox_Core_Exception_NoSuchFileException("'{$filename}' does not exist");
         }
     }
     return $data;
 }
コード例 #3
0
ファイル: Memcache.php プロジェクト: godboko/modules
 public function save($objectId, $object, $expiration = null)
 {
     return $this->memcache->set($this->encode($this->namespace, $objectId), $object, 0, $expiration === null ? $this->expiration : $expiration);
 }
コード例 #4
0
ファイル: test_master.php プロジェクト: burstzp/subscribe
<?php

// test
$mc = new memcache();
$mc->addServer("127.0.0.1", 15800);
$t1 = microtime(true);
for ($i = 0; $i < 100; $i++) {
    //$data = $mc->set("articles", '[{"Offset":"1105072","Data":"a_2999973"},{"Offset":"1105073","Data":"a_2999974"},{"Offset":"1105074","Data":"a_2999975"},{"Offset":"1105075","Data":"a_2999976"},{"Offset":"1105076","Data":"a_2999977"},{"Offset":"1105077","Data":"a_2999978"},{"Offset":"1105078","Data":"a_2999979"},{"Offset":"1105079","Data":"a_2999980"},{"Offset":"1105080","Data":"a_2999981"},{"Offset":"1105081","Data":"a_2999982"},{"Offset":"1105082","Data":"a_2999983"},{"Offset":"1105083","Data":"a_2999984"},{"Offset":"1105084","Data":"a_2999985"},{"Offset":"1105085","Data":"a_2999986"},{"Offset":"1105086","Data":"a_2999987"},{"Offset":"1105087","Data":"a_2999988"},{"Offset":"1105088","Data":"a_2999989"},{"Offset":"1105089","Data":"a_2999990"},{"Offset":"1105090","Data":"a_2999991"},{"Offset":"1105091","Data":"a_2999992"},{"Offset":"1105092","Data":"a_2999993"},{"Offset":"1105093","Data":"a_2999994"},{"Offset":"1105094","Data":"a_2999995"},{"Offset":"1105095","Data":"a_2999996"},{"Offset":"1105096","Data":"a_2999997"},{"Offset":"1105097","Data":"a_2999998"},{"Offset":"1105098","Data":"a_2999999"},{"Offset":"1105099","Data":"a_20"},{"Offset":"1105100","Data":"a_21"},{"Offset":"1105101","Data":"a_22"},{"Offset":"1105102","Data":"a_23"},{"Offset":"1105103","Data":"a_24"},{"Offset":"1105104","Data":"a_25"},{"Offset":"1105105","Data":"a_26"},{"Offset":"1105106","Data":"a_27"},{"Offset":"1105107","Data":"a_28"},{"Offset":"1105108","Data":"a_29"},{"Offset":"1105109","Data":"a_210"},{"Offset":"1105110","Data":"a_211"},{"Offset":"1105111","Data":"a_212"},{"Offset":"1105112","Data":"a_213"},{"Offset":"1105113","Data":"a_214"},{"Offset":"1105114","Data":"a_215"},{"Offset":"1105115","Data":"a_216"},{"Offset":"1105116","Data":"a_217"},{"Offset":"1105117","Data":"a_218"},{"Offset":"1105118","Data":"a_219"},{"Offset":"1105119","Data":"a_220"},{"Offset":"1105120","Data":"a_221"},{"Offset":"1105121","Data":"a_222"},{"Offset":"1105122","Data":"a_223"},{"Offset":"1105123","Data":"a_224"},{"Offset":"1105124","Data":"a_225"},{"Offset":"1105125","Data":"a_226"},{"Offset":"1105126","Data":"a_227"},{"Offset":"1105127","Data":"a_228"},{"Offset":"1105128","Data":"a_229"},{"Offset":"1105129","Data":"a_230"},{"Offset":"1105130","Data":"a_231"},{"Offset":"1105131","Data":"a_232"},{"Offset":"1105132","Data":"a_233"},{"Offset":"1105133","Data":"a_234"},{"Offset":"1105134","Data":"a_235"},{"Offset":"1105135","Data":"a_236"},{"Offset":"1105136","Data":"a_237"},{"Offset":"1105137","Data":"a_238"},{"Offset":"1105138","Data":"a_239"},{"Offset":"1105139","Data":"a_240"},{"Offset":"1105140","Data":"a_241"},{"Offset":"1105141","Data":"a_242"},{"Offset":"1105142","Data":"a_243"},{"Offset":"1105143","Data":"a_244"},{"Offset":"1105144","Data":"a_245"},{"Offset":"1105145","Data":"a_246"},{"Offset":"1105146","Data":"a_247"},{"Offset":"1105147","Data":"a_248"},{"Offset":"1105148","Data":"a_249"},{"Offset":"1105149","Data":"a_250"},{"Offset":"1105150","Data":"a_251"},{"Offset":"1105151","Data":"a_252"},{"Offset":"1105152","Data":"a_253"},{"Offset":"1105153","Data":"a_254"},{"Offset":"1105154","Data":"a_255"},{"Offset":"1105155","Data":"a_256"},{"Offset":"1105156","Data":"a_257"},{"Offset":"1105157","Data":"a_258"},{"Offset":"1105158","Data":"a_259"},{"Offset":"1105159","Data":"a_260"},{"Offset":"1105160","Data":"a_261"},{"Offset":"1105161","Data":"a_262"},{"Offset":"1105162","Data":"a_263"},{"Offset":"1105163","Data":"a_264"},{"Offset":"1105164","Data":"a_265"},{"Offset":"1105165","Data":"a_266"},{"Offset":"1105166","Data":"a_267"},{"Offset":"1105167","Data":"a_268"},{"Offset":"1105168","Data":"a_269"},{"Offset":"1105169","Data":"a_270"},{"Offset":"1105170","Data":"a_271"},{"Offset":"1105171","Data":"a_272"}]', 600);
    $data = $mc->set("articles5", '[{"Offset":"99994","Data":"abcd99993"},{"Offset":"99995","Data":"abcd99994"},{"Offset":"99996","Data":"abcd99995"},{"Offset":"99997","Data":"abcd99996"},{"Offset":"99998","Data":"abcd99997"},{"Offset":"99999","Data":"abcd99998"},{"Offset":"100000","Data":"abcd99999"}]' . $i);
    if ($data === false) {
        var_dump("abcd" . $i);
    }
}
//var_dump($mc->get("articles#1770949968#100838#1"));
//var_dump($mc->get(""));
//var_dump($mc->delete("sdsd"));
var_dump(microtime(true) - $t1);
//var_dump($mc->delete("1#1770949965#222"));
コード例 #5
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");
}
コード例 #6
0
ファイル: index.php プロジェクト: gogi4ello/website
        $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();