Esempio n. 1
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");
}
Esempio n. 2
0
<?php

include 'MemcacheSASL.php';
$m = new MemcacheSASL();
$m->addServer('mc7.ec2.northscale.net', '11211');
$m->setSaslAuthData('username', 'password');
var_dump($m->add('test', '123'));
$m->delete('test');