Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
User Posts

Go to Profile

And I do like so to detect the cases for the announce url


// Detect Public/Private trackers - Fixed - Feb 27, 2020
$matches = [];  
if ($row["external"] = 'yes' && !preg_match('{^http://[\w\.]*website.com/}i', $row["announce"], $matches)) {
   print("<p>Public Tracker <span style='color:#C0C0C0;padding-left:10px'>" . htmlspecialchars($row['announce']) . "</span></p>");
}
if ($row["external"] = 'no' && $CURUSER && preg_match('{^http://[\w\.]*switch-torrents.com/}i', $row["announce"], $matches)) {
   print("<p><img src='/images/q_block_private.png' style='height:22px;width:22px;vertical-align:top;margin-right:7px' /> Private Tracker <br /><span style='color:#808080;padding-top:15px'>" . $row['announce'] . "</span></p>");
}
if ($row["external"] = 'no' && !$CURUSER && preg_match('{^http://[\w\.]*switch-torrents.com/}i', $row["announce"], $matches)) {
   print("<p><img src='/images/q_block_private.png' style='height:22px;width:22px;vertical-align:top;margin-right:7px;color:#C0C0C0' /> Private Tracker (<a href='" . $site_config['SITEURL'] . "/signin/?returnto=/details/$id/'>sign in</a> for access key)</p>");
}
If you are only private tracking torrents (your own announce strictly), then this mod won't do much. You can still modify it to update tables without the check by removing


if ($row["external"] = 'yes' && $CURUSER["control_panel"]=="yes") {
// Keep all this code inside
}


I dont trust external="no", it never seems to work. I would use != "yes" which is the opposite, much like a negative value in css, same idea.
Its all on pause now, I can not seem to get $pager to work nicely with the memcached function. Until I do, its on pause and won't be encouraging the switch. Doesn't make sense if users can not use the pager.
"spiritblue, post: 68023, member: 401":

thank you one more addition to this hack


That isn't an addition, that is default TT code that should always remain in torrents-details.php, I instruct to add code under due to how it queries SQL first, any position before that fails to retrieve $row.
If you don't want to deal with the unknown with the passkey system, and lack of FAQ on this matter specific to TT, you can simply achieve it reliably this way. This opens the door for AJAX automatic announce updates (like regenerating new passkeys with a button for user), including peers and seeds. Got tired of this so I made a solution, I needed this working.

Open torrents-upload.php and find:

if (!in_array($announce, $announce_urls, 1)) {
           $external = 'yes';
       } else {
           $external = 'no';
       }


Replace with

$external = 'yes'; // FORCE YES TO ALL UPLOADS. QUERY UPDATE TO 'OFF' IF PRIVATE & UPDATE PASSKEY (SHA1 COMING SOON) - torrents-details.php


Your just forcing external at all times. Next, open torrents-details.php and find

$row = mysql_fetch_assoc($res);


After that, add:

// Condition: ALL torrents are now external by default on upload.
// Fix: Detect if torrent is external, match table url to private announce ($announce), generate passkey, update table - Feb 26, 2020

if ($row["external"] = 'yes' && $CURUSER["control_panel"]=="yes") { // Admin only

   $matches = [];
   $generatekey = substr(md5($row['name']), 17, 20);  // Generate 15 char passkey. String cut twice, decoding difficult.
   $announce = $site_config['announce_list'] . '?passkey=' . $generatekey;
   if (preg_match('{^http://[\w\.]*website.com/}i', $row["announce"], $matches)) {
      SQL_Query_exec("UPDATE torrents SET external='no', announce=" . sqlesc($announce) . " WHERE id=$id");
      SQL_Query_exec("UPDATE users SET passkey=" . sqlesc($generatekey) . " WHERE id=$CURUSER[id]");
   }
}


Change website.com to your real domain. I didn't optimize much of this, it can be better. I see 2 areas that could be improved.

Now when a user visits a private torrent, but the torrents-upload.php failed to take action, passkey all that mess.. this just does it for you on first/only page load.
The first post was a really poor way of doing this, I've done something a lot better that allows AJAX to auto-update the torrent on first and only page view. This makes a lot more sense. Try it if you like, I couldn't find another way.

I'll be using this proudly - [color=rgb(235, 107, 86)]torrents-details.php[/color]
// Condition: ALL torrents are now external by default on upload.
// Fix: Detect if torrent is external, match table url to private announce ($domain), generate passkey, update table - Feb 26, 2020

if ($row["external"] = 'yes' && $CURUSER["control_panel"]=="yes") { // Admin only

   $matches = [];
   $domain = 'http://www.website.com/announce?passkey=' . substr(md5($row['name']), 17, 20);
   if (preg_match('{^http://[\w\.]*website.com/}i', $row["announce"], $matches)) {
      SQL_Query_exec("UPDATE torrents SET external='no', announce=" . sqlesc($domain) . " WHERE id=$id");
   }
}
Hey everyone,

I'm trying to check against the parsed .torrent on torrents-upload.php as it fails to consider passkey in [color=rgb(251, 160, 38)]$site_config['announce_list'] [/color][color=rgb(204, 204, 204)]so anything we upload using our own announce url (our own domain), it fails to check
if it is anyway different from announce_list, which means uploads are ALWAYS flagged as "external" which they are not and hold no other backup trackers. Every line of config is in tact, and I take that file seriously.[/color]

I can not figure out for the life of me how to do a simple check on our domain against the array. Thrown maybe 6 different solutions at it, and no dice. var_dump is helpful but I just can't call my function correctly, or any other
way of doing this.

Problem:
Upload private torrent (with our announce url). Thinks it is external, and does just that. .torrent metadata confirmed. Makes no sense.

Desired Solution:
Upload a private torrent and see it as non-external. To not fail on domain validity (what the hell?)

I've tried:


var_dump(CheckTracker());

   function CheckTracker($domain){ // returns true on domain, or false on domain
   
   $domain = "http://website.com/announce";
   if (preg_match('{^http://[\w\.]*website.com/}i', $domain)) {
          return true;    // domain is a match from what is seen in .torrent in any pattern.
   } else {
          return false;    // domain is a NOT match from what is seen in .torrent in any pattern.
          }
  // return; // <- this returns the full url of current page
   }


And further on torrents-upload.php


        $TorrentInfo  = array();
       $TorrentInfo  = ParseTorrent("$torrent_dir/$fname");
       $announce     = $TorrentInfo[0];
       $infohash     = $TorrentInfo[1];
       $creationdate = $TorrentInfo[2];
       $internalname = $TorrentInfo[3];
       $torrentsize  = $TorrentInfo[4];
       $filecount    = $TorrentInfo[5];
       $annlist      = $TorrentInfo[6];
       $comment      = $TorrentInfo[7];
       $filelist     = $TorrentInfo[8];
   
       if (!in_array($announce, CheckTracker($annlist) === false)) {
       
       $external = 'yes';
   
       } else {
   
           $external = 'no';
      }
       


CheckTracker() has had many different passes, with and without a variable. The function echo perfectly fine, both on false/true/string. How to pass it over to the array check??
true, false, string.. doesn't matter. It almost entirely ignores it.

See, I'm trying to bypass the announce_list config variable because thats how this started. So I'm trying to jump in before it checks that, to validate our announce url using preg_match(). Anyone know what I'm missing here?

The reason for all of this mess is because this does not work:

site_config['PASSKEYURL'] =  "$site_config[announce_list]?passkey=%s";


Because that parameter will never pass over, and lack of feedback on StackOverflow only adds to the mystery. Pissing me off.. does this line above even work for anybody?
Snatchlist [TTv3] — 2020-02-26 19:21:35 in v3 Mods Completed
Sorry, what does this mod do exactly? Is it just a table with stored stats on non-external torrents?
category picture — 2020-02-26 19:12:24 in v3 Mods Requests
You won't focus on the code 'unless you want it'. You want to start by uploading your category images now, into /images/categories and next you want to use admincp (I use database) to update the images so the site can use them.

yourwebsite.com/admincp.php?action=categories&do=view

Then you want to click [EDIT] for each item. In the image field, you want this format:  

images/categories/someimage.jpg

someimage.jpg does not exist, that is a example. Use your own images and save settings. Clear browser cache and refresh.
category picture — 2020-02-26 18:50:45 in v3 Mods Requests
Easily, and most of it is already implemented in V3. Looks like you just need to upload category images to /images/categories and make the changes 'image' column in 'categories' database table to reflect changes: images/categories/someimage.jpg

If you wish to strip out the parent category and only show the sub category, use this:


$shortcatname = htmlspecialchars(str_replace("Movies:", "", $row["cat_name"]));


Replace Movies with your category name. Useful for clean layouts.
It depends on what the query does. If you have a set of users and then want to grab the "top 10 music affinity" with some of those friends, it is worth to have both cachings: - each friend (in fact, each user of the site) - the top 10 query for each user (space is cheaper than CPU time)

