Browse Source

Upload files to 'classes'

Stortebeker 6 years ago
parent
commit
3310daabc0
4 changed files with 622 additions and 571 deletions
  1. 149
    137
      classes/bencodetorrent.class.php
  2. 23
    23
      classes/bitcoinrpc.class.php
  3. 75
    71
      classes/bookmarks.class.php
  4. 375
    340
      classes/cache.class.php

+ 149
- 137
classes/bencodetorrent.class.php View File

@@ -1,158 +1,170 @@
1
-<?
1
+<?php
2 2
 /**
3 3
  * Torrent class that contains some convenient functions related to torrent meta data
4 4
  */
5
-class BencodeTorrent extends BencodeDecode {
6
-  private $PathKey = 'path';
7
-  public $Files = [];
8
-  public $Size = 0;
5
+class BencodeTorrent extends BencodeDecode
6
+{
7
+    private $PathKey = 'path';
8
+    public $Files = [];
9
+    public $Size = 0;
9 10
 
10
-  /**
11
-   * Create a list of the files in the torrent and their sizes as well as the total torrent size
12
-   *
13
-   * @return array with a list of files and file sizes
14
-   */
15
-  public function file_list() {
16
-    if (empty($this->Dec)) {
17
-      return false;
18
-    }
19
-    $InfoDict =& $this->Dec['info'];
20
-    if (!isset($InfoDict['files'])) {
21
-      // Single-file torrent
22
-      $this->Size = (Int64::is_int($InfoDict['length'])
23
-        ? Int64::get($InfoDict['length'])
24
-        : $InfoDict['length']);
25
-      $Name = (isset($InfoDict['name.utf-8'])
26
-        ? $InfoDict['name.utf-8']
27
-        : $InfoDict['name']);
28
-      $this->Files[] = array($this->Size, $Name);
29
-    } else {
30
-      if (isset($InfoDict['path.utf-8']['files'][0])) {
31
-        $this->PathKey = 'path.utf-8';
32
-      }
33
-      foreach ($InfoDict['files'] as $File) {
34
-        $TmpPath = [];
35
-        foreach ($File[$this->PathKey] as $SubPath) {
36
-          $TmpPath[] = $SubPath;
11
+    /**
12
+     * Create a list of the files in the torrent and their sizes as well as the total torrent size
13
+     *
14
+     * @return array with a list of files and file sizes
15
+     */
16
+    public function file_list()
17
+    {
18
+        if (empty($this->Dec)) {
19
+            return false;
20
+        }
21
+        $InfoDict =& $this->Dec['info'];
22
+        if (!isset($InfoDict['files'])) {
23
+            // Single-file torrent
24
+            $this->Size = (Int64::is_int($InfoDict['length'])
25
+            ? Int64::get($InfoDict['length'])
26
+            : $InfoDict['length']);
27
+            $Name = (isset($InfoDict['name.utf-8'])
28
+            ? $InfoDict['name.utf-8']
29
+            : $InfoDict['name']);
30
+            $this->Files[] = array($this->Size, $Name);
31
+        } else {
32
+            if (isset($InfoDict['path.utf-8']['files'][0])) {
33
+                $this->PathKey = 'path.utf-8';
34
+            }
35
+            foreach ($InfoDict['files'] as $File) {
36
+                $TmpPath = [];
37
+                foreach ($File[$this->PathKey] as $SubPath) {
38
+                    $TmpPath[] = $SubPath;
39
+                }
40
+                $CurSize = (Int64::is_int($File['length'])
41
+                ? Int64::get($File['length'])
42
+                : $File['length']);
43
+                $this->Files[] = array($CurSize, implode('/', $TmpPath));
44
+                $this->Size += $CurSize;
45
+            }
46
+            uasort($this->Files, function ($a, $b) {
47
+                return strnatcasecmp($a[1], $b[1]);
48
+            });
37 49
         }
38
-        $CurSize = (Int64::is_int($File['length'])
39
-          ? Int64::get($File['length'])
40
-          : $File['length']);
41
-        $this->Files[] = array($CurSize, implode('/', $TmpPath));
42
-        $this->Size += $CurSize;
43
-      }
44
-      uasort($this->Files, function($a, $b) {
45
-          return strnatcasecmp($a[1], $b[1]);
46
-        });
50
+        return array($this->Size, $this->Files);
47 51
     }
48
-    return array($this->Size, $this->Files);
49
-  }
50 52
 
51
-  /**
52
-   * Find out the name of the torrent
53
-   *
54
-   * @return string torrent name
55
-   */
56
-  public function get_name() {
57
-    if (empty($this->Dec)) {
58
-      return false;
59
-    }
60
-    if (isset($this->Dec['info']['name.utf-8'])) {
61
-      return $this->Dec['info']['name.utf-8'];
53
+    /**
54
+     * Find out the name of the torrent
55
+     *
56
+     * @return string torrent name
57
+     */
58
+    public function get_name()
59
+    {
60
+        if (empty($this->Dec)) {
61
+            return false;
62
+        }
63
+        if (isset($this->Dec['info']['name.utf-8'])) {
64
+            return $this->Dec['info']['name.utf-8'];
65
+        }
66
+        return $this->Dec['info']['name'];
62 67
     }
63
-    return $this->Dec['info']['name'];
64
-  }
65 68
 
66
-  /**
67
-   * Find out the total size of the torrent
68
-   *
69
-   * @return string torrent size
70
-   */
71
-  public function get_size() {
72
-    if (empty($this->Files)) {
73
-      if (empty($this->Dec)) {
74
-        return false;
75
-      }
76
-      $FileList = $this->file_list();
69
+    /**
70
+     * Find out the total size of the torrent
71
+     *
72
+     * @return string torrent size
73
+     */
74
+    public function get_size()
75
+    {
76
+        if (empty($this->Files)) {
77
+            if (empty($this->Dec)) {
78
+                return false;
79
+            }
80
+            $FileList = $this->file_list();
81
+        }
82
+        return $FileList[0];
77 83
     }
78
-    return $FileList[0];
79
-  }
80 84
 
81
-  /**
82
-   * Checks if the "private" flag is present in the torrent
83
-   *
84
-   * @return true if the "private" flag is set
85
-   */
86
-  public function is_private() {
87
-    if (empty($this->Dec)) {
88
-      return false;
89
-    }
90
-    return isset($this->Dec['info']['private']) && Int64::get($this->Dec['info']['private']) == 1;
91
-  }
92
-  /**
93
-   * Add the "private" flag to the torrent
94
-   *
95
-   * @return true if a change was required
96
-   */
97
-  public function make_private() {
98
-    if (empty($this->Dec)) {
99
-      return false;
85
+    /**
86
+     * Checks if the "private" flag is present in the torrent
87
+     *
88
+     * @return true if the "private" flag is set
89
+     */
90
+    public function is_private()
91
+    {
92
+        if (empty($this->Dec)) {
93
+            return false;
94
+        }
95
+        return isset($this->Dec['info']['private']) && Int64::get($this->Dec['info']['private']) == 1;
100 96
     }
101
-    if ($this->is_private()) {
102
-      return false;
97
+    /**
98
+     * Add the "private" flag to the torrent
99
+     *
100
+     * @return true if a change was required
101
+     */
102
+    public function make_private()
103
+    {
104
+        if (empty($this->Dec)) {
105
+            return false;
106
+        }
107
+        if ($this->is_private()) {
108
+            return false;
109
+        }
110
+        $this->Dec['info']['private'] = Int64::make(1);
111
+        ksort($this->Dec['info']);
112
+        return true;
103 113
     }
104
-    $this->Dec['info']['private'] = Int64::make(1);
105
-    ksort($this->Dec['info']);
106
-    return true;
107
-  }
108 114
 
109
-  /**
110
-   * Add the "source" field to the torrent
111
-   *
112
-   * @return true if a change was required
113
-   */
114
-  public function make_sourced() {
115
-    $Sources = Users::get_upload_sources();
116
-    if (empty($this->Dec)) { return false; }
117
-    if (isset($this->Dec['info']['source']) && ($this->Dec['info']['source'] == $Sources[0] || $this->Dec['info']['source'] == $Sources[1])) {
118
-      return false;
115
+    /**
116
+     * Add the "source" field to the torrent
117
+     *
118
+     * @return true if a change was required
119
+     */
120
+    public function make_sourced()
121
+    {
122
+        $Sources = Users::get_upload_sources();
123
+        if (empty($this->Dec)) {
124
+            return false;
125
+        }
126
+        if (isset($this->Dec['info']['source']) && ($this->Dec['info']['source'] == $Sources[0] || $this->Dec['info']['source'] == $Sources[1])) {
127
+            return false;
128
+        }
129
+        $this->Dec['info']['source'] = $Sources[0];
130
+        ksort($this->Dec['info']);
131
+        return true;
119 132
     }
120
-    $this->Dec['info']['source'] = $Sources[0];
121
-    ksort($this->Dec['info']);
122
-    return true;
123
-  }
124 133
 
125
-  /**
126
-   * Calculate the torrent's info hash
127
-   *
128
-   * @return info hash in hexadecimal form
129
-   */
130
-  public function info_hash() {
131
-    if (empty($this->Dec) || !isset($this->Dec['info'])) {
132
-      return false;
134
+    /**
135
+     * Calculate the torrent's info hash
136
+     *
137
+     * @return info hash in hexadecimal form
138
+     */
139
+    public function info_hash()
140
+    {
141
+        if (empty($this->Dec) || !isset($this->Dec['info'])) {
142
+            return false;
143
+        }
144
+        return sha1($this->encode(false, 'info'));
133 145
     }
134
-    return sha1($this->encode(false, 'info'));
135
-  }
136 146
 
137
-  /**
138
-   * Add the announce URL to a torrent
139
-   */
140
-  public static function add_announce_url($Data, $Url) {
141
-    return 'd8:announce'.strlen($Url).':'.$Url.substr($Data, 1);
142
-  }
147
+    /**
148
+     * Add the announce URL to a torrent
149
+     */
150
+    public static function add_announce_url($Data, $Url)
151
+    {
152
+        return 'd8:announce'.strlen($Url).':'.$Url.substr($Data, 1);
153
+    }
143 154
 
144
-  /**
145
-   * Add list of announce URLs to a torrent
146
-   */
147
-  public static function add_announce_list($Data, $Urls) {
148
-    $r = 'd13:announce-listl';
149
-    for ($i = 0; $i < count($Urls); $i++) {
150
-      $r .= 'l';
151
-      for ($j = 0; $j < count($Urls[$i]); $j++) {
152
-        $r .= strlen($Urls[$i][$j]).':'.$Urls[$i][$j];
153
-      }
154
-      $r .= 'e';
155
+    /**
156
+     * Add list of announce URLs to a torrent
157
+     */
158
+    public static function add_announce_list($Data, $Urls)
159
+    {
160
+        $r = 'd13:announce-listl';
161
+        for ($i = 0; $i < count($Urls); $i++) {
162
+            $r .= 'l';
163
+            for ($j = 0; $j < count($Urls[$i]); $j++) {
164
+                $r .= strlen($Urls[$i][$j]).':'.$Urls[$i][$j];
165
+            }
166
+            $r .= 'e';
167
+        }
168
+        return $r.'e'.substr($Data, 1);
155 169
     }
156
-    return $r.'e'.substr($Data, 1);
157
-  }
158 170
 }

+ 23
- 23
classes/bitcoinrpc.class.php View File

@@ -1,32 +1,32 @@
1 1
 <?php
2
-class BitcoinRpc {
2
+class BitcoinRpc
3
+{
4
+    public static function __callStatic($Method, $Args)
5
+    {
6
+        if (!defined('BITCOIN_RPC_URL')) {
7
+            return false;
8
+        }
9
+        $MessageID = mt_rand();
10
+        $Params = json_encode(array(
11
+        'method' => $Method,
12
+        'params' => $Args,
13
+        'id' => $MessageID));
3 14
 
4
-  public static function __callStatic($Method, $Args) {
5
-    if (!defined('BITCOIN_RPC_URL')) {
6
-      return false;
7
-    }
8
-    $MessageID = mt_rand();
9
-    $Params = json_encode(array(
10
-      'method' => $Method,
11
-      'params' => $Args,
12
-      'id' => $MessageID)
13
-    );
14
-
15
-    $Request = array(
16
-      'http' => array(
15
+        $Request = array(
16
+        'http' => array(
17 17
         'method' => 'POST',
18 18
         'header' => 'Content-type: application/json',
19 19
         'content' => $Params
20 20
         )
21
-      );
21
+        );
22 22
 
23
-    if (!$Response = file_get_contents(BITCOIN_RPC_URL, false, stream_context_create($Request))) {
24
-      return false;
25
-    }
26
-    $Response = json_decode($Response);
27
-    if ($Response->id != $MessageID || !empty($Response->error) || empty($Response->result)) {
28
-      return false;
23
+        if (!$Response = file_get_contents(BITCOIN_RPC_URL, false, stream_context_create($Request))) {
24
+            return false;
25
+        }
26
+        $Response = json_decode($Response);
27
+        if ($Response->id != $MessageID || !empty($Response->error) || empty($Response->result)) {
28
+            return false;
29
+        }
30
+        return $Response->result;
29 31
     }
30
-    return $Response->result;
31
-  }
32 32
 }

+ 75
- 71
classes/bookmarks.class.php View File

@@ -1,5 +1,6 @@
1
-<?
2
-class Bookmarks {
1
+<?php
2
+class Bookmarks
3
+{
3 4
 
4 5
   /**
5 6
    * Check if can bookmark
@@ -7,93 +8,96 @@ class Bookmarks {
7 8
    * @param string $Type
8 9
    * @return boolean
9 10
    */
10
-  public static function can_bookmark($Type) {
11
-    return in_array($Type, array(
11
+    public static function can_bookmark($Type)
12
+    {
13
+        return in_array($Type, array(
12 14
         'torrent',
13 15
         'artist',
14 16
         'collage',
15 17
         'request'
16
-    ));
17
-  }
18
+        ));
19
+    }
18 20
 
19
-  /**
20
-   * Get the bookmark schema.
21
-   * Recommended usage:
22
-   * list($Table, $Col) = bookmark_schema('torrent');
23
-   *
24
-   * @param string $Type the type to get the schema for
25
-   */
26
-  public static function bookmark_schema($Type) {
27
-    switch ($Type) {
28
-      case 'torrent':
29
-        return array(
21
+    /**
22
+     * Get the bookmark schema.
23
+     * Recommended usage:
24
+     * list($Table, $Col) = bookmark_schema('torrent');
25
+     *
26
+     * @param string $Type the type to get the schema for
27
+     */
28
+    public static function bookmark_schema($Type)
29
+    {
30
+        switch ($Type) {
31
+            case 'torrent':
32
+                return array(
30 33
             'bookmarks_torrents',
31 34
             'GroupID'
32
-        );
33
-        break;
34
-      case 'artist':
35
-        return array(
35
+                );
36
+            break;
37
+            case 'artist':
38
+                return array(
36 39
             'bookmarks_artists',
37 40
             'ArtistID'
38
-        );
39
-        break;
40
-      case 'collage':
41
-        return array(
41
+                );
42
+            break;
43
+            case 'collage':
44
+                return array(
42 45
             'bookmarks_collages',
43 46
             'CollageID'
44
-        );
45
-        break;
46
-      case 'request':
47
-        return array(
47
+                );
48
+            break;
49
+            case 'request':
50
+                return array(
48 51
             'bookmarks_requests',
49 52
             'RequestID'
50
-        );
51
-        break;
52
-      default:
53
-        die('HAX');
53
+                );
54
+            break;
55
+            default:
56
+                die('HAX');
57
+        }
54 58
     }
55
-  }
56 59
 
57
-  /**
58
-   * Check if something is bookmarked
59
-   *
60
-   * @param string $Type
61
-   *          type of bookmarks to check
62
-   * @param int $ID
63
-   *          bookmark's id
64
-   * @return boolean
65
-   */
66
-  public static function has_bookmarked($Type, $ID) {
67
-    return in_array($ID, self::all_bookmarks($Type));
68
-  }
69
-
70
-  /**
71
-   * Fetch all bookmarks of a certain type for a user.
72
-   * If UserID is false than defaults to G::$LoggedUser['ID']
73
-   *
74
-   * @param string $Type
75
-   *          type of bookmarks to fetch
76
-   * @param int $UserID
77
-   *          userid whose bookmarks to get
78
-   * @return array the bookmarks
79
-   */
80
-  public static function all_bookmarks($Type, $UserID = false) {
81
-    if ($UserID === false) {
82
-      $UserID = G::$LoggedUser['ID'];
60
+    /**
61
+     * Check if something is bookmarked
62
+     *
63
+     * @param string $Type
64
+     *          type of bookmarks to check
65
+     * @param int $ID
66
+     *          bookmark's id
67
+     * @return boolean
68
+     */
69
+    public static function has_bookmarked($Type, $ID)
70
+    {
71
+        return in_array($ID, self::all_bookmarks($Type));
83 72
     }
84
-    $CacheKey = 'bookmarks_' . $Type . '_' . $UserID;
85
-    if (($Bookmarks = G::$Cache->get_value($CacheKey)) === false) {
86
-      list ($Table, $Col) = self::bookmark_schema($Type);
87
-      $QueryID = G::$DB->get_query_id();
88
-      G::$DB->query("
73
+
74
+    /**
75
+     * Fetch all bookmarks of a certain type for a user.
76
+     * If UserID is false than defaults to G::$LoggedUser['ID']
77
+     *
78
+     * @param string $Type
79
+     *          type of bookmarks to fetch
80
+     * @param int $UserID
81
+     *          userid whose bookmarks to get
82
+     * @return array the bookmarks
83
+     */
84
+    public static function all_bookmarks($Type, $UserID = false)
85
+    {
86
+        if ($UserID === false) {
87
+            $UserID = G::$LoggedUser['ID'];
88
+        }
89
+        $CacheKey = 'bookmarks_' . $Type . '_' . $UserID;
90
+        if (($Bookmarks = G::$Cache->get_value($CacheKey)) === false) {
91
+            list($Table, $Col) = self::bookmark_schema($Type);
92
+            $QueryID = G::$DB->get_query_id();
93
+            G::$DB->query("
89 94
         SELECT $Col
90 95
         FROM $Table
91 96
         WHERE UserID = '$UserID'");
92
-      $Bookmarks = G::$DB->collect($Col);
93
-      G::$DB->set_query_id($QueryID);
94
-      G::$Cache->cache_value($CacheKey, $Bookmarks, 0);
97
+            $Bookmarks = G::$DB->collect($Col);
98
+            G::$DB->set_query_id($QueryID);
99
+            G::$Cache->cache_value($CacheKey, $Bookmarks, 0);
100
+        }
101
+        return $Bookmarks;
95 102
     }
96
-    return $Bookmarks;
97
-  }
98 103
 }
99
-?>

+ 375
- 340
classes/cache.class.php View File

@@ -1,4 +1,4 @@
1
-<?
1
+<?php
2 2
 /*************************************************************************|
3 3
 |--------------- Caching class -------------------------------------------|
4 4
 |*************************************************************************|
@@ -25,26 +25,31 @@ memcached -d -m 8192 -l 10.10.0.1 -t8 -C
25 25
 |*************************************************************************/
26 26
 
27 27
 if (!extension_loaded('memcache') && !extension_loaded('memcached')) {
28
-  die('Memcache Extension not loaded.');
28
+    die('Memcache Extension not loaded.');
29 29
 }
30 30
 
31 31
 if (class_exists('Memcached')) {
32
-  class MemcacheCompat extends Memcached {}
32
+    class MemcacheCompat extends Memcached
33
+    {
34
+    }
33 35
 } else {
34
-  class MemcacheCompat extends Memcache {}
36
+    class MemcacheCompat extends Memcache
37
+    {
38
+    }
35 39
 }
36 40
 
37
-class Cache extends MemcacheCompat {
38
-  // Torrent Group cache version
39
-  const GROUP_VERSION = 5;
40
-
41
-  public $CacheHits = [];
42
-  public $MemcacheDBArray = [];
43
-  public $MemcacheDBKey = '';
44
-  protected $InTransaction = false;
45
-  public $Time = 0;
46
-  private $Servers = [];
47
-  private $PersistentKeys = [
41
+class Cache extends MemcacheCompat
42
+{
43
+    // Torrent Group cache version
44
+    const GROUP_VERSION = 5;
45
+
46
+    public $CacheHits = [];
47
+    public $MemcacheDBArray = [];
48
+    public $MemcacheDBKey = '';
49
+    protected $InTransaction = false;
50
+    public $Time = 0;
51
+    private $Servers = [];
52
+    private $PersistentKeys = [
48 53
     'ajax_requests_*',
49 54
     'query_lock_*',
50 55
     'stats_*',
@@ -54,362 +59,392 @@ class Cache extends MemcacheCompat {
54 59
     // Cache-based features
55 60
     'global_notification',
56 61
     'notifications_one_reads_*',
57
-  ];
58
-  private $ClearedKeys = [];
59
-
60
-  public $CanClear = false;
61
-  public $InternalCache = true;
62
-
63
-  function __construct($Servers) {
64
-    if (is_subclass_of($this, 'Memcached')) parent::__construct();
65
-    $this->Servers = $Servers;
66
-    foreach ($Servers as $Server) {
67
-      if (is_subclass_of($this, 'Memcache')) {
68
-        $this->addServer($Server['host'], $Server['port'], true, $Server['buckets']);
69
-      } else {
70
-        $this->addServer(str_replace('unix://', '', $Server['host']), $Server['port'], $Server['buckets']);
71
-      }
72
-    }
73
-  }
74
-
75
-  //---------- Caching functions ----------//
76
-
77
-  // Allows us to set an expiration on otherwise perminantly cache'd values
78
-  // Useful for disabled users, locked threads, basically reducing ram usage
79
-  public function expire_value($Key, $Duration = 2592000) {
80
-    $StartTime = microtime(true);
81
-    $this->set($Key, $this->get($Key), $Duration);
82
-    $this->Time += (microtime(true) - $StartTime) * 1000;
83
-  }
84
-
85
-  // Wrapper for Memcache::set, with the zlib option removed and default duration of 30 days
86
-  public function cache_value($Key, $Value, $Duration = 2592000) {
87
-    $StartTime = microtime(true);
88
-    if (empty($Key)) {
89
-      trigger_error("Cache insert failed for empty key");
90
-    }
91
-    $SetParams = [$Key, $Value, 0, $Duration];
92
-    if (is_subclass_of($this, 'Memcached')) unset($SetParams[2]);
93
-    if (!$this->set(...$SetParams)) {
94
-      trigger_error("Cache insert failed for key $Key");
62
+    ];
63
+    private $ClearedKeys = [];
64
+
65
+    public $CanClear = false;
66
+    public $InternalCache = true;
67
+
68
+    public function __construct($Servers)
69
+    {
70
+        if (is_subclass_of($this, 'Memcached')) {
71
+            parent::__construct();
72
+        }
73
+        $this->Servers = $Servers;
74
+        foreach ($Servers as $Server) {
75
+            if (is_subclass_of($this, 'Memcache')) {
76
+                $this->addServer($Server['host'], $Server['port'], true, $Server['buckets']);
77
+            } else {
78
+                $this->addServer(str_replace('unix://', '', $Server['host']), $Server['port'], $Server['buckets']);
79
+            }
80
+        }
95 81
     }
96
-    if ($this->InternalCache && array_key_exists($Key, $this->CacheHits)) {
97
-      $this->CacheHits[$Key] = $Value;
82
+
83
+    //---------- Caching functions ----------//
84
+
85
+    // Allows us to set an expiration on otherwise perminantly cache'd values
86
+    // Useful for disabled users, locked threads, basically reducing ram usage
87
+    public function expire_value($Key, $Duration = 2592000)
88
+    {
89
+        $StartTime = microtime(true);
90
+        $this->set($Key, $this->get($Key), $Duration);
91
+        $this->Time += (microtime(true) - $StartTime) * 1000;
98 92
     }
99
-    $this->Time += (microtime(true) - $StartTime) * 1000;
100
-  }
101
-
102
-  // Wrapper for Memcache::add, with the zlib option removed and default duration of 30 days
103
-  public function add_value($Key, $Value, $Duration = 2592000) {
104
-    $StartTime = microtime(true);
105
-    $AddParams = [$Key, $Value, false, $Duration];
106
-    if (is_subclass_of($this, 'Memcached')) unset($AddParams[2]);
107
-    $Added = $this->add(...$AddParams);
108
-    $this->Time += (microtime(true) - $StartTime) * 1000;
109
-    return $Added;
110
-  }
111
-
112
-  public function replace_value($Key, $Value, $Duration = 2592000) {
113
-    $StartTime = microtime(true);
114
-    $ReplaceParams = [$Key, $Value, false, $Duration];
115
-    if (is_subclass_of($this, 'Memcached')) unset($ReplaceParams[2]);
116
-    $this->replace(...$ReplaceParams);
117
-    if ($this->InternalCache && array_key_exists($Key, $this->CacheHits)) {
118
-      $this->CacheHits[$Key] = $Value;
93
+
94
+    // Wrapper for Memcache::set, with the zlib option removed and default duration of 30 days
95
+    public function cache_value($Key, $Value, $Duration = 2592000)
96
+    {
97
+        $StartTime = microtime(true);
98
+        if (empty($Key)) {
99
+            trigger_error("Cache insert failed for empty key");
100
+        }
101
+        $SetParams = [$Key, $Value, 0, $Duration];
102
+        if (is_subclass_of($this, 'Memcached')) {
103
+            unset($SetParams[2]);
104
+        }
105
+        if (!$this->set(...$SetParams)) {
106
+            trigger_error("Cache insert failed for key $Key");
107
+        }
108
+        if ($this->InternalCache && array_key_exists($Key, $this->CacheHits)) {
109
+            $this->CacheHits[$Key] = $Value;
110
+        }
111
+        $this->Time += (microtime(true) - $StartTime) * 1000;
119 112
     }
120
-    $this->Time += (microtime(true) - $StartTime) * 1000;
121
-  }
122 113
 
123
-  public function get_value($Key, $NoCache = false) {
124
-    if (!$this->InternalCache) {
125
-      $NoCache = true;
114
+    // Wrapper for Memcache::add, with the zlib option removed and default duration of 30 days
115
+    public function add_value($Key, $Value, $Duration = 2592000)
116
+    {
117
+        $StartTime = microtime(true);
118
+        $AddParams = [$Key, $Value, false, $Duration];
119
+        if (is_subclass_of($this, 'Memcached')) {
120
+            unset($AddParams[2]);
121
+        }
122
+        $Added = $this->add(...$AddParams);
123
+        $this->Time += (microtime(true) - $StartTime) * 1000;
124
+        return $Added;
126 125
     }
127
-    $StartTime = microtime(true);
128
-    if (empty($Key)) {
129
-      trigger_error('Cache retrieval failed for empty key');
126
+
127
+    public function replace_value($Key, $Value, $Duration = 2592000)
128
+    {
129
+        $StartTime = microtime(true);
130
+        $ReplaceParams = [$Key, $Value, false, $Duration];
131
+        if (is_subclass_of($this, 'Memcached')) {
132
+            unset($ReplaceParams[2]);
133
+        }
134
+        $this->replace(...$ReplaceParams);
135
+        if ($this->InternalCache && array_key_exists($Key, $this->CacheHits)) {
136
+            $this->CacheHits[$Key] = $Value;
137
+        }
138
+        $this->Time += (microtime(true) - $StartTime) * 1000;
130 139
     }
131 140
 
132
-    if (!empty($_GET['clearcache']) && $this->CanClear && !isset($this->ClearedKeys[$Key]) && !Misc::in_array_partial($Key, $this->PersistentKeys)) {
133
-      if ($_GET['clearcache'] === '1') {
134
-        // Because check_perms() isn't true until LoggedUser is pulled from the cache, we have to remove the entries loaded before the LoggedUser data
135
-        // Because of this, not user cache data will require a secondary pageload following the clearcache to update
136
-        if (count($this->CacheHits) > 0) {
137
-          foreach (array_keys($this->CacheHits) as $HitKey) {
138
-            if (!isset($this->ClearedKeys[$HitKey]) && !Misc::in_array_partial($HitKey, $this->PersistentKeys)) {
139
-              $this->delete($HitKey);
140
-              unset($this->CacheHits[$HitKey]);
141
-              $this->ClearedKeys[$HitKey] = true;
141
+    public function get_value($Key, $NoCache = false)
142
+    {
143
+        if (!$this->InternalCache) {
144
+            $NoCache = true;
145
+        }
146
+        $StartTime = microtime(true);
147
+        if (empty($Key)) {
148
+            trigger_error('Cache retrieval failed for empty key');
149
+        }
150
+
151
+        if (!empty($_GET['clearcache']) && $this->CanClear && !isset($this->ClearedKeys[$Key]) && !Misc::in_array_partial($Key, $this->PersistentKeys)) {
152
+            if ($_GET['clearcache'] === '1') {
153
+                // Because check_perms() isn't true until LoggedUser is pulled from the cache, we have to remove the entries loaded before the LoggedUser data
154
+                // Because of this, not user cache data will require a secondary pageload following the clearcache to update
155
+                if (count($this->CacheHits) > 0) {
156
+                    foreach (array_keys($this->CacheHits) as $HitKey) {
157
+                        if (!isset($this->ClearedKeys[$HitKey]) && !Misc::in_array_partial($HitKey, $this->PersistentKeys)) {
158
+                            $this->delete($HitKey);
159
+                            unset($this->CacheHits[$HitKey]);
160
+                            $this->ClearedKeys[$HitKey] = true;
161
+                        }
162
+                    }
163
+                }
164
+                $this->delete($Key);
165
+                $this->Time += (microtime(true) - $StartTime) * 1000;
166
+                return false;
167
+            } elseif ($_GET['clearcache'] == $Key) {
168
+                $this->delete($Key);
169
+                $this->Time += (microtime(true) - $StartTime) * 1000;
170
+                return false;
171
+            } elseif (substr($_GET['clearcache'], -1) === '*') {
172
+                $Prefix = substr($_GET['clearcache'], 0, -1);
173
+                if ($Prefix === '' || $Prefix === substr($Key, 0, strlen($Prefix))) {
174
+                    $this->delete($Key);
175
+                    $this->Time += (microtime(true) - $StartTime) * 1000;
176
+                    return false;
177
+                }
142 178
             }
143
-          }
179
+            $this->ClearedKeys[$Key] = true;
180
+        }
181
+
182
+        // For cases like the forums, if a key is already loaded, grab the existing pointer
183
+        if (isset($this->CacheHits[$Key]) && !$NoCache) {
184
+            $this->Time += (microtime(true) - $StartTime) * 1000;
185
+            return $this->CacheHits[$Key];
186
+        }
187
+
188
+        $Return = $this->get($Key);
189
+        if ($Return !== false) {
190
+            $this->CacheHits[$Key] = $NoCache ? null : $Return;
144 191
         }
145
-        $this->delete($Key);
146
-        $this->Time += (microtime(true) - $StartTime) * 1000;
147
-        return false;
148
-      } elseif ($_GET['clearcache'] == $Key) {
149
-        $this->delete($Key);
150 192
         $this->Time += (microtime(true) - $StartTime) * 1000;
151
-        return false;
152
-      } elseif (substr($_GET['clearcache'], -1) === '*') {
153
-        $Prefix = substr($_GET['clearcache'], 0, -1);
154
-        if ($Prefix === '' || $Prefix === substr($Key, 0, strlen($Prefix))) {
155
-          $this->delete($Key);
156
-          $this->Time += (microtime(true) - $StartTime) * 1000;
157
-          return false;
158
-        }
159
-      }
160
-      $this->ClearedKeys[$Key] = true;
193
+        return $Return;
161 194
     }
162 195
 
163
-    // For cases like the forums, if a key is already loaded, grab the existing pointer
164
-    if (isset($this->CacheHits[$Key]) && !$NoCache) {
165
-      $this->Time += (microtime(true) - $StartTime) * 1000;
166
-      return $this->CacheHits[$Key];
196
+    // Wrapper for Memcache::delete. For a reason, see above.
197
+    public function delete_value($Key)
198
+    {
199
+        $StartTime = microtime(true);
200
+        if (empty($Key)) {
201
+            trigger_error('Cache deletion failed for empty key');
202
+        }
203
+        if (!$this->delete($Key)) {
204
+            //trigger_error("Cache delete failed for key $Key");
205
+        }
206
+        unset($this->CacheHits[$Key]);
207
+        $this->Time += (microtime(true) - $StartTime) * 1000;
167 208
     }
168 209
 
169
-    $Return = $this->get($Key);
170
-    if ($Return !== false) {
171
-      $this->CacheHits[$Key] = $NoCache ? null : $Return;
172
-    }
173
-    $this->Time += (microtime(true) - $StartTime) * 1000;
174
-    return $Return;
175
-  }
176
-
177
-  // Wrapper for Memcache::delete. For a reason, see above.
178
-  public function delete_value($Key) {
179
-    $StartTime = microtime(true);
180
-    if (empty($Key)) {
181
-      trigger_error('Cache deletion failed for empty key');
182
-    }
183
-    if (!$this->delete($Key)) {
184
-      //trigger_error("Cache delete failed for key $Key");
185
-    }
186
-    unset($this->CacheHits[$Key]);
187
-    $this->Time += (microtime(true) - $StartTime) * 1000;
188
-  }
189
-
190
-  public function increment_value($Key, $Value = 1) {
191
-    $StartTime = microtime(true);
192
-    $NewVal = $this->increment($Key, $Value);
193
-    if (isset($this->CacheHits[$Key])) {
194
-      $this->CacheHits[$Key] = $NewVal;
195
-    }
196
-    $this->Time += (microtime(true) - $StartTime) * 1000;
197
-  }
198
-
199
-  public function decrement_value($Key, $Value = 1) {
200
-    $StartTime = microtime(true);
201
-    $NewVal = $this->decrement($Key, $Value);
202
-    if (isset($this->CacheHits[$Key])) {
203
-      $this->CacheHits[$Key] = $NewVal;
204
-    }
205
-    $this->Time += (microtime(true) - $StartTime) * 1000;
206
-  }
207
-
208
-  //---------- memcachedb functions ----------//
209
-
210
-  public function begin_transaction($Key) {
211
-    $Value = $this->get($Key);
212
-    if (!is_array($Value)) {
213
-      $this->InTransaction = false;
214
-      $this->MemcacheDBKey = [];
215
-      $this->MemcacheDBKey = '';
216
-      return false;
217
-    }
218
-    $this->MemcacheDBArray = $Value;
219
-    $this->MemcacheDBKey = $Key;
220
-    $this->InTransaction = true;
221
-    return true;
222
-  }
223
-
224
-  public function cancel_transaction() {
225
-    $this->InTransaction = false;
226
-    $this->MemcacheDBKey = [];
227
-    $this->MemcacheDBKey = '';
228
-  }
229
-
230
-  public function commit_transaction($Time = 2592000) {
231
-    if (!$this->InTransaction) {
232
-      return false;
233
-    }
234
-    $this->cache_value($this->MemcacheDBKey, $this->MemcacheDBArray, $Time);
235
-    $this->InTransaction = false;
236
-  }
237
-
238
-  // Updates multiple rows in an array
239
-  public function update_transaction($Rows, $Values) {
240
-    if (!$this->InTransaction) {
241
-      return false;
242
-    }
243
-    $Array = $this->MemcacheDBArray;
244
-    if (is_array($Rows)) {
245
-      $i = 0;
246
-      $Keys = $Rows[0];
247
-      $Property = $Rows[1];
248
-      foreach ($Keys as $Row) {
249
-        $Array[$Row][$Property] = $Values[$i];
250
-        $i++;
251
-      }
252
-    } else {
253
-      $Array[$Rows] = $Values;
254
-    }
255
-    $this->MemcacheDBArray = $Array;
256
-  }
257
-
258
-  // Updates multiple values in a single row in an array
259
-  // $Values must be an associative array with key:value pairs like in the array we're updating
260
-  public function update_row($Row, $Values) {
261
-    if (!$this->InTransaction) {
262
-      return false;
263
-    }
264
-    if ($Row === false) {
265
-      $UpdateArray = $this->MemcacheDBArray;
266
-    } else {
267
-      $UpdateArray = $this->MemcacheDBArray[$Row];
268
-    }
269
-    foreach ($Values as $Key => $Value) {
270
-      if (!array_key_exists($Key, $UpdateArray)) {
271
-        trigger_error('Bad transaction key ('.$Key.') for cache '.$this->MemcacheDBKey);
272
-      }
273
-      if ($Value === '+1') {
274
-        if (!is_number($UpdateArray[$Key])) {
275
-          trigger_error('Tried to increment non-number ('.$Key.') for cache '.$this->MemcacheDBKey);
276
-        }
277
-        ++$UpdateArray[$Key]; // Increment value
278
-      } elseif ($Value === '-1') {
279
-        if (!is_number($UpdateArray[$Key])) {
280
-          trigger_error('Tried to decrement non-number ('.$Key.') for cache '.$this->MemcacheDBKey);
281
-        }
282
-        --$UpdateArray[$Key]; // Decrement value
283
-      } else {
284
-        $UpdateArray[$Key] = $Value; // Otherwise, just alter value
285
-      }
286
-    }
287
-    if ($Row === false) {
288
-      $this->MemcacheDBArray = $UpdateArray;
289
-    } else {
290
-      $this->MemcacheDBArray[$Row] = $UpdateArray;
210
+    public function increment_value($Key, $Value = 1)
211
+    {
212
+        $StartTime = microtime(true);
213
+        $NewVal = $this->increment($Key, $Value);
214
+        if (isset($this->CacheHits[$Key])) {
215
+            $this->CacheHits[$Key] = $NewVal;
216
+        }
217
+        $this->Time += (microtime(true) - $StartTime) * 1000;
291 218
     }
292
-  }
293 219
 
294
-  // Increments multiple values in a single row in an array
295
-  // $Values must be an associative array with key:value pairs like in the array we're updating
296
-  public function increment_row($Row, $Values) {
297
-    if (!$this->InTransaction) {
298
-      return false;
299
-    }
300
-    if ($Row === false) {
301
-      $UpdateArray = $this->MemcacheDBArray;
302
-    } else {
303
-      $UpdateArray = $this->MemcacheDBArray[$Row];
304
-    }
305
-    foreach ($Values as $Key => $Value) {
306
-      if (!array_key_exists($Key, $UpdateArray)) {
307
-        trigger_error("Bad transaction key ($Key) for cache ".$this->MemcacheDBKey);
308
-      }
309
-      if (!is_number($Value)) {
310
-        trigger_error("Tried to increment with non-number ($Key) for cache ".$this->MemcacheDBKey);
311
-      }
312
-      $UpdateArray[$Key] += $Value; // Increment value
313
-    }
314
-    if ($Row === false) {
315
-      $this->MemcacheDBArray = $UpdateArray;
316
-    } else {
317
-      $this->MemcacheDBArray[$Row] = $UpdateArray;
220
+    public function decrement_value($Key, $Value = 1)
221
+    {
222
+        $StartTime = microtime(true);
223
+        $NewVal = $this->decrement($Key, $Value);
224
+        if (isset($this->CacheHits[$Key])) {
225
+            $this->CacheHits[$Key] = $NewVal;
226
+        }
227
+        $this->Time += (microtime(true) - $StartTime) * 1000;
318 228
     }
319
-  }
320 229
 
321
-  // Insert a value at the beginning of the array
322
-  public function insert_front($Key, $Value) {
323
-    if (!$this->InTransaction) {
324
-      return false;
230
+    //---------- memcachedb functions ----------//
231
+
232
+    public function begin_transaction($Key)
233
+    {
234
+        $Value = $this->get($Key);
235
+        if (!is_array($Value)) {
236
+            $this->InTransaction = false;
237
+            $this->MemcacheDBKey = [];
238
+            $this->MemcacheDBKey = '';
239
+            return false;
240
+        }
241
+        $this->MemcacheDBArray = $Value;
242
+        $this->MemcacheDBKey = $Key;
243
+        $this->InTransaction = true;
244
+        return true;
325 245
     }
326
-    if ($Key === '') {
327
-      array_unshift($this->MemcacheDBArray, $Value);
328
-    } else {
329
-      $this->MemcacheDBArray = array($Key=>$Value) + $this->MemcacheDBArray;
246
+
247
+    public function cancel_transaction()
248
+    {
249
+        $this->InTransaction = false;
250
+        $this->MemcacheDBKey = [];
251
+        $this->MemcacheDBKey = '';
330 252
     }
331
-  }
332 253
 
333
-  // Insert a value at the end of the array
334
-  public function insert_back($Key, $Value) {
335
-    if (!$this->InTransaction) {
336
-      return false;
254
+    public function commit_transaction($Time = 2592000)
255
+    {
256
+        if (!$this->InTransaction) {
257
+            return false;
258
+        }
259
+        $this->cache_value($this->MemcacheDBKey, $this->MemcacheDBArray, $Time);
260
+        $this->InTransaction = false;
337 261
     }
338
-    if ($Key === '') {
339
-      array_push($this->MemcacheDBArray, $Value);
340
-    } else {
341
-      $this->MemcacheDBArray = $this->MemcacheDBArray + array($Key=>$Value);
262
+
263
+    // Updates multiple rows in an array
264
+    public function update_transaction($Rows, $Values)
265
+    {
266
+        if (!$this->InTransaction) {
267
+            return false;
268
+        }
269
+        $Array = $this->MemcacheDBArray;
270
+        if (is_array($Rows)) {
271
+            $i = 0;
272
+            $Keys = $Rows[0];
273
+            $Property = $Rows[1];
274
+            foreach ($Keys as $Row) {
275
+                $Array[$Row][$Property] = $Values[$i];
276
+                $i++;
277
+            }
278
+        } else {
279
+            $Array[$Rows] = $Values;
280
+        }
281
+        $this->MemcacheDBArray = $Array;
342 282
     }
343 283
 
344
-  }
284
+    // Updates multiple values in a single row in an array
285
+    // $Values must be an associative array with key:value pairs like in the array we're updating
286
+    public function update_row($Row, $Values)
287
+    {
288
+        if (!$this->InTransaction) {
289
+            return false;
290
+        }
291
+        if ($Row === false) {
292
+            $UpdateArray = $this->MemcacheDBArray;
293
+        } else {
294
+            $UpdateArray = $this->MemcacheDBArray[$Row];
295
+        }
296
+        foreach ($Values as $Key => $Value) {
297
+            if (!array_key_exists($Key, $UpdateArray)) {
298
+                trigger_error('Bad transaction key ('.$Key.') for cache '.$this->MemcacheDBKey);
299
+            }
300
+            if ($Value === '+1') {
301
+                if (!is_number($UpdateArray[$Key])) {
302
+                    trigger_error('Tried to increment non-number ('.$Key.') for cache '.$this->MemcacheDBKey);
303
+                }
304
+                ++$UpdateArray[$Key]; // Increment value
305
+            } elseif ($Value === '-1') {
306
+                if (!is_number($UpdateArray[$Key])) {
307
+                    trigger_error('Tried to decrement non-number ('.$Key.') for cache '.$this->MemcacheDBKey);
308
+                }
309
+                --$UpdateArray[$Key]; // Decrement value
310
+            } else {
311
+                $UpdateArray[$Key] = $Value; // Otherwise, just alter value
312
+            }
313
+        }
314
+        if ($Row === false) {
315
+            $this->MemcacheDBArray = $UpdateArray;
316
+        } else {
317
+            $this->MemcacheDBArray[$Row] = $UpdateArray;
318
+        }
319
+    }
345 320
 
346
-  public function insert($Key, $Value) {
347
-    if (!$this->InTransaction) {
348
-      return false;
321
+    // Increments multiple values in a single row in an array
322
+    // $Values must be an associative array with key:value pairs like in the array we're updating
323
+    public function increment_row($Row, $Values)
324
+    {
325
+        if (!$this->InTransaction) {
326
+            return false;
327
+        }
328
+        if ($Row === false) {
329
+            $UpdateArray = $this->MemcacheDBArray;
330
+        } else {
331
+            $UpdateArray = $this->MemcacheDBArray[$Row];
332
+        }
333
+        foreach ($Values as $Key => $Value) {
334
+            if (!array_key_exists($Key, $UpdateArray)) {
335
+                trigger_error("Bad transaction key ($Key) for cache ".$this->MemcacheDBKey);
336
+            }
337
+            if (!is_number($Value)) {
338
+                trigger_error("Tried to increment with non-number ($Key) for cache ".$this->MemcacheDBKey);
339
+            }
340
+            $UpdateArray[$Key] += $Value; // Increment value
341
+        }
342
+        if ($Row === false) {
343
+            $this->MemcacheDBArray = $UpdateArray;
344
+        } else {
345
+            $this->MemcacheDBArray[$Row] = $UpdateArray;
346
+        }
349 347
     }
350
-    if ($Key === '') {
351
-      $this->MemcacheDBArray[] = $Value;
352
-    } else {
353
-      $this->MemcacheDBArray[$Key] = $Value;
348
+
349
+    // Insert a value at the beginning of the array
350
+    public function insert_front($Key, $Value)
351
+    {
352
+        if (!$this->InTransaction) {
353
+            return false;
354
+        }
355
+        if ($Key === '') {
356
+            array_unshift($this->MemcacheDBArray, $Value);
357
+        } else {
358
+            $this->MemcacheDBArray = array($Key=>$Value) + $this->MemcacheDBArray;
359
+        }
354 360
     }
355
-  }
356 361
 
357
-  public function delete_row($Row) {
358
-    if (!$this->InTransaction) {
359
-      return false;
362
+    // Insert a value at the end of the array
363
+    public function insert_back($Key, $Value)
364
+    {
365
+        if (!$this->InTransaction) {
366
+            return false;
367
+        }
368
+        if ($Key === '') {
369
+            array_push($this->MemcacheDBArray, $Value);
370
+        } else {
371
+            $this->MemcacheDBArray = $this->MemcacheDBArray + array($Key=>$Value);
372
+        }
360 373
     }
361
-    if (!isset($this->MemcacheDBArray[$Row])) {
362
-      trigger_error("Tried to delete non-existent row ($Row) for cache ".$this->MemcacheDBKey);
374
+
375
+    public function insert($Key, $Value)
376
+    {
377
+        if (!$this->InTransaction) {
378
+            return false;
379
+        }
380
+        if ($Key === '') {
381
+            $this->MemcacheDBArray[] = $Value;
382
+        } else {
383
+            $this->MemcacheDBArray[$Key] = $Value;
384
+        }
363 385
     }
364
-    unset($this->MemcacheDBArray[$Row]);
365
-  }
366
-
367
-  public function update($Key, $Rows, $Values, $Time = 2592000) {
368
-    if (!$this->InTransaction) {
369
-      $this->begin_transaction($Key);
370
-      $this->update_transaction($Rows, $Values);
371
-      $this->commit_transaction($Time);
372
-    } else {
373
-      $this->update_transaction($Rows, $Values);
386
+
387
+    public function delete_row($Row)
388
+    {
389
+        if (!$this->InTransaction) {
390
+            return false;
391
+        }
392
+        if (!isset($this->MemcacheDBArray[$Row])) {
393
+            trigger_error("Tried to delete non-existent row ($Row) for cache ".$this->MemcacheDBKey);
394
+        }
395
+        unset($this->MemcacheDBArray[$Row]);
374 396
     }
375
-  }
376
-
377
-  /**
378
-   * Tries to set a lock. Expiry time is one hour to avoid indefinite locks
379
-   *
380
-   * @param string $LockName name on the lock
381
-   * @return true if lock was acquired
382
-   */
383
-  public function get_query_lock($LockName) {
384
-    return $this->add_value('query_lock_'.$LockName, 1, 3600);
385
-  }
386
-
387
-  /**
388
-   * Remove lock
389
-   *
390
-   * @param string $LockName name on the lock
391
-   */
392
-  public function clear_query_lock($LockName) {
393
-    $this->delete_value('query_lock_'.$LockName);
394
-  }
395
-
396
-  /**
397
-   * Get cache server status
398
-   *
399
-   * @return array (host => int status, ...)
400
-   */
401
-  public function server_status() {
402
-    $Status = [];
403
-    if (is_subclass_of($this, 'Memcached')) {
404
-      $MemcachedStats = $this->getStats();
397
+
398
+    public function update($Key, $Rows, $Values, $Time = 2592000)
399
+    {
400
+        if (!$this->InTransaction) {
401
+            $this->begin_transaction($Key);
402
+            $this->update_transaction($Rows, $Values);
403
+            $this->commit_transaction($Time);
404
+        } else {
405
+            $this->update_transaction($Rows, $Values);
406
+        }
405 407
     }
406
-    foreach ($this->Servers as $Server) {
407
-      if (is_subclass_of($this, 'Memcached')) {
408
-        $Status["$Server[host]:$Server[port]"] = gettype($MemcachedStats["$Server[host]:$Server[port]"]) == 'array' ? 1 : 0;
409
-      } else {
410
-        $Status["$Server[host]:$Server[port]"] = $this->getServerStatus($Server['host'], $Server['port']);
411
-      }
408
+
409
+    /**
410
+     * Tries to set a lock. Expiry time is one hour to avoid indefinite locks
411
+     *
412
+     * @param string $LockName name on the lock
413
+     * @return true if lock was acquired
414
+     */
415
+    public function get_query_lock($LockName)
416
+    {
417
+        return $this->add_value('query_lock_'.$LockName, 1, 3600);
418
+    }
419
+
420
+    /**
421
+     * Remove lock
422
+     *
423
+     * @param string $LockName name on the lock
424
+     */
425
+    public function clear_query_lock($LockName)
426
+    {
427
+        $this->delete_value('query_lock_'.$LockName);
428
+    }
429
+
430
+    /**
431
+     * Get cache server status
432
+     *
433
+     * @return array (host => int status, ...)
434
+     */
435
+    public function server_status()
436
+    {
437
+        $Status = [];
438
+        if (is_subclass_of($this, 'Memcached')) {
439
+            $MemcachedStats = $this->getStats();
440
+        }
441
+        foreach ($this->Servers as $Server) {
442
+            if (is_subclass_of($this, 'Memcached')) {
443
+                $Status["$Server[host]:$Server[port]"] = gettype($MemcachedStats["$Server[host]:$Server[port]"]) == 'array' ? 1 : 0;
444
+            } else {
445
+                $Status["$Server[host]:$Server[port]"] = $this->getServerStatus($Server['host'], $Server['port']);
446
+            }
447
+        }
448
+        return $Status;
412 449
     }
413
-    return $Status;
414
-  }
415 450
 }

Loading…
Cancel
Save