Beispiel #1
0
function get_memcache()
{
    $m = new MemcacheSASL();
    $m->addServer($_ENV['MEMCACHE_SERVERS'], '11211');
    $m->setSaslAuthData($_ENV['MEMCACHE_USERNAME'], $_ENV['MEMCACHE_PASSWORD']);
    return $m;
}
function cometchatMemcacheConnect()
{
    include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "cometchat_cache.php";
    global $memcache;
    if (defined('MEMCACHE') && MEMCACHE != 0 && MC_NAME == 'memcachier') {
        $memcache = new MemcacheSASL();
        $memcache->addServer(MC_SERVER, MC_PORT);
        $memcache->setSaslAuthData(MC_USERNAME, MC_PASSWORD);
    } elseif (defined('MEMCACHE') && MEMCACHE != 0) {
        phpFastCache::setup("path", dirname(__FILE__) . DIRECTORY_SEPARATOR . 'writable' . DIRECTORY_SEPARATOR . 'cache');
        phpFastCache::setup("storage", MC_NAME);
        $memcache = phpFastCache();
    }
}
function updatecaching()
{
    global $ts;
    $conn = 1;
    $errorCode = 0;
    $memcacheAuth = 0;
    include_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "cometchat_cache.php";
    if ($_POST['MC_NAME'] == 'memcachier') {
        $memcacheAuth = 1;
        $conn = 0;
        $memcache = new MemcacheSASL();
        $memcache->addServer($_POST['MC_SERVER'], $_POST['MC_PORT']);
        if ($memcachierAuth = $memcache->setSaslAuthData($_POST['MC_USERNAME'], $_POST['MC_PASSWORD'])) {
            $memcache->set('auth', 'ok');
            if (!($conn = $memcache->get('auth'))) {
                $errorCode = 3;
            }
            $memcache->delete('auth');
        } else {
            $errorCode = 3;
        }
    } elseif ($_POST['MC_NAME'] != '') {
        $conn = 0;
        $memcacheAuth = 1;
        phpFastCache::setup("storage", $_POST['MC_NAME']);
        $memcache = new phpFastCache();
        $driverPresent = isset($memcache->driver->option['availability']) ? 0 : 1;
        if ($driverPresent) {
            if ($_POST['MC_NAME'] == 'memcache') {
                $server = array(array($_POST['MC_SERVER'], $_POST['MC_PORT'], 1));
                $memcache->option('server', $server);
            }
            $memcache->set('auth', 'ok', 30);
            if (!($conn = $memcache->get('auth'))) {
                $errorCode = 1;
            }
            $memcache->delete('auth');
        }
    }
    if ($conn && !$errorCode) {
        $data = 'define(\'MEMCACHE\',\'' . $memcacheAuth . '\');' . "\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\r\n";
        $data .= 'define(\'MC_NAME\',\'' . $_POST['MC_NAME'] . '\');' . "\t\t\t// Set name of caching method if 0 : '', 1 : memcache, 2 : files, 3 : memcachier, 4 : apc, 5 : wincache, 6 : sqlite & 7 : memcached";
        configeditor('MEMCACHE', $data, 0);
        $_SESSION['cometchat']['error'] = 'Caching details updated successfully.';
    } else {
        if ($_POST['MC_NAME'] == 'memcachier') {
            $_SESSION['cometchat']['error'] = 'Failed to update caching details. Please check your Memchachier server details';
        } elseif ($_POST['MC_NAME'] == 'files') {
            $_SESSION['cometchat']['error'] = 'Please check file permission of your cache directory. Please try 755/777/644';
        } elseif ($_POST['MC_NAME'] == 'apc') {
            $_SESSION['cometchat']['error'] = 'Failed to update caching details. Please check your APC configuration.';
        } elseif ($_POST['MC_NAME'] == 'wincache') {
            $_SESSION['cometchat']['error'] = 'Failed to update caching details. Please check your Wincache configuration.';
        } elseif ($_POST['MC_NAME'] == 'sqlite') {
            $_SESSION['cometchat']['error'] = 'Failed to update caching details. Please check your SQLite configuration.';
        } elseif ($_POST['MC_NAME'] == 'memcached') {
            $_SESSION['cometchat']['error'] = 'Failed to update caching details. Please check your Memcached configuration.';
        } else {
            $_SESSION['cometchat']['error'] = 'Failed to update caching details. Please check your Memcache server configuration.';
        }
    }
    header("Location:?module=settings&action=caching&ts={$ts}");
}
Beispiel #4
0
    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'];
}
authenticate();
$module = "dashboard";
Beispiel #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");
}
Beispiel #6
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');
Beispiel #7
0
function updatecaching()
{
    global $ts;
    $conn = 1;
    $errorCode = 0;
    $memcacheAuth = 0;
    include_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "cometchat_cache.php";
    if ($_POST['MC_NAME'] == 'memcachier') {
        $memcacheAuth = 1;
        $conn = 0;
        $memcache = new MemcacheSASL();
        $memcache->addServer($_POST['MC_SERVER'], $_POST['MC_PORT']);
        if ($memcachierAuth = $memcache->setSaslAuthData($_POST['MC_USERNAME'], $_POST['MC_PASSWORD'])) {
            $memcache->set('auth', 'ok');
            if (!($conn = $memcache->get('auth'))) {
                $errorCode = 3;
            }
            $memcache->delete('auth');
        } else {
            $errorCode = 3;
        }
    } elseif ($_POST['MC_NAME'] != '') {
        $conn = 0;
        $memcacheAuth = 1;
        phpFastCache::setup("storage", $_POST['MC_NAME']);
        $memcache = new phpFastCache();
        $driverPresent = isset($memcache->driver->option['availability']) ? 0 : 1;
        if ($driverPresent) {
            if ($_POST['MC_NAME'] == 'memcache' && class_exists("Memcache") || $_POST['MC_NAME'] == 'memcached' && class_exists("Memcached")) {
                if ($_POST['MC_NAME'] == 'memcache') {
                    $server = array(array($_POST['MC_SERVER'], $_POST['MC_PORT'], 1));
                    $memcache->option('server', $server);
                }
                if ($_POST['MC_NAME'] == 'memcached') {
                    $server = array(array($_POST['MC_SERVER'], $_POST['MC_PORT'], 1));
                    $memcache->option('server', $server);
                }
                $memcache->set('auth', 'ok', 30);
                if (!($conn = $memcache->get('auth'))) {
                    $errorCode = 1;
                }
                $memcache->delete('auth');
            }
        }
    }
    if (!$errorCode) {
        configeditor($_POST);
        $_SESSION['cometchat']['error'] = 'Caching details updated successfully.';
    } else {
        if ($_POST['MC_NAME'] == 'memcachier') {
            $_SESSION['cometchat']['error'] = 'Failed to update caching details. Please check your Memchachier server details';
        } elseif ($_POST['MC_NAME'] == 'files') {
            $_SESSION['cometchat']['error'] = 'Please check file permission of your cache directory. Please try 755/777/644';
        } elseif ($_POST['MC_NAME'] == 'apc') {
            $_SESSION['cometchat']['error'] = 'Failed to update caching details. Please check your APC configuration.';
        } elseif ($_POST['MC_NAME'] == 'wincache') {
            $_SESSION['cometchat']['error'] = 'Failed to update caching details. Please check your Wincache configuration.';
        } elseif ($_POST['MC_NAME'] == 'sqlite') {
            $_SESSION['cometchat']['error'] = 'Failed to update caching details. Please check your SQLite configuration.';
        } elseif ($_POST['MC_NAME'] == 'memcached') {
            $_SESSION['cometchat']['error'] = 'Failed to update caching details. Please check your Memcached configuration.';
        } else {
            $_SESSION['cometchat']['error'] = 'Failed to update caching details. Please check your Memcache server configuration.';
        }
    }
    header("Location:?module=settings&action=caching&ts={$ts}");
}