But in general it is worth to store in Memcached all individual entities that are going to be used frequently (either in the same code execution, or in subsequent requests or by other users). Then things like CPU or resource heavy queries and data processings either Memcached-them or delegate them to async. jobs instead of making them realtime (e.g. Top 10 site users doesn't needs to be realtime, can be updated hourly or daily). And of course taking into account that if you store and Memcached individual entities, you have to remove all referential integrity from the DB to be able to reuse them either individually or in groups.
I disagree, but its all about learning. It does exactly what its supposed to. Set the lifetime according to your traffic and upload frequency, as you do with tuning your sitemap.xml change frequency, same idea.

This method is serializing data much more efficiently than the 2 previous codes I went with to the end, so this may just be better than what people are using. Maybe the caching code you have needs a look over.

This is what I have, and has no respect to default TT template.

index.php  :  torrents_cached();

functions.php  :

// NEW Memcached TorrentTable function
function torrents_cached(){

   global $site_config, $CURUSER, $THEME, $LANGUAGE;

   $memc = new Memcached();
   $memc->addServer("127.0.0.1", 11211);

//Set the table name according to Your Table
$key = md5("SELECT torrents.id, torrents.hits, torrents.views, torrents.anon, torrents.announce, torrents.category, torrents.leechers, torrents.nfo, torrents.seeders, torrents.name, torrents.times_completed, torrents.size, torrents.added, torrents.comments, torrents.numfiles, torrents.filename, torrents.owner, torrents.external, torrents.freeleech, torrents.image1, torrents.image2, torrents.hits, torrents.cover1 AS cover, categories.name AS cat_name, categories.image AS cat_pic, categories.parent_cat AS cat_parent, users.username, users.avatar, users.privacy, IF(torrents.numratings < 2, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN users ON torrents.owner = users.id WHERE visible = 'yes' AND banned = 'no' ORDER BY torrents.added DESC LIMIT 50");
$get_result = array();

$get_result = $memc->get($key);
if($get_result){
echo '<b>Read from Memory:</b><br><br>';
foreach( $get_result as $val ){

// CHEAT SHEET - Array from memory - all tested:
/*
echo 'Name: ' . $val[0] . '<br>';
echo 'ID: ' . $val[1] . '<br>';
echo 'Cover: ' . $val[2] . '<br>';
echo 'Downloads: ' . $val[3] . '<br>';
echo 'Views: ' . $val[4] . '<br>';
echo 'Owner: ' . $val[5] . '<br>';
echo 'Seeders: ' . $val[6] . '<br>';
echo 'Leechers: ' . $val[7] . '<br>';
echo 'Category: ' . $val[8] . '<br>';
echo 'Size: ' . $val[9] . '<br>';
echo 'Image1: ' . $val[10] . '<br>';
echo 'Image2: ' . $val[11] . '<br>';
echo 'Added: ' . $val[12] . '<br>';
*/

// NOT Cached: $query["avatar"] - Until I find a way to use the left join.
// NOT Cached: $query["cat_name"] - Until I find a way to use the left join.

print("<div itemscope itemtype='http://schema.org/ItemList' class='row news-feed'>
     
          <div class='col t12'>
          <div id='infinite-newsfeed-container-page-1' style='_margin-top:-.5rem;'>
          <section class='recent-news card' style='overflow:visible'>");
   print('<article itemprop="itemListElement" itemscope itemtype="http://schema.org/Article" class="row" id="post-52856" class="post-52856 post type-post status-publish format-standard has-post-thumbnail hentry category-news tag-fifa-19 tag-switch news">
   <div class="col t5 col-card-image">
          <div class="card-image">');
   print("<a itemprop=\"url\" href=\"" . $site_config['SITEURL'] . "/details/" . $val[1] . "/\">");
   print("<img src='" . $site_config['SITEURL'] . "/uploads/images/" . $val[10] . "' style='height:139px;' /></a>");
   print("</div></div>");

   print("<div class=\"col t7\">\n");

           $shortcatname = htmlspecialchars(str_replace("Switch:", "", $val[8])); // strip category name
           $char1 = 39; // Cut name length
           $smallname = htmlspecialchars(CutName($val[0], $char1));
           $dispname = $smallname;
           //$descrs = $row["description"];
           //$last_access = $CURUSER["last_browse"];
           $time_now = gmtime();
           if ($last_access > $time_now || !is_numeric($last_access))
               $last_access = $time_now;
           //if (sql_timestamp_to_unix_timestamp($val[12]) >= $last_access)
               //$dispname .= "New";
           //if ($row["freeleech"] == 1)
           //    $dispname .= " <img src='images/free.gif' border='0' alt='' />";
           //if ($row["team"] != 0)
           //    $dispname .= " <img src='" . $row["teamimage"] . "' border='0' alt = '" . $row["teamname"] . "'>";
       
     
           //if ($CURUSER) {
           //    $bookt = SQL_Query_exec("SELECT torrentid FROM bookmarks WHERE torrentid = $id AND userid = $CURUSER[id]");
           //    if (mysql_num_rows($bookt) > 0) {
           //        $bookmark = "<a href='" . $site_config['SITEURL'] . "/bookmarks/'><img src='" . $site_config['SITEURL'] . "/images/booked.png' width='25' height='25' border='0' title='Bookmarked'></a>";
           //    } else {
                   $bookmark = "<a href='" . $site_config['SITEURL'] . "/bookmark/$id/'><img src='" . $site_config['SITEURL'] . "/images/book.png' width='25' height='25' border='0' title='Bookmark this Torrent'></a>";
           //        echo "<a href='" . $site_config['SITEURL'] . "/bookmark/$id/'><img src='" . $site_config['SITEURL'] . "/images/book.png' width='25' height='25' border='0' title='Bookmark this Torrent'></a>";
           //    }
           // }
   
       
           //if (($row["anon"] == "yes" || $row["privacy"] == "strong") && $CURUSER["id"] != $row["owner"] && $CURUSER["edit_torrents"] != "yes")
           //        echo "Anonymous";
           //        elseif ($row["username"])

               // New tab-style torrent stats per result - homepage (views, downloads) - Feb 2, 2020
           print("<span class=\"post-topic left\" style='text-transform:capitalize;'>Added ".date("M d, Y", utc_to_tz_time($val[12]))." <small>by</small> <span style='text-transform:capitalize;'><a href='" . $site_config['SITEURL'] . "/user/?id=$val[5]'>".$row['username']."</a> <img src='" . $site_config['SITEURL'] . "/" . $row['avatar'] . "' style=\"margin-bottom:-3px;height:15px;width:15px;border-radius:50%\" /></span></span><span class=\"post-topic right\" style='text-transform:lowercase;color:#242424;cursor:default;margin-right:-1px;margin-top:-20px'><span style='box-shadow:inset 0 0 10px #D42128;color:#FFF;background:#ED2324;border-radius:4px;padding-left:7px;padding-right:7px;padding-top:4px;padding-bottom:3px'>$val[4] <img src='" . $site_config['SITEURL'] . "/images/index_views.png' class='responsive-img' style='width:16px;height:16px;vertical-align:top' /></span><span style='box-shadow:inset 0 0 10px #D42128;color:#FFF;background:#ED2324;border-radius:4px;padding-left:7px;padding-right:6px;padding-top:4px;padding-bottom:3px;margin-left:7px'>$val[3] <img src='/images/index_dl.png' class='responsive-img' style='width:12px;height:8px;vertical-align:middle' /></span></span>");
   
           if ($CURUSER) {
               print("<span itemprop=\"name\"><h3 itemprop=\"headline\" class=\"entry-title\">" . (count($expandrows) ? "<a rel=\"bookmark\" href=\"javascript: klappe_torrent('t" . $val[0] . "')\"></a>" : "") . "&nbsp;$bookmark <a title=\"" . $val[0] . "\" href=\"/details/$val[1]/\" style='color:#000;text-decoration:none;'>$dispname</a> $freeleech $new</h3></span>");
           } elseif (!$CURUSER) {
               print("<span itemprop=\"name\"><h3 itemprop=\"headline\" class=\"entry-title\">" . (count($expandrows) ? "<a rel=\"bookmark\" href=\"javascript: klappe_torrent('t" . $val[0] . "')\"></a>" : "") . "&nbsp;<a href='/signin/?returnto=/bookmark.php'><img src='../images/book.png' width='25' height='25' border='0' title='Bookmarked'></a> <a title=\"" . $val[0] . "\" href=\"/details/$val[1]/\" style-='color:#000;text-decoration:none;'>$dispname</a> $freeleech $new</h3></span>");
           }
       
           print("<div itemprop=\"commentCount\" class=\"comments card-title z-depth-1 valign-wrapper\"><span class=\"valign\"><a itemprop=\"discussionUrl\" class=\"hidden_count\" href=\"/details/$id/#comments\">" . number_format($row["comments"]) . "</a></span></div>");

           if ($CURUSER) { // current user
           print("<form method='post' action='" . $site_config['SITEURL'] . "/details/$val[1]/' onsubmit='return validate();'><span style='box-shadow:inset 0 0 10px #D42128;background:#ED2324;border-bottom-left-radius:3px;padding-left:7px;padding-right:7px;padding-top:4px;padding-bottom:3px;position:absolute;left:0px;bottom:0px'><a style='color:#FFF;font-size:14px' href='" . $site_config['SITEURL'] . "/cat/" . $val[8] . "/' title='Browse " . $shortcatname . " Torrents'>" . $shortcatname . "</a></span><span style='margin-right:20px;'><button class='btn btn-danger' onclick='this.form.submit();' type='submit' style='height:35px;width:158px;margin-top:-9px;'>Torrent</button></span><span style='font-size:18.75pt;color:#C0C0C0;'>".mksize($val[9])."</span><div style='clear:both;display:inline;float:right;text-align:right;'><span style='text-align:right;font-size:18.75pt;color:#2E8B57;'>".number_format($val[6])."</span>
           <span style='text-align:right;font-size:18.75pt;color:#C0C0C0;padding-left:10px;padding-right:5px;'>/</span></form>");
           print("<span style='text-align:right;font-size:18.75pt;color:#DC143C;'>" . number_format($val[7]) . "</span>\n");

           /*  WITH DOWNLOAD BUTTON (DIRECT DOWNLOADING)
           print("<form method='post' action='" . $site_config['SITEURL'] . "/download/$id/" . rawurlencode($row["filename"]) . "' onsubmit='return validate();'><span style='box-shadow:inset 0 0 10px #D42128;background:#ED2324;border-bottom-left-radius:3px;padding-left:7px;padding-right:7px;padding-top:4px;padding-bottom:3px;position:absolute;left:0px;bottom:0px'><a style='color:#FFF;font-size:14px' href='" . $site_config['SITEURL'] . "/cat/" . $row['category'] . "/' title='Browse " . $shortcatname . " Torrents'>" . $shortcatname . "</a></span><span style='margin-right:20px;'><button class='btn btn-danger' onclick='this.form.submit();' type='submit' style='height:35px;width:158px;margin-top:-9px;'>Download</button></span><span style='font-size:18.75pt;color:#C0C0C0;'>".mksize($row["size"])."</span><div style='clear:both;display:inline;float:right;text-align:right;'><span style='text-align:right;font-size:18.75pt;color:#2E8B57;'>".number_format($row["seeders"])."</span>
           <span style='text-align:right;font-size:18.75pt;color:#C0C0C0;padding-left:10px;padding-right:5px;'>/</span></form>");
           */
       
           } else { // not current user
           print("<form method='post' action='" . $site_config['SITEURL'] . "/signin/?returnto=/download/$val[1]/" . rawurlencode($row["filename"]) . "' onsubmit='return validate();'><span style='box-shadow:inset 0 0 10px #D42128;background:#ED2324;border-bottom-left-radius:3px;padding-left:7px;padding-right:7px;padding-top:4px;padding-bottom:3px;position:absolute;left:0px;bottom:0px'><a style='color:#FFF;font-size:14px' href='" . $site_config['SITEURL'] . "/cat/" . $val[8] . "/' title='Browse " . $shortcatname . " Torrents'>" . $shortcatname . "</a></span><span style='margin-right:20px;'><button class='btn btn-danger' onclick='this.form.submit();' type='submit' style='height:35px;width:158px;margin-top:-9px;'>Torrent</button></span><span style='font-size:18.75pt;color:#C0C0C0;'>".mksize($val[9])."</span><div style='clear:both;display:inline;float:right;text-align:right;'><span style='text-align:right;font-size:18.75pt;color:#2E8B57;'>".number_format($val[6])."</span>
           <span style='text-align:right;font-size:18.75pt;color:#C0C0C0;padding-left:10px;padding-right:5px;'>/</span></form>");
           print("<span style='text-align:right;font-size:18.75pt;color:#DC143C;'>" . number_format($val[7]) . "</span>\n");

           }
       
           print("</div></article>
           </section>
           </div><!-- END #infinite-newsfeed-container-page-1 -->
           </div><!-- END col t12 -->
           </div><!-- END row news-feed -->
           </div><!-- END content-inner -->");
}

}else{ // ----------------------------------

//Set the table name according to Your Table
$query = "SELECT torrents.id, torrents.hits, torrents.views, torrents.anon, torrents.announce, torrents.category, torrents.leechers, torrents.nfo, torrents.seeders, torrents.name, torrents.times_completed, torrents.size, torrents.added, torrents.comments, torrents.numfiles, torrents.filename, torrents.owner, torrents.external, torrents.freeleech, torrents.image1, torrents.image2, torrents.hits, torrents.cover1 AS cover, categories.name AS cat_name, categories.image AS cat_pic, categories.parent_cat AS cat_parent, users.username, users.avatar, users.privacy, IF(torrents.numratings < 2, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN users ON torrents.owner = users.id WHERE visible = 'yes' AND banned = 'no' ORDER BY torrents.added DESC LIMIT 50";
$result = mysql_query($query) or die('Error in Query!');

echo '<b>Read from Database:</b><br><br>';

$getAllResult = array();
while( $row = mysql_fetch_array($result) ){

   //print "<p><small>Retrieved data from Memcached</small></p>";


print("<div itemscope itemtype='http://schema.org/ItemList' class='row news-feed'><div class='col t12'>
          <div id='infinite-newsfeed-container-page-1' style='_margin-top:-.5rem;'>
          <section class='recent-news card' style='overflow:visible'>");
   print('<article itemprop="itemListElement" itemscope itemtype="http://schema.org/Article" class="row" id="post-52856" class="post-52856 post type-post status-publish format-standard has-post-thumbnail hentry category-news tag-fifa-19 tag-switch news"><div class="col t5 col-card-image">
          <div class="card-image">');
   print("<a itemprop=\"url\" href=\"" . $site_config['SITEURL'] . "/details/$id/\">");
   print("<img src='" . $site_config['SITEURL'] . "/uploads/images/" . $row['image1'] . "' style='height:139px;' /></a>");
   print("</div></div>");

   print("<div class=\"col t7\">\n");

           $shortcatname = htmlspecialchars(str_replace("Switch:", "", $row["cat_name"])); // strip category name
           $char1 = 39; // Cut name length
           $smallname = htmlspecialchars(CutName($row["name"], $char1));
           $dispname = $smallname;
           $descrs = $row["description"];
           $last_access = $CURUSER["last_browse"];
           $time_now = gmtime();
           if ($last_access > $time_now || !is_numeric($last_access))
               $last_access = $time_now;
           //if (sql_timestamp_to_unix_timestamp($row["added"]) >= $last_access)
               //$dispname .= "New";
           if ($row["freeleech"] == 1)
               $dispname .= " <img src='images/free.gif' border='0' alt='' />";
           if ($row["team"] != 0)
               $dispname .= " <img src='" . $row["teamimage"] . "' border='0' alt = '" . $row["teamname"] . "'>";
           /*
           if ($CURUSER) {
               $bookt = SQL_Query_exec("SELECT torrentid FROM bookmarks WHERE torrentid = $id AND userid = $CURUSER[id]");
               if (mysql_num_rows($bookt) > 0) {
                   $bookmark = "<a href='" . $site_config['SITEURL'] . "/bookmarks/'><img src='" . $site_config['SITEURL'] . "/images/booked.png' width='25' height='25' border='0' title='Bookmarked'></a>";
               } else {
                   $bookmark = "<a href='" . $site_config['SITEURL'] . "/bookmark/$id/'><img src='" . $site_config['SITEURL'] . "/images/book.png' width='25' height='25' border='0' title='Bookmark this Torrent'></a>";
               }
           
            }
           */
       
           if (($row["anon"] == "yes" || $row["privacy"] == "strong") && $CURUSER["id"] != $row["owner"] && $CURUSER["edit_torrents"] != "yes")
                   echo "Anonymous";
               elseif ($row["username"])

               // New tab-style torrent stats per result - homepage (views, downloads) - Feb 2, 2020
           print("<span class=\"post-topic left\" style='text-transform:capitalize;'>Added ".date("M d, Y", utc_to_tz_time($row['added']))." <small>by</small> <span style='text-transform:capitalize;'><a href='" . $site_config['SITEURL'] . "/user/?id=$row[owner]'>".$row['username']."</a> <img src='" . $site_config['SITEURL'] . "/" . $row['avatar'] . "' style=\"margin-bottom:-3px;height:15px;width:15px;border-radius:50%\" /></span></span><span class=\"post-topic right\" style='text-transform:lowercase;color:#242424;cursor:default;margin-right:-1px;margin-top:-20px'><span style='box-shadow:inset 0 0 10px #D42128;color:#FFF;background:#ED2324;border-radius:4px;padding-left:7px;padding-right:7px;padding-top:4px;padding-bottom:3px'>$row[views] <img src='" . $site_config['SITEURL'] . "/images/index_views.png' class='responsive-img' style='width:16px;height:16px;vertical-align:top' /></span><span style='box-shadow:inset 0 0 10px #D42128;color:#FFF;background:#ED2324;border-radius:4px;padding-left:7px;padding-right:6px;padding-top:4px;padding-bottom:3px;margin-left:7px'>$row[hits] <img src='/images/index_dl.png' class='responsive-img' style='width:12px;height:8px;vertical-align:middle' /></span></span>");
   
           if ($CURUSER) {
               print("<span itemprop=\"name\"><h3 itemprop=\"headline\" class=\"entry-title\">" . (count($expandrows) ? "<a rel=\"bookmark\" href=\"javascript: klappe_torrent('t" . $row['id'] . "')\"></a>" : "") . "&nbsp;$bookmark <a title=\"" . $row["name"] . "\" href=\"/details/$id/\" style='color:#000;text-decoration:none;'>$dispname</a> $freeleech $new</h3></span>");
           } elseif (!$CURUSER) {
               print("<span itemprop=\"name\"><h3 itemprop=\"headline\" class=\"entry-title\">" . (count($expandrows) ? "<a rel=\"bookmark\" href=\"javascript: klappe_torrent('t" . $row['id'] . "')\"></a>" : "") . "&nbsp;<a href='/signin/?returnto=/bookmark.php'><img src='../images/book.png' width='25' height='25' border='0' title='Bookmarked'></a> <a title=\"" . $row["name"] . "\" href=\"/details/$id/\" style-='color:#000;text-decoration:none;'>$dispname</a> $freeleech $new</h3></span>");
           }
           
           print("<div itemprop=\"commentCount\" class=\"comments card-title z-depth-1 valign-wrapper\"><span class=\"valign\"><a itemprop=\"discussionUrl\" class=\"hidden_count\" href=\"/details/$id/#comments\">" . number_format($row["comments"]) . "</a></span></div>");

           if ($CURUSER) { // current user
           print("<form method='post' action='" . $site_config['SITEURL'] . "/details/$id/' onsubmit='return validate();'><span style='box-shadow:inset 0 0 10px #D42128;background:#ED2324;border-bottom-left-radius:3px;padding-left:7px;padding-right:7px;padding-top:4px;padding-bottom:3px;position:absolute;left:0px;bottom:0px'><a style='color:#FFF;font-size:14px' href='" . $site_config['SITEURL'] . "/cat/" . $row['category'] . "/' title='Browse " . $shortcatname . " Torrents'>" . $shortcatname . "</a></span><span style='margin-right:20px;'><button class='btn btn-danger' onclick='this.form.submit();' type='submit' style='height:35px;width:158px;margin-top:-9px;'>Torrent</button></span><span style='font-size:18.75pt;color:#C0C0C0;'>".mksize($row["size"])."</span><div style='clear:both;display:inline;float:right;text-align:right;'><span style='text-align:right;font-size:18.75pt;color:#2E8B57;'>".number_format($row["seeders"])."</span>
           <span style='text-align:right;font-size:18.75pt;color:#C0C0C0;padding-left:10px;padding-right:5px;'>/</span></form>");
           print("<span style='text-align:right;font-size:18.75pt;color:#DC143C;'>" . number_format($val[7]) . "</span>\n");
       
           /*  WITH DOWNLOAD BUTTON (DIRECT DOWNLOADING)
           print("<form method='post' action='" . $site_config['SITEURL'] . "/download/$id/" . rawurlencode($row["filename"]) . "' onsubmit='return validate();'><span style='box-shadow:inset 0 0 10px #D42128;background:#ED2324;border-bottom-left-radius:3px;padding-left:7px;padding-right:7px;padding-top:4px;padding-bottom:3px;position:absolute;left:0px;bottom:0px'><a style='color:#FFF;font-size:14px' href='" . $site_config['SITEURL'] . "/cat/" . $row['category'] . "/' title='Browse " . $shortcatname . " Torrents'>" . $shortcatname . "</a></span><span style='margin-right:20px;'><button class='btn btn-danger' onclick='this.form.submit();' type='submit' style='height:35px;width:158px;margin-top:-9px;'>Download</button></span><span style='font-size:18.75pt;color:#C0C0C0;'>".mksize($row["size"])."</span><div style='clear:both;display:inline;float:right;text-align:right;'><span style='text-align:right;font-size:18.75pt;color:#2E8B57;'>".number_format($row["seeders"])."</span>
           <span style='text-align:right;font-size:18.75pt;color:#C0C0C0;padding-left:10px;padding-right:5px;'>/</span></form>");
           */
       
           } else { // not current user
           print("<form method='post' action='" . $site_config['SITEURL'] . "/signin/?returnto=/download/$id/" . rawurlencode($row["filename"]) . "' onsubmit='return validate();'><span style='box-shadow:inset 0 0 10px #D42128;background:#ED2324;border-bottom-left-radius:3px;padding-left:7px;padding-right:7px;padding-top:4px;padding-bottom:3px;position:absolute;left:0px;bottom:0px'><a style='color:#FFF;font-size:14px' href='" . $site_config['SITEURL'] . "/cat/" . $row['category'] . "/' title='Browse " . $shortcatname . " Torrents'>" . $shortcatname . "</a></span><span style='margin-right:20px;'><button class='btn btn-danger' onclick='this.form.submit();' type='submit' style='height:35px;width:158px;margin-top:-9px;'>Torrent</button></span><span style='font-size:18.75pt;color:#C0C0C0;'>".mksize($row["size"])."</span><div style='clear:both;display:inline;float:right;text-align:right;'><span style='text-align:right;font-size:18.75pt;color:#2E8B57;'>".number_format($row["seeders"])."</span>
           <span style='text-align:right;font-size:18.75pt;color:#C0C0C0;padding-left:10px;padding-right:5px;'>/</span></form>");
           print("<span style='text-align:right;font-size:18.75pt;color:#DC143C;'>" . number_format($val[7]) . "</span>\n");
           }
       

           print("</div></article>
           </section>
           </div><!-- END #infinite-newsfeed-container-page-1 -->
           </div><!-- END col t12 -->
           </div><!-- END row news-feed -->
           </div><!-- END content-inner -->");

// Result set - Full array for what we need.
$getAllResult[] = array($row['name'], $row['id'], $row['cover'], $row['hits'], $row['views'], $row['owner'], $row['seeders'], $row['leechers'], $row['category'], $row['size'], $row['image1'], $row['image2'], $row['added']);
//$getAllResult[] = array($row['name'], $row['id'], $row['cover']);
}

// Set Data In Cache
// 300 = 5 minutes, 600 = 10 minutes, 900 = 15 minutes, 0 = lifetime
$memc->set($key, $getAllResult, 7200);
}

} // end function


Change [color=rgb(184, 49, 47)]7200[/color] to your desired cache time (near last line)
That’s why you set the lifetime for the cache, I’m not understanding quite what you mean. This lines up with almost any memcached php tutorial on the web. Torrent table split the query process in half between the function and continued on with the rest of the execution on index.php. Remove whole block on index and write your own. The internal caching Is broken, and was never updated.

Caching little tid bits of data like a users age, or signature is a waste of resource and time, you want to target the highest hits like the torrents on the home page maybe even content on torrents-details.php
I got Memcached working completely after maybe 6 hours. Created a new torrents_cached() and replaced everything for torrenttable() on index.php with 1 line.

So.. after all this time today, it works great. I flushed the storage at every request which brought time to be very long, but reliably tested. Simple plugged my existing HTML into it, traced the array values from the md5 key => query and found out what all row values are, threw them in after writing a quick "cheat sheet" on the array values and after some testing on that for each value its pulling out at cache time, its pretty good :)

I honestly don't know what the point of this is with such small load for me, as if to say "hey I got it", but maybe someone can find it useful.

The challenge would be to apply it to a stock functions.php for the standard template. Makes sharing difficult when layout is too different.

Anyway, anyone want this function for their site? Will take maybe 1 hour to make compatible & write up quick instructions.
To debug the connection, go with this


<?
/**
* Class and Function List:
* Function list:
* - TTCache()
* - Set()
* - Delete()
* - Get()
* - get_row_count_cached()
* - SQL_Query_exec_cached()
* Classes list:
* - TTCache
*/
$GLOBALS["TTCache"] = new TTCache;

class TTCache
{
function TTCache()
{
 global $site_config;
 $this->cachedir = $site_config["cache_dir"];
 $this->type     = strtolower(trim($site_config["cache_type"]));

 switch ($this->type)
 {
  case "memcached":

   $this->obj      = new Memcached;
   $this
    ->obj
    ->addServer('127.0.0.1', 11211);
   $this
    ->obj
    ->setOption(Memcached::OPT_BINARY_PROTOCOL, true);

  break;
  case "apc":
   if (function_exists("apc_store")) break;
  case "xcache":
   if (function_exists("xcache_set")) break;
  default:
   $this->type = "disk";
  }
 }

 function Set($var, $val, $expire     = 0)
 {
  global $site_config;
  if ($expire == 0) return;
  switch ($this->type)
  {
   case "memcached":
    return $this
     ->obj
     ->set($site_config['SITENAME'] . "_" . $var, $val, 0, $expire);
   break;
   case "apc":
    return apc_store($var, $val, $expire);
   break;
   case "disk":
    $fp = fopen($this->cachedir . "/$var.cache", "w");
    fwrite($fp, serialize($val));
    fclose($fp);
    return;
   break;
   case "xcache":
    return xcache_set($var, serialize($val) , $expire);
   break;
  }
 }

 function Delete($var)
 {
  global $site_config;

  switch ($this->type)
  {
   case "memcached":
    return $this
     ->obj
     ->delete($site_config['SITENAME'] . "_" . $var);
   break;
   case "apc":
    return apc_delete($var);
   break;
   case "disk":
    @unlink($this->cachedir . "/$var.cache");
   break;
   case "xcache":
    return xcache_unset($var);
   break;
  }
 }

 function Get($var, $expire = 0)
 {
  global $site_config;
  if ($expire == 0) return false;
  switch ($this->type)
  {
   case "memcached":
    return $this
     ->obj
     ->get($site_config['SITENAME'] . "_" . $var);
   break;
   case "apc":
    return apc_fetch($var);
   break;
   case "disk":
    $file = $this->cachedir . "/$var.cache";
    if (file_exists($file) && (time() - filemtime($file)) < $expire) return unserialize(file_get_contents($file));
    return false;
    break;
   case "xcache":
    if (xcache_isset($var)) return unserialize(xcache_get($var));
    return false;
    break;
   }
  }
}

// Cached MySQL Functions
function get_row_count_cached($table, $suffix = "")
{
 global $TTCache;

 $query  = "SELECT COUNT(*) FROM $table $suffix";
 $cache  = "get_row_count/" . sha1($query);
 if (($ret    = $TTCache->Get($cache, 300)) === false)
 {
  $res    = SQL_Query_exec($query);
  $row    = mysql_fetch_row($res);
  $ret    = $row[0];
  $TTCache->Set($cache, $ret, 300);
 }
 return $ret;
}

function SQL_Query_exec_cached($query, $cache_time  = 300, $cache_blank = 1)
{
 global $TTCache;

 $cache       = "queries/" . sha1($query);
 if (($rows        = $TTCache->Get($cache, $cache_time)) === false)
 {
  $res         = SQL_Query_exec($query);
  $rows        = array();
  while ($row         = mysql_fetch_assoc($res)) $rows[]             = $row;
  if (count($rows) || $cache_blank) $TTCache->Set($cache, $rows, $cache_time);
 }
 return count($rows) ? $rows : false;
}
?>


This will get you torrent table data back, encoded in JSON but that is where I didn't continue with it. I have JSON disabled on my extension, so if we decode this return data maybe it will kick in. Experiment with the object connection parameters until it clicks and works.

-> [url='https://www.php.net/manual/en/memcached.constants.php']Memcached Predefined Constants[/url]

In the meantime, it does work:

https://www.switch-torrents.com/testmemcached.php
You got as far as implementing the backend support on port 11211, you should include the memcached manager for admincp, it’s easier. Next, is caching and requesting data for torrenttable() which has a 100% success rate/hit. let me reimplement this and see what’s going on. I dedicated to not used this after some tests, so I need to find my code snippet.
I did this weeks ago and demonstrated in index.php and using the PHP mecached management script to monitor data. This guide seems to trail off after the functions.php which implies it’s experimental. Thanks so much, I’ll post my bit today of what I did to torrenttable() caching @ 128MB allocated.
Awesome work guys! Will check out the stable release today.
The default where() function seems to have broke on me, maybe due to a minor mysql version update. So this code does works, but the problem is its sending the direct file system path to the page into the database, instead of page name. I've used your code correctly or it would not be updating record at all, maybe even a white page.

I can't seem to figure it out. While the old function died suddenly, this one seems to be more efficient. Any thoughts?


function where($where, $userid, $update = 1)
{
   if (!is_valid_id($userid)) die;
   if (empty($where)) $where  = "Unknown Location...";
   if ($update) SQL_Query_exec("UPDATE users SET last_access='" . get_date_time() . "', page=" . sqlesc($where) . " WHERE id=" . $userid);
   if (!$update)
   {
       return $where;
   }
   else
   {
       return;
   }
}


I've used different combinations of stdhead() but yours and all others fail. It is inserting a error 404 file path to exactly that, to the database. Is something wrong with this function block?
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 1
  • Members: 0
  • Guests online: 1
  • Comments: 3
  • Messages: 1,728