Skip to content

Commit

Permalink
Issue #2800605 by Chi, Wim Leers, dhirendra.mishra, mr.baileys, jheds…
Browse files Browse the repository at this point in the history
…trom, dawehner, borisson_, catch, alexpott: Warn/inform users when the hosting environment has a too low limit of APCU cache

(cherry picked from commit cee0a334817b123ae57127a1d37d8e721542e8da)
  • Loading branch information
alexpott committed Mar 3, 2020
1 parent d70caf0 commit 9066799
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions modules/system/system.install
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -311,6 +312,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'] = [
Expand Down

0 comments on commit 9066799

Please sign in to comment.