Add memcached support with cache_get/cache_set wrappers, use them to cache video embeds indefinitely
This commit is contained in:
@@ -33,6 +33,9 @@ $sourcedir = '/var/www/rock/forum/Sources';
|
||||
$webmaster_email = 'noreply@rock.ru'; # Email address to send emails from. (like noreply@yourdomain.com.)
|
||||
$cookiename = 'SMFCookie10'; # Name of the cookie to set for authentication.
|
||||
|
||||
$mongo_server = "mongodb://rock.home:27017";
|
||||
$memcached_host = "127.0.0.1";
|
||||
$memcached_port = 11211;
|
||||
########## Database Info ##########
|
||||
#$db_server = '127.0.0.1:3306';
|
||||
$db_server = 'localhost';
|
||||
@@ -45,4 +48,4 @@ $db_error_send = 1;
|
||||
|
||||
|
||||
$db_last_error = 1353665424;
|
||||
?>
|
||||
?>
|
||||
|
||||
@@ -1305,11 +1305,9 @@ function parseVideo($matches) {
|
||||
}
|
||||
}
|
||||
|
||||
function parseVideoMyspace($url)
|
||||
{
|
||||
$ttl = 3600;
|
||||
$html = xcache_get($url);
|
||||
if ($html !== NULL) {
|
||||
function parseVideoMyspace($url) {
|
||||
$html = cache_get($url);
|
||||
if ($html !== FALSE) {
|
||||
return $html;
|
||||
}
|
||||
$page = curl_get(htmlspecialchars_decode($url));
|
||||
@@ -1326,15 +1324,13 @@ function parseVideoMyspace($url)
|
||||
$html = '<a href="'.$url.'">Посмотреть видео</a>';
|
||||
$ttl = 60;
|
||||
}
|
||||
xcache_set($url, $html, $ttl);
|
||||
cache_set($url, $html);
|
||||
return $html;
|
||||
}
|
||||
|
||||
function parseVideoDailymotion($url)
|
||||
{
|
||||
$ttl = 3600;
|
||||
$html = xcache_get($url);
|
||||
if ($html !== NULL) {
|
||||
function parseVideoDailymotion($url) {
|
||||
$html = cache_get($url);
|
||||
if ($html !== FALSE) {
|
||||
return $html;
|
||||
}
|
||||
$oembed_endpoint = 'http://www.dailymotion.com/api/oembed';
|
||||
@@ -1346,22 +1342,23 @@ function parseVideoDailymotion($url)
|
||||
$html = '<a href="'.$url.'">Посмотреть видео</a>';
|
||||
$ttl = 60;
|
||||
}
|
||||
xcache_set($url, $html, $ttl);
|
||||
cache_set($url, $html);
|
||||
return $html;
|
||||
}
|
||||
|
||||
#function xcache_get($param) {
|
||||
# return NULL;
|
||||
#}
|
||||
#
|
||||
#function xcache_set($param, $value) {
|
||||
# return NULL;
|
||||
#}
|
||||
function cache_get($param) {
|
||||
global $memcached;
|
||||
return $memcached->get($param);
|
||||
}
|
||||
|
||||
function cache_set($param, $value, $ttl = 0) {
|
||||
global $memcached;
|
||||
return $memcached->set($param, $value, $ttl);
|
||||
}
|
||||
function parseVideoYoutube($url)
|
||||
{
|
||||
$ttl = 3600;
|
||||
$html = xcache_get($url);
|
||||
if ($html !== NULL) {
|
||||
$html = cache_get($url);
|
||||
if ($html !== FALSE) {
|
||||
return $html;
|
||||
}
|
||||
$oembed_endpoint = 'http://www.youtube.com/oembed';
|
||||
@@ -1378,15 +1375,14 @@ function parseVideoYoutube($url)
|
||||
$html = '<a href="'.$theURL.'">Посмотреть видео</a>';
|
||||
$ttl = 60;
|
||||
}
|
||||
xcache_set($url, $html, $ttl);
|
||||
cache_set($url, $html);
|
||||
return $html;
|
||||
}
|
||||
|
||||
function parseVideoVimeo($url)
|
||||
{
|
||||
$ttl = 3600;
|
||||
$html = xcache_get($url);
|
||||
if ($html !== NULL) {
|
||||
$html = cache_get($url);
|
||||
if ($html !== FALSE) {
|
||||
return $html;
|
||||
}
|
||||
$oembed_endpoint = 'http://www.vimeo.com/api/oembed';
|
||||
@@ -1398,7 +1394,7 @@ function parseVideoVimeo($url)
|
||||
$html = '<a href="'.$url.'">Посмотреть видео</a>';
|
||||
$ttl = 60;
|
||||
}
|
||||
xcache_set($url, $html, $ttl);
|
||||
cache_set($url, $html);
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,6 +75,9 @@ if (!$db_connection || !@mysql_select_db($db_name, $db_connection))
|
||||
|
||||
$mongodb = new MongoClient();
|
||||
|
||||
$memcached = new Memcached();
|
||||
$memcached->addServer($memcached_host, $memcached_port);
|
||||
|
||||
//
|
||||
mysql_query("SET NAMES 'utf8'");
|
||||
setlocale(LC_ALL,"ru_RU.UTF-8");
|
||||
|
||||
Reference in New Issue
Block a user