/*** SIDEBAR ****/ echo '<div id="sidebar">'; do_banner_right(); do_best_stories(); do_best_comments(); do_vertical_tags('published'); echo '</div>' . "\n"; /*** END SIDEBAR ***/ echo '<div id="newswrap">' . "\n"; echo '<div class="topheading"><h2>' . _('noticias más comentadas') . '</h2></div>'; $link = new Link(); // Use memcache if available if ($globals['memcache_host'] && get_current_page() < 4) { $memcache_key = 'topcommented_' . $from . '_' . get_current_page(); } if (!($memcache_key && ($rows = memcache_mget($memcache_key . 'rows')) && ($links = memcache_mget($memcache_key)))) { // It's not in memcache if ($time_link) { $rows = min(100, $db->get_var("SELECT count(*) FROM links WHERE {$time_link}")); } else { $rows = min(100, $db->get_var("SELECT count(*) FROM links")); } if ($rows == 0) { do_error(_('no hay noticias seleccionadas'), 500); } $links = $db->get_results("{$sql} LIMIT {$offset},{$page_size}"); if ($memcache_key) { memcache_madd($memcache_key . 'rows', $rows, 1800); memcache_madd($memcache_key, $links, 1800); } }
/*** SIDEBAR ****/ echo '<div id="sidebar">'; do_banner_right(); do_best_stories(); do_best_comments(); do_vertical_tags('published'); echo '</div>' . "\n"; /*** END SIDEBAR ***/ echo '<div id="newswrap">' . "\n"; echo '<div class="topheading"><h2>' . _('noticias más comentadas') . '</h2></div>'; $link = new Link(); // Use memcache if available if ($globals['memcache_host'] && get_current_page() < 4) { $memcache_key = 'topcommented_' . $globals['site_shortname'] . $from . '_' . get_current_page(); } if (!($memcache_key && ($rows = memcache_mget($memcache_key . 'rows')) && ($links = unserialize(memcache_mget($memcache_key))))) { // It's not in memcache $rows = -1; // min(100, $db->get_var("SELECT count(*) FROM links")); $links = $db->get_results("{$sql} LIMIT {$offset},{$page_size}"); if ($memcache_key) { memcache_madd($memcache_key . 'rows', $rows, 1800); memcache_madd($memcache_key, serialize($links), 1800); } } if ($links) { foreach ($links as $dblink) { $link->id = $dblink->link_id; $link->read(); $link->print_summary('short'); }
static function store_clicks() { global $globals, $db; if (!self::$clicked) { return false; } $id = self::$clicked; self::$clicked = 0; if (!memcache_menabled()) { $db->query("UPDATE link_clicks SET counter=counter+1 WHERE id = {$id}"); return true; } $key = 'clicks_cache'; $cache = memcache_mget($key); if (!$cache || !is_array($cache)) { $cache = array(); $cache['time'] = $globals['start_time']; $cache[$id] = 1; $in_cache = false; } else { $cache[$id]++; $in_cache = true; } if ($globals['start_time'] - $cache['time'] > 3.0 + rand(0, 100) / 100) { // We use random to minimize race conditions for deleting the cache if ($in_cache && !memcache_mdelete($key)) { memcache_madd($key, array()); syslog(LOG_INFO, "store_clicks: Delete failed"); } ksort($cache); // To avoid transaction's deadlocks $show_errors = $db->show_errors; $db->show_errors = false; // we know there can be lock timeouts :( $tries = 0; // By the way, freaking locking timeouts with few updates per second with this technique while ($tries < 3) { $error = false; $db->transaction(); $total = 0; $r = true; foreach ($cache as $id => $counter) { if ($id > 0 && $counter > 0) { $r = $db->query("INSERT INTO link_clicks (id, counter) VALUES ({$id},{$counter}) ON DUPLICATE KEY UPDATE counter=counter+{$counter}"); // $r = $db->query("UPDATE link_clicks SET counter=counter+$counter WHERE id = $id"); if (!$r) { break; } $total += $counter; } } if ($r) { $db->commit(); $tries = 100000; // Stop it } else { $tries++; syslog(LOG_INFO, "failed {$tries} attempts in store_clicks"); $db->rollback(); } } $db->show_errors = $show_errors; } else { memcache_madd($key, $cache); } }
$from_where = " FROM links, users WHERE user_level not in ('disabled', 'autodisabled') and link_status = 'published' AND link_author=user_id GROUP BY link_author"; $order_by = " ORDER BY count DESC "; break; case 4: $select = "SELECT user_id, count(*) as count "; $from_where = " FROM comments, users WHERE user_level not in ('disabled', 'autodisabled') and comment_user_id=user_id GROUP BY comment_user_id"; $order_by = " ORDER BY count DESC "; break; case 5: $select = "SELECT user_id, count(*) as count "; $from_where = " FROM votes, users WHERE vote_type='links' and vote_user_id=user_id GROUP BY vote_user_id"; $order_by = " ORDER BY count DESC "; break; } $sql = "{$select} {$from_where} {$order_by} LIMIT {$page_size}"; if (!($users = unserialize(memcache_mget($sql)))) { $users = $db->get_results($sql); memcache_madd($sql, serialize($users), 3600); } do_header(_('usuarios') . ' | ' . $globals['site_name']); echo '<div id="singlewrap">' . "\n"; echo '<div class="topheading"><h2>' . _('estadísticas de usuarios') . '</h2></div>'; echo '<table class="decorated"><tr>'; // Print headers for ($i = 0; $i < count($items); $i++) { echo '<th class="short">'; if ($i == $sortby) { echo '<span class="info_s">' . $items[$i] . '</span>'; } elseif ($i <= 3 && $i > 0) { // Don't show order by votes or comment // Too much CPU and disk IO consuption
ping_error('cache directory not available'); } if (!is_writeable($globals['cache_dir'])) { ping_error('cache directory not writeble'); } // Check access to DB $db->connect(); if (!$db->connected) { // Force DB access ping_error('DB not available'); } // Check memcache if (memcache_menabled()) { $data = array(1, 2, 3); memcache_madd('ping', $data, 10); $result = memcache_mget('ping'); if (!$result || $data != $result) { ping_error('memcache failed'); } } } echo "pong\n"; function ping_error($log) { header('HTTP/1.1 500 Server error'); if (!empty($log)) { echo "ERROR ping: {$log}"; syslog(LOG_INFO, "ERROR ping: {$log}"); } die; }