* API: only cache in APC by default, if it has at least 64M of shared memory, otherwise use filesystem

This commit is contained in:
Ralf Becker 2012-10-23 07:49:42 +00:00
parent c77521cbd0
commit f6aa1ca1aa
2 changed files with 39 additions and 7 deletions

View File

@ -518,13 +518,6 @@ class egw_cache
} }
} }
// setting apc as default provide, if apc_fetch function exists AND not cli or apc enabled for cli
if (is_null(egw_cache::$default_provider))
{
egw_cache::$default_provider = function_exists('apc_fetch') && (PHP_SAPI != 'cli' || ini_get('apc.enable_cli')) ?
'egw_cache_apc' : 'egw_cache_files';
}
/** /**
* Interface for a caching provider for tree and instance level * Interface for a caching provider for tree and instance level
* *
@ -623,6 +616,12 @@ abstract class egw_cache_provider_check implements egw_cache_provider
} }
} }
// setting apc as default provider, if apc_fetch function exists AND further checks in egw_cache_apc recommed it
if (is_null(egw_cache::$default_provider))
{
egw_cache::$default_provider = function_exists('apc_fetch') && egw_cache_apc::available() ? 'egw_cache_apc' : 'egw_cache_files';
}
// some testcode, if this file is called via it's URL // some testcode, if this file is called via it's URL
// can be run on command-line: sudo php -d apc.enable_cli=1 -f phpgwapi/inc/class.egw_cache.inc.php // can be run on command-line: sudo php -d apc.enable_cli=1 -f phpgwapi/inc/class.egw_cache.inc.php
/*if (isset($_SERVER['SCRIPT_FILENAME']) && realpath($_SERVER['SCRIPT_FILENAME']) == __FILE__) /*if (isset($_SERVER['SCRIPT_FILENAME']) && realpath($_SERVER['SCRIPT_FILENAME']) == __FILE__)

View File

@ -40,6 +40,39 @@ class egw_cache_apc extends egw_cache_provider_check implements egw_cache_provid
} }
} }
/**
* Check if APC is available for caching user data
*
* Default shared memory size of 32M is just enough for the byte code cache,
* but not for caching user data, we only use APC by default if we have at least 64M.
*
* @return boolean true: apc available, false: not
*/
public static function available()
{
$available = false;
if (function_exists('apc_fetch') && (PHP_SAPI != 'cli' || ini_get('apc.enable_cli')))
{
$size = ini_get('apc.shm_size');
switch(strtoupper(substr($size, -1)))
{
case 'G':
$size *= 1024;
case 'M':
$size *= 1024;
case 'K':
$size *= 1024;
}
$size *= ini_get('apc.shm_segments');
// only cache in APC, if we have at least 64M available (default is 32M)
$available = $size >= 64*1024*1024;
}
//error_log(__METHOD__."() size=$size returning ".array2string($available));
return $available;
}
/** /**
* Stores some data in the cache * Stores some data in the cache
* *