Added apc cache for config files

Loggin improvements
This commit is contained in:
RainLoop Team 2014-10-14 15:04:11 +04:00
parent ef7f8bddb3
commit 0af6fbadaa
5 changed files with 149 additions and 18 deletions

View file

@ -1999,14 +1999,28 @@ class Utils
} }
/** /**
* @param string $sFunctionName * @param string|array $mFunctionNameOrNames
* *
* @return bool * @return bool
*/ */
public static function FunctionExistsAndEnabled($sFunctionName) public static function FunctionExistsAndEnabled($mFunctionNameOrNames)
{ {
static $aCache = null; static $aCache = null;
if (empty($sFunctionName) || !\function_exists($sFunctionName) || !\is_callable($sFunctionName))
if (\is_array($mFunctionNameOrNames))
{
foreach ($mFunctionNameOrNames as $sFunctionName)
{
if (!\MailSo\Base\Utils::FunctionExistsAndEnabled($sFunctionName))
{
return false;
}
}
return true;
}
if (empty($mFunctionNameOrNames) || !\function_exists($mFunctionNameOrNames) || !\is_callable($mFunctionNameOrNames))
{ {
return false; return false;
} }
@ -2017,7 +2031,7 @@ class Utils
$sDisableFunctions = \is_string($sDisableFunctions) && 0 < \strlen($sDisableFunctions) ? $sDisableFunctions : ''; $sDisableFunctions = \is_string($sDisableFunctions) && 0 < \strlen($sDisableFunctions) ? $sDisableFunctions : '';
$aCache = \explode(',', $sDisableFunctions); $aCache = \explode(',', $sDisableFunctions);
$aCache = is_array($aCache) && 0 < count($aCache) ? $aCache : array(); $aCache = \is_array($aCache) && 0 < \count($aCache) ? $aCache : array();
if (\extension_loaded('suhosin')) if (\extension_loaded('suhosin'))
{ {
@ -2025,17 +2039,17 @@ class Utils
$sSuhosin = \is_string($sSuhosin) && 0 < \strlen($sSuhosin) ? $sSuhosin : ''; $sSuhosin = \is_string($sSuhosin) && 0 < \strlen($sSuhosin) ? $sSuhosin : '';
$aSuhosinCache = \explode(',', $sSuhosin); $aSuhosinCache = \explode(',', $sSuhosin);
$aSuhosinCache = is_array($aSuhosinCache) && 0 < count($aSuhosinCache) ? $aSuhosinCache : array(); $aSuhosinCache = \is_array($aSuhosinCache) && 0 < \count($aSuhosinCache) ? $aSuhosinCache : array();
if (0 < \count($aSuhosinCache)) if (0 < \count($aSuhosinCache))
{ {
$aCache = array_merge($aCache, $aSuhosinCache); $aCache = \array_merge($aCache, $aSuhosinCache);
$aCache = array_unique($aCache); $aCache = \array_unique($aCache);
} }
} }
} }
return !\in_array($sFunctionName, $aCache); return !\in_array($mFunctionNameOrNames, $aCache);
} }
/** /**

View file

@ -673,16 +673,22 @@ class Actions
switch (true) switch (true)
{ {
case 'APC' === $sDriver && \MailSo\Base\Utils::FunctionExistsAndEnabled('apc_store'): case ('APC' === $sDriver || 'APCU' === $sDriver) &&
\MailSo\Base\Utils::FunctionExistsAndEnabled(array(
'apc_store', 'apc_fetch', 'apc_delete', 'apc_clear_cache')):
$oDriver = \MailSo\Cache\Drivers\APC::NewInstance(); $oDriver = \MailSo\Cache\Drivers\APC::NewInstance();
break; break;
case 'MEMCACHE' === $sDriver && \MailSo\Base\Utils::FunctionExistsAndEnabled('memcache_connect'):
case 'MEMCACHED' === $sDriver && \MailSo\Base\Utils::FunctionExistsAndEnabled('memcache_connect'): case ('MEMCACHE' === $sDriver || 'MEMCACHED' === $sDriver) &&
\MailSo\Base\Utils::FunctionExistsAndEnabled('memcache_connect'):
$oDriver = \MailSo\Cache\Drivers\Memcache::NewInstance( $oDriver = \MailSo\Cache\Drivers\Memcache::NewInstance(
$this->Config()->Get('labs', 'fast_cache_memcache_host', '127.0.0.1'), $this->Config()->Get('labs', 'fast_cache_memcache_host', '127.0.0.1'),
(int) $this->Config()->Get('labs', 'fast_cache_memcache_port', 11211) (int) $this->Config()->Get('labs', 'fast_cache_memcache_port', 11211)
); );
break; break;
default: default:
$oDriver = \MailSo\Cache\Drivers\File::NewInstance(APP_PRIVATE_DATA.'cache'); $oDriver = \MailSo\Cache\Drivers\File::NewInstance(APP_PRIVATE_DATA.'cache');
break; break;
@ -749,10 +755,18 @@ class Actions
$this->oLogger->WriteEmptyLine(); $this->oLogger->WriteEmptyLine();
$oHttp = $this->Http(); $oHttp = $this->Http();
$this->oLogger->Write('[DATE:'.\gmdate('d.m.y').'][RL:'.APP_VERSION.'][PHP:'.PHP_VERSION.'][IP:'. $this->oLogger->Write('[DATE:'.\gmdate('d.m.y').'][RL:'.APP_VERSION.'][PHP:'.PHP_VERSION.'][IP:'.
$oHttp->GetClientIp().'][PID:'.(\MailSo\Base\Utils::FunctionExistsAndEnabled('getmypid') ? \getmypid() : 'unknown'). $oHttp->GetClientIp().'][PID:'.(\MailSo\Base\Utils::FunctionExistsAndEnabled('getmypid') ? \getmypid() : 'unknown').
'][GUID:'.\MailSo\Log\Logger::Guid().']'); '][GUID:'.\MailSo\Log\Logger::Guid().']');
$this->oLogger->Write(
'[APC:'.(\MailSo\Base\Utils::FunctionExistsAndEnabled('apc_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()).']'
);
$this->oLogger->Write( $this->oLogger->Write(
'['.$oHttp->GetMethod().'] '.$oHttp->GetScheme().'://'.$oHttp->GetHost(false, false).$oHttp->GetServer('REQUEST_URI', ''), '['.$oHttp->GetMethod().'] '.$oHttp->GetScheme().'://'.$oHttp->GetHost(false, false).$oHttp->GetServer('REQUEST_URI', ''),
\MailSo\Log\Enumerations\Type::NOTE, 'REQUEST'); \MailSo\Log\Enumerations\Type::NOTE, 'REQUEST');

View file

@ -186,4 +186,13 @@ class Api
return false; return false;
} }
/**
* @return bool
*/
public static function LogoutCurrentLogginedUser()
{
\RainLoop\Utils::ClearCookie('rlsession');
return false;
}
} }

View file

@ -14,22 +14,30 @@ abstract class AbstractConfig
*/ */
private $aData; private $aData;
/**
* @var bool
*/
private $bUseApcCache;
/** /**
* @var string * @var string
*/ */
protected $sFilePrefix; private $sFileHeader;
/** /**
* @param string $sFileName * @param string $sFileName
* @param string $sFilePrefix = '' * @param string $sFileHeader = ''
* *
* @return void * @return void
*/ */
public function __construct($sFileName, $sFilePrefix = '') public function __construct($sFileName, $sFileHeader = '')
{ {
$this->sFile = \APP_PRIVATE_DATA.'configs/'.$sFileName; $this->sFile = \APP_PRIVATE_DATA.'configs/'.$sFileName;
$this->sFilePrefix = $sFilePrefix; $this->sFileHeader = $sFileHeader;
$this->aData = $this->defaultValues(); $this->aData = $this->defaultValues();
$this->bUseApcCache = APP_USE_APC_CACHE &&
\MailSo\Base\Utils::FunctionExistsAndEnabled(array('apc_fetch', 'apc_store'));
} }
/** /**
@ -42,7 +50,7 @@ abstract class AbstractConfig
*/ */
public function IsInited() public function IsInited()
{ {
return is_array($this->aData) && 0 < count($this->aData); return \is_array($this->aData) && 0 < \count($this->aData);
} }
/** /**
@ -73,7 +81,7 @@ abstract class AbstractConfig
{ {
if (isset($this->aData[$sSectionKey][$sParamKey][0])) if (isset($this->aData[$sSectionKey][$sParamKey][0]))
{ {
$sType = gettype($this->aData[$sSectionKey][$sParamKey][0]); $sType = \gettype($this->aData[$sSectionKey][$sParamKey][0]);
switch ($sType) switch ($sType)
{ {
default: default:
@ -96,6 +104,82 @@ abstract class AbstractConfig
} }
} }
/**
* @return string
*/
private function cacheKey()
{
return 'config:'.\sha1($this->sFile).':';
}
/**
* @return bool
*/
private function loadDataFromCache()
{
if ($this->bUseApcCache)
{
$iMTime = @\filemtime($this->sFile);
if (\is_int($iMTime) && 0 < $iMTime)
{
$sKey = $this->cacheKey();
$iTime = \apc_fetch($sKey.'time');
if ($iTime && $iMTime === (int) $iTime)
{
$aFetchData = \apc_fetch($sKey.'data');
if (\is_array($aFetchData))
{
$this->aData = $aFetchData;
return true;
}
}
}
}
return false;
}
/**
* @return bool
*/
private function storeDataToCache()
{
if ($this->bUseApcCache)
{
$iMTime = @\filemtime($this->sFile);
if (\is_int($iMTime) && 0 < $iMTime)
{
$sKey = $this->cacheKey();
\apc_store($sKey.'time', $iMTime);
\apc_store($sKey.'data', $this->aData);
return true;
}
}
return false;
}
/**
* @return bool
*/
private function clearCache()
{
if ($this->bUseApcCache)
{
$sKey = $this->cacheKey();
\apc_delete($sKey.'time');
\apc_delete($sKey.'data');
return true;
}
return false;
}
/** /**
* @return bool * @return bool
*/ */
@ -103,6 +187,11 @@ abstract class AbstractConfig
{ {
if (\file_exists($this->sFile) && \is_readable($this->sFile)) if (\file_exists($this->sFile) && \is_readable($this->sFile))
{ {
if ($this->loadDataFromCache())
{
return true;
}
$aData = @\parse_ini_file($this->sFile, true); $aData = @\parse_ini_file($this->sFile, true);
if (\is_array($aData) && 0 < count($aData)) if (\is_array($aData) && 0 < count($aData))
{ {
@ -117,6 +206,8 @@ abstract class AbstractConfig
} }
} }
$this->storeDataToCache();
return true; return true;
} }
} }
@ -191,8 +282,9 @@ abstract class AbstractConfig
} }
} }
$this->clearCache();
return false !== \file_put_contents($this->sFile, return false !== \file_put_contents($this->sFile,
(0 < \strlen($this->sFilePrefix) ? $this->sFilePrefix : ''). (0 < \strlen($this->sFileHeader) ? $this->sFileHeader : '').
$sNewLine.\implode($sNewLine, $aResultLines)); $sNewLine.\implode($sNewLine, $aResultLines));
} }
} }

View file

@ -24,6 +24,8 @@ Options -Indexes
define('APP_REQUEST_RND', md5(APP_START.rand(10000, 99999).APP_START)); define('APP_REQUEST_RND', md5(APP_START.rand(10000, 99999).APP_START));
define('APP_VERSION_ROOT_PATH', APP_INDEX_ROOT_PATH.'rainloop/v/'.APP_VERSION.'/'); define('APP_VERSION_ROOT_PATH', APP_INDEX_ROOT_PATH.'rainloop/v/'.APP_VERSION.'/');
define('APP_USE_APC_CACHE', true);
$sCustomDataPath = ''; $sCustomDataPath = '';
if (file_exists(APP_INDEX_ROOT_PATH.'include.php')) if (file_exists(APP_INDEX_ROOT_PATH.'include.php'))
{ {