mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-21 22:03:49 -07:00
feat(cache): Checking if extensions are installed (#1759)
* feat(cache): Checking if extensions are installed * Updated * Update APCu.php * Update Sqlite.php * Update Sqlite.php * Update APCu.php * Update Sqlite.php * Update APCu.php * Updated * Update APCu.php * Update Redis.php
This commit is contained in:
parent
0aab040080
commit
7f31022cfc
8 changed files with 140 additions and 6 deletions
|
@ -13,6 +13,8 @@ use TorrentPier\Dev;
|
||||||
|
|
||||||
use MatthiasMullie\Scrapbook\Adapters\Apc;
|
use MatthiasMullie\Scrapbook\Adapters\Apc;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class APCu
|
* Class APCu
|
||||||
* @package TorrentPier\Legacy\Cache
|
* @package TorrentPier\Legacy\Cache
|
||||||
|
@ -54,6 +56,9 @@ class APCu extends Common
|
||||||
*/
|
*/
|
||||||
public function __construct(string $prefix)
|
public function __construct(string $prefix)
|
||||||
{
|
{
|
||||||
|
if (!$this->isInstalled()) {
|
||||||
|
throw new Exception('ext-apcu not installed. Check out php.ini file');
|
||||||
|
}
|
||||||
$this->apcu = new Apc();
|
$this->apcu = new Apc();
|
||||||
$this->prefix = $prefix;
|
$this->prefix = $prefix;
|
||||||
$this->dbg_enabled = Dev::sqlDebugAllowed();
|
$this->dbg_enabled = Dev::sqlDebugAllowed();
|
||||||
|
@ -127,4 +132,14 @@ class APCu extends Common
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checking if APCu is installed
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function isInstalled(): bool
|
||||||
|
{
|
||||||
|
return extension_loaded('apcu') && function_exists('apcu_fetch');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ use TorrentPier\Dev;
|
||||||
use Memcached as MemcachedClient;
|
use Memcached as MemcachedClient;
|
||||||
use MatthiasMullie\Scrapbook\Adapters\Memcached as MemcachedCache;
|
use MatthiasMullie\Scrapbook\Adapters\Memcached as MemcachedCache;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Memcached
|
* Class Memcached
|
||||||
* @package TorrentPier\Legacy\Cache
|
* @package TorrentPier\Legacy\Cache
|
||||||
|
@ -77,6 +79,9 @@ class Memcached extends Common
|
||||||
*/
|
*/
|
||||||
public function __construct(array $cfg, string $prefix)
|
public function __construct(array $cfg, string $prefix)
|
||||||
{
|
{
|
||||||
|
if (!$this->isInstalled()) {
|
||||||
|
throw new Exception('ext-memcached not installed. Check out php.ini file');
|
||||||
|
}
|
||||||
$this->client = new MemcachedClient();
|
$this->client = new MemcachedClient();
|
||||||
$this->cfg = $cfg;
|
$this->cfg = $cfg;
|
||||||
$this->prefix = $prefix;
|
$this->prefix = $prefix;
|
||||||
|
@ -98,7 +103,7 @@ class Memcached extends Common
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->connected) {
|
if (!$this->connected) {
|
||||||
die("Could not connect to $this->engine server");
|
throw new Exception("Could not connect to $this->engine server");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->memcached = new MemcachedCache($this->client);
|
$this->memcached = new MemcachedCache($this->client);
|
||||||
|
@ -187,4 +192,14 @@ class Memcached extends Common
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checking if Memcached is installed
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function isInstalled(): bool
|
||||||
|
{
|
||||||
|
return extension_loaded('memcached') && class_exists('Memcached');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ use TorrentPier\Dev;
|
||||||
use Redis as RedisClient;
|
use Redis as RedisClient;
|
||||||
use MatthiasMullie\Scrapbook\Adapters\Redis as RedisCache;
|
use MatthiasMullie\Scrapbook\Adapters\Redis as RedisCache;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Redis
|
* Class Redis
|
||||||
* @package TorrentPier\Legacy\Cache
|
* @package TorrentPier\Legacy\Cache
|
||||||
|
@ -77,6 +79,9 @@ class Redis extends Common
|
||||||
*/
|
*/
|
||||||
public function __construct(array $cfg, string $prefix)
|
public function __construct(array $cfg, string $prefix)
|
||||||
{
|
{
|
||||||
|
if (!$this->isInstalled()) {
|
||||||
|
throw new Exception('ext-redis not installed. Check out php.ini file');
|
||||||
|
}
|
||||||
$this->client = new RedisClient();
|
$this->client = new RedisClient();
|
||||||
$this->cfg = $cfg;
|
$this->cfg = $cfg;
|
||||||
$this->prefix = $prefix;
|
$this->prefix = $prefix;
|
||||||
|
@ -100,7 +105,7 @@ class Redis extends Common
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->connected) {
|
if (!$this->connected) {
|
||||||
die("Could not connect to $this->engine server");
|
throw new Exception("Could not connect to $this->engine server");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->redis = new RedisCache($this->client);
|
$this->redis = new RedisCache($this->client);
|
||||||
|
@ -189,4 +194,14 @@ class Redis extends Common
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checking if Redis is installed
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function isInstalled(): bool
|
||||||
|
{
|
||||||
|
return extension_loaded('redis') && class_exists('Redis');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ use TorrentPier\Dev;
|
||||||
use MatthiasMullie\Scrapbook\Adapters\SQLite as SQLiteCache;
|
use MatthiasMullie\Scrapbook\Adapters\SQLite as SQLiteCache;
|
||||||
use PDO;
|
use PDO;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Sqlite
|
* Class Sqlite
|
||||||
* @package TorrentPier\Legacy\Cache
|
* @package TorrentPier\Legacy\Cache
|
||||||
|
@ -34,6 +36,13 @@ class Sqlite extends Common
|
||||||
*/
|
*/
|
||||||
public string $engine = 'SQLite';
|
public string $engine = 'SQLite';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQLite DB file extension
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $dbExtension = '.db';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache prefix
|
* Cache prefix
|
||||||
*
|
*
|
||||||
|
@ -56,7 +65,10 @@ class Sqlite extends Common
|
||||||
*/
|
*/
|
||||||
public function __construct(string $dir, string $prefix)
|
public function __construct(string $dir, string $prefix)
|
||||||
{
|
{
|
||||||
$client = new PDO("sqlite:$dir.db");
|
if (!$this->isInstalled()) {
|
||||||
|
throw new Exception('ext-pdo_sqlite not installed. Check out php.ini file');
|
||||||
|
}
|
||||||
|
$client = new PDO('sqlite:' . $dir . $this->dbExtension);
|
||||||
$this->sqlite = new SQLiteCache($client);
|
$this->sqlite = new SQLiteCache($client);
|
||||||
$this->prefix = $prefix;
|
$this->prefix = $prefix;
|
||||||
$this->dbg_enabled = Dev::sqlDebugAllowed();
|
$this->dbg_enabled = Dev::sqlDebugAllowed();
|
||||||
|
@ -130,4 +142,14 @@ class Sqlite extends Common
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checking if PDO SQLite is installed
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function isInstalled(): bool
|
||||||
|
{
|
||||||
|
return extension_loaded('pdo_sqlite') && class_exists('PDO');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ use TorrentPier\Dev;
|
||||||
|
|
||||||
use MatthiasMullie\Scrapbook\Adapters\Apc;
|
use MatthiasMullie\Scrapbook\Adapters\Apc;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class APCu
|
* Class APCu
|
||||||
* @package TorrentPier\Legacy\Datastore
|
* @package TorrentPier\Legacy\Datastore
|
||||||
|
@ -47,6 +49,9 @@ class APCu extends Common
|
||||||
*/
|
*/
|
||||||
public function __construct(string $prefix)
|
public function __construct(string $prefix)
|
||||||
{
|
{
|
||||||
|
if (!$this->isInstalled()) {
|
||||||
|
throw new Exception('ext-apcu not installed. Check out php.ini file');
|
||||||
|
}
|
||||||
$this->apcu = new Apc();
|
$this->apcu = new Apc();
|
||||||
$this->prefix = $prefix;
|
$this->prefix = $prefix;
|
||||||
$this->dbg_enabled = Dev::sqlDebugAllowed();
|
$this->dbg_enabled = Dev::sqlDebugAllowed();
|
||||||
|
@ -121,4 +126,14 @@ class APCu extends Common
|
||||||
$this->num_queries++;
|
$this->num_queries++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checking if APCu is installed
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function isInstalled(): bool
|
||||||
|
{
|
||||||
|
return extension_loaded('apcu') && function_exists('apcu_fetch');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ use TorrentPier\Dev;
|
||||||
use Memcached as MemcachedClient;
|
use Memcached as MemcachedClient;
|
||||||
use MatthiasMullie\Scrapbook\Adapters\Memcached as MemcachedCache;
|
use MatthiasMullie\Scrapbook\Adapters\Memcached as MemcachedCache;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Memcached
|
* Class Memcached
|
||||||
* @package TorrentPier\Legacy\Datastore
|
* @package TorrentPier\Legacy\Datastore
|
||||||
|
@ -70,6 +72,9 @@ class Memcached extends Common
|
||||||
*/
|
*/
|
||||||
public function __construct(array $cfg, string $prefix)
|
public function __construct(array $cfg, string $prefix)
|
||||||
{
|
{
|
||||||
|
if (!$this->isInstalled()) {
|
||||||
|
throw new Exception('ext-memcached not installed. Check out php.ini file');
|
||||||
|
}
|
||||||
$this->client = new MemcachedClient();
|
$this->client = new MemcachedClient();
|
||||||
$this->cfg = $cfg;
|
$this->cfg = $cfg;
|
||||||
$this->prefix = $prefix;
|
$this->prefix = $prefix;
|
||||||
|
@ -91,7 +96,7 @@ class Memcached extends Common
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->connected) {
|
if (!$this->connected) {
|
||||||
die("Could not connect to $this->engine server");
|
throw new Exception("Could not connect to $this->engine server");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->memcached = new MemcachedCache($this->client);
|
$this->memcached = new MemcachedCache($this->client);
|
||||||
|
@ -181,4 +186,14 @@ class Memcached extends Common
|
||||||
$this->num_queries++;
|
$this->num_queries++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checking if Memcached is installed
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function isInstalled(): bool
|
||||||
|
{
|
||||||
|
return extension_loaded('memcached') && class_exists('Memcached');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ use TorrentPier\Dev;
|
||||||
use Redis as RedisClient;
|
use Redis as RedisClient;
|
||||||
use MatthiasMullie\Scrapbook\Adapters\Redis as RedisCache;
|
use MatthiasMullie\Scrapbook\Adapters\Redis as RedisCache;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Redis
|
* Class Redis
|
||||||
* @package TorrentPier\Legacy\Datastore
|
* @package TorrentPier\Legacy\Datastore
|
||||||
|
@ -70,6 +72,9 @@ class Redis extends Common
|
||||||
*/
|
*/
|
||||||
public function __construct(array $cfg, string $prefix)
|
public function __construct(array $cfg, string $prefix)
|
||||||
{
|
{
|
||||||
|
if (!$this->isInstalled()) {
|
||||||
|
throw new Exception('ext-redis not installed. Check out php.ini file');
|
||||||
|
}
|
||||||
$this->client = new RedisClient();
|
$this->client = new RedisClient();
|
||||||
$this->cfg = $cfg;
|
$this->cfg = $cfg;
|
||||||
$this->prefix = $prefix;
|
$this->prefix = $prefix;
|
||||||
|
@ -93,7 +98,7 @@ class Redis extends Common
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->connected) {
|
if (!$this->connected) {
|
||||||
die("Could not connect to $this->engine server");
|
throw new Exception("Could not connect to $this->engine server");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->redis = new RedisCache($this->client);
|
$this->redis = new RedisCache($this->client);
|
||||||
|
@ -183,4 +188,14 @@ class Redis extends Common
|
||||||
$this->num_queries++;
|
$this->num_queries++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checking if Redis is installed
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function isInstalled(): bool
|
||||||
|
{
|
||||||
|
return extension_loaded('redis') && class_exists('Redis');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ use TorrentPier\Dev;
|
||||||
use MatthiasMullie\Scrapbook\Adapters\SQLite as SQLiteCache;
|
use MatthiasMullie\Scrapbook\Adapters\SQLite as SQLiteCache;
|
||||||
use PDO;
|
use PDO;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Sqlite
|
* Class Sqlite
|
||||||
* @package TorrentPier\Legacy\Datastore
|
* @package TorrentPier\Legacy\Datastore
|
||||||
|
@ -27,6 +29,13 @@ class Sqlite extends Common
|
||||||
*/
|
*/
|
||||||
public string $engine = 'SQLite';
|
public string $engine = 'SQLite';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQLite DB file extension
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $dbExtension = '.db';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache prefix
|
* Cache prefix
|
||||||
*
|
*
|
||||||
|
@ -49,7 +58,10 @@ class Sqlite extends Common
|
||||||
*/
|
*/
|
||||||
public function __construct(string $dir, string $prefix)
|
public function __construct(string $dir, string $prefix)
|
||||||
{
|
{
|
||||||
$client = new PDO("sqlite:$dir.db");
|
if (!$this->isInstalled()) {
|
||||||
|
throw new Exception('ext-pdo_sqlite not installed. Check out php.ini file');
|
||||||
|
}
|
||||||
|
$client = new PDO('sqlite:' . $dir . $this->dbExtension);
|
||||||
$this->sqlite = new SQLiteCache($client);
|
$this->sqlite = new SQLiteCache($client);
|
||||||
$this->prefix = $prefix;
|
$this->prefix = $prefix;
|
||||||
$this->dbg_enabled = Dev::sqlDebugAllowed();
|
$this->dbg_enabled = Dev::sqlDebugAllowed();
|
||||||
|
@ -124,4 +136,14 @@ class Sqlite extends Common
|
||||||
$this->num_queries++;
|
$this->num_queries++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checking if PDO SQLite is installed
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function isInstalled(): bool
|
||||||
|
{
|
||||||
|
return extension_loaded('pdo_sqlite') && class_exists('PDO');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue