From 9859bab9c35bdc721bff3237b08d8bfac1c9b727 Mon Sep 17 00:00:00 2001 From: djmaze Date: Tue, 13 Jul 2021 20:38:13 +0200 Subject: [PATCH] Rename APC to APCU Drop unused APP_REQUEST_RND --- _include.php | 3 +++ .../MailSo/Cache/Drivers/{APC.php => APCU.php} | 10 +++++----- .../v/0.0.0/app/libraries/RainLoop/Actions.php | 6 +++--- .../libraries/RainLoop/Config/AbstractConfig.php | 14 +++++++------- .../Providers/Storage/TemproryApcStorage.php | 6 +++--- snappymail/v/0.0.0/include.php | 7 +++---- 6 files changed, 24 insertions(+), 22 deletions(-) rename snappymail/v/0.0.0/app/libraries/MailSo/Cache/Drivers/{APC.php => APCU.php} (79%) diff --git a/_include.php b/_include.php index e89506d55..869d1c166 100644 --- a/_include.php +++ b/_include.php @@ -10,6 +10,9 @@ // Uncomment to enable multiple domain installation. //define('MULTIDOMAIN', 1); +// Uncomment to disable APCU. +//define('APP_USE_APCU_CACHE', false); + /** * Custom 'data' folder path * @return string diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Cache/Drivers/APC.php b/snappymail/v/0.0.0/app/libraries/MailSo/Cache/Drivers/APCU.php similarity index 79% rename from snappymail/v/0.0.0/app/libraries/MailSo/Cache/Drivers/APC.php rename to snappymail/v/0.0.0/app/libraries/MailSo/Cache/Drivers/APCU.php index c5b5ab085..8f1730edb 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Cache/Drivers/APC.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Cache/Drivers/APCU.php @@ -16,7 +16,7 @@ namespace MailSo\Cache\Drivers; * @package Cache * @subpackage Drivers */ -class APC implements \MailSo\Cache\DriverInterface +class APCU implements \MailSo\Cache\DriverInterface { /** * @var string @@ -35,25 +35,25 @@ class APC implements \MailSo\Cache\DriverInterface public function Set(string $sKey, string $sValue) : bool { - return \apc_store($this->generateCachedKey($sKey), (string) $sValue); + return \apcu_store($this->generateCachedKey($sKey), (string) $sValue); } public function Get(string $sKey) : string { - $sValue = \apc_fetch($this->generateCachedKey($sKey)); + $sValue = \apcu_fetch($this->generateCachedKey($sKey)); return \is_string($sValue) ? $sValue : ''; } public function Delete(string $sKey) : void { - \apc_delete($this->generateCachedKey($sKey)); + \apcu_delete($this->generateCachedKey($sKey)); } public function GC(int $iTimeToClearInHours = 24) : bool { if (0 === $iTimeToClearInHours) { - return \apc_clear_cache('user'); + return \apcu_clear_cache('user'); } return false; diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php index 40cdc3487..6935da9b4 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -686,9 +686,9 @@ class Actions $oDriver = new \MailSo\Cache\Drivers\File(APP_PRIVATE_DATA . 'cache', $sKey); break; - case ('APC' === $sDriver || 'APCU' === $sDriver) && + case ('APCU' === $sDriver) && \MailSo\Base\Utils::FunctionExistsAndEnabled(array( - 'apc_store', 'apc_fetch', 'apc_delete', 'apc_clear_cache')): + 'apcu_store', 'apcu_fetch', 'apcu_delete', 'apcu_clear_cache')): $oDriver = new \MailSo\Cache\Drivers\APC($sKey); break; @@ -795,7 +795,7 @@ class Actions ); $this->oLogger->Write( - '[APC:' . (\MailSo\Base\Utils::FunctionExistsAndEnabled('apc_fetch') ? 'on' : 'off') . + '[APCU:' . (\MailSo\Base\Utils::FunctionExistsAndEnabled('apcu_fetch') ? 'on' : 'off') . '][MB:' . (\MailSo\Base\Utils::FunctionExistsAndEnabled('mb_convert_encoding') ? 'on' : 'off') . '][PDO:' . (\class_exists('PDO') ? (\implode(',', \Pdo::getAvailableDrivers()) ?: '~') : 'off') . '][Streams:' . \implode(',', \stream_get_transports()) . diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Config/AbstractConfig.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Config/AbstractConfig.php index 4c0627d0b..8333befa7 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Config/AbstractConfig.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Config/AbstractConfig.php @@ -42,7 +42,7 @@ abstract class AbstractConfig $this->aData = $this->defaultValues(); $this->bUseApcCache = APP_USE_APC_CACHE && - \MailSo\Base\Utils::FunctionExistsAndEnabled(array('apc_fetch', 'apc_store')); + \MailSo\Base\Utils::FunctionExistsAndEnabled(array('apcu_fetch', 'apcu_store')); } protected abstract function defaultValues() : array; @@ -116,10 +116,10 @@ abstract class AbstractConfig { $sKey = $this->cacheKey(); - $sTimeHash = \apc_fetch($sKey.'time'); + $sTimeHash = \apcu_fetch($sKey.'time'); if ($sTimeHash && $sTimeHash === \md5($iMTime.'/'.$iATime)) { - $aFetchData = \apc_fetch($sKey.'data'); + $aFetchData = \apcu_fetch($sKey.'data'); if (\is_array($aFetchData)) { $this->aData = $aFetchData; @@ -146,8 +146,8 @@ abstract class AbstractConfig { $sKey = $this->cacheKey(); - \apc_store($sKey.'time', \md5($iMTime.'/'.$iATime)); - \apc_store($sKey.'data', $this->aData); + \apcu_store($sKey.'time', \md5($iMTime.'/'.$iATime)); + \apcu_store($sKey.'data', $this->aData); return true; } @@ -162,8 +162,8 @@ abstract class AbstractConfig { $sKey = $this->cacheKey(); - \apc_delete($sKey.'time'); - \apc_delete($sKey.'data'); + \apcu_delete($sKey.'time'); + \apcu_delete($sKey.'data'); return true; } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Storage/TemproryApcStorage.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Storage/TemproryApcStorage.php index d0fa13aec..aab6cac5f 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Storage/TemproryApcStorage.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Storage/TemproryApcStorage.php @@ -9,7 +9,7 @@ class TemproryApcStorage extends \RainLoop\Providers\Storage\FileStorage */ public function Put($oAccount, int $iStorageType, string $sKey, string $sValue) : bool { - return !!\apc_store($this->generateFileName($oAccount, $iStorageType, $sKey, true), $sValue); + return !!\apcu_store($this->generateFileName($oAccount, $iStorageType, $sKey, true), $sValue); } /** @@ -21,7 +21,7 @@ class TemproryApcStorage extends \RainLoop\Providers\Storage\FileStorage public function Get($oAccount, int $iStorageType, string $sKey, $mDefault = false) { $bValue = false; - $mValue = \apc_fetch($this->generateFileName($oAccount, $iStorageType, $sKey), $bValue); + $mValue = \apcu_fetch($this->generateFileName($oAccount, $iStorageType, $sKey), $bValue); if (!$bValue) { $mValue = $mDefault; @@ -35,7 +35,7 @@ class TemproryApcStorage extends \RainLoop\Providers\Storage\FileStorage */ public function Clear($oAccount, int $iStorageType, string $sKey) : bool { - \apc_delete($this->generateFileName($oAccount, $iStorageType, $sKey)); + \apcu_delete($this->generateFileName($oAccount, $iStorageType, $sKey)); return true; } diff --git a/snappymail/v/0.0.0/include.php b/snappymail/v/0.0.0/include.php index 6fd780e89..1a24c36ca 100644 --- a/snappymail/v/0.0.0/include.php +++ b/snappymail/v/0.0.0/include.php @@ -2,7 +2,7 @@ if (defined('APP_VERSION')) { - if (!defined('APP_REQUEST_RND')) + if (!defined('APP_VERSION_ROOT_PATH')) { if (function_exists('sys_getloadavg')) { $load = sys_getloadavg(); @@ -25,11 +25,8 @@ ini_set('register_globals', 0); ini_set('zend.ze1_compatibility_mode', 0); - define('APP_REQUEST_RND', function_exists('uuid_create') ? md5(uuid_create(UUID_TYPE_DEFAULT)) : bin2hex(random_bytes(16))); define('APP_VERSION_ROOT_PATH', APP_INDEX_ROOT_PATH.'snappymail/v/'.APP_VERSION.'/'); - define('APP_USE_APC_CACHE', true); - // "img-src https:" is allowed due to remote images in e-mails define('APP_DEFAULT_CSP', "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data: https: http:; style-src 'self' 'unsafe-inline'"); @@ -57,6 +54,8 @@ include_once APP_INDEX_ROOT_PATH.'include.php'; } + defined('APP_USE_APCU_CACHE') || define('APP_USE_APCU_CACHE', true); + $sCustomDataPath = function_exists('__get_custom_data_full_path') ? rtrim(trim(__get_custom_data_full_path()), '\\/') : $sCustomDataPath; define('APP_DATA_FOLDER_PATH', 0 === strlen($sCustomDataPath) ? APP_INDEX_ROOT_PATH.'data/' : $sCustomDataPath.'/'); unset($sCustomDataPath);