Unverified Commit cee0a334 authored by alexpott's avatar alexpott

Issue #2800605 by Chi, Wim Leers, dhirendra.mishra, mr.baileys, jhedstrom,...

Issue #2800605 by Chi, Wim Leers, dhirendra.mishra, mr.baileys, jhedstrom, dawehner, borisson_, catch, alexpott: Warn/inform users when the hosting environment has a too low limit of APCU cache
parent de27c163
......@@ -6,6 +6,7 @@
*/
use Drupal\Component\FileSystem\FileSystem as FileSystemComponent;
use Drupal\Component\Utility\Bytes;
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Environment;
use Drupal\Component\Utility\OpCodeCache;
......@@ -303,6 +304,46 @@ function system_requirements($phase) {
$requirements['php_opcache']['title'] = t('PHP OPcode caching');
}
// Check to see if APCu is installed and configured correctly.
if ($phase == 'runtime' && PHP_SAPI != 'cli') {
$requirements['php_apcu']['title'] = t('PHP APCu caching');
if (extension_loaded('apcu') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN)) {
$memory_info = apcu_sma_info(TRUE);
$apcu_actual_size = format_size($memory_info['seg_size']);
$apcu_recommended_size = '32 MB';
$requirements['php_apcu']['value'] = t('Enabled (@size)', ['@size' => $apcu_actual_size]);
if (Bytes::toInt($apcu_actual_size) < Bytes::toInt($apcu_recommended_size)) {
$requirements['php_apcu']['severity'] = REQUIREMENT_WARNING;
$requirements['php_apcu']['description'] = t('Depending on your configuration, Drupal can run with a @apcu_size APCu limit. However, a @apcu_default_size APCu limit (the default) or above is recommended, especially if your site uses additional custom or contributed modules.', [
'@apcu_size' => $apcu_actual_size,
'@apcu_default_size' => $apcu_recommended_size,
]);
}
else {
$memory_available = $memory_info['avail_mem'] / $memory_info['seg_size'];
if ($memory_available < 0.1) {
$requirements['php_apcu']['severity'] = REQUIREMENT_ERROR;
}
elseif ($memory_available < 0.25) {
$requirements['php_apcu']['severity'] = REQUIREMENT_WARNING;
}
else {
$requirements['php_apcu']['severity'] = REQUIREMENT_OK;
}
$requirements['php_apcu']['description'] = t('Memory available: @available.', [
'@available' => format_size($memory_info['avail_mem']),
]);
}
}
else {
$requirements['php_apcu'] += [
'value' => t('Not enabled'),
'severity' => REQUIREMENT_INFO,
'description' => t('PHP APCu caching can improve your site\'s performance considerably. It is <strong>highly recommended</strong> to have <a href="https://www.php.net/manual/apcu.installation.php" target="_blank">APCu</a> installed on your server.'),
];
}
}
if ($phase != 'update') {
// Test whether we have a good source of random bytes.
$requirements['php_random_bytes'] = [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment