From 8161de9ca6fc7a27f4efb05af440221693eba735 Mon Sep 17 00:00:00 2001 From: Mark Trapp Date: Thu, 24 Oct 2013 20:26:07 -0700 Subject: [PATCH] Issue #1984180 by Mark Trapp, torotil: Add APCu support. --- apc.install | 38 +++++++++++++++++++++++++++++++++----- apc.module | 13 ++++++++----- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/apc.install b/apc.install index bab073d..e64114a 100644 --- a/apc.install +++ b/apc.install @@ -10,17 +10,40 @@ function apc_requirements($phase) { // Test APC. $apc_enabled = (function_exists('apc_cache_info') && ($cache = @apc_cache_info('user', TRUE))); - $meets_version = version_compare(phpversion('apc'), '3.1.1')>= 0; + + if (extension_loaded('apcu')) { + $version = phpversion('apcu'); + $name = $t('APCu'); + $description = $t('APC needs APCu version >=4.0.2.'); + + $meets_version = version_compare($version, '4.0.2') >= 0; + + // APCu reports cache info with keys that differ from APC. + // This has been fixed upstream, but has not made it into a release. + // @see https://github.com/krakjoe/apcu/issues/41 + // @see https://github.com/krakjoe/apcu/pull/42 + $cache['num_entries'] = isset($cache['num_entries']) ? $cache['num_entries'] : $cache['nentries']; + $cache['start_time'] = isset($cache['start_time']) ? $cache['start_time'] : $cache['stime']; + + } + else { + $version = phpversion('apc'); + $name = $t('APCu'); + $description = $t('APC needs version >=3.1.1.'); + + $meets_version = version_compare($version, '3.1.1') >= 0; + } $requirements['apc'] = array( - 'title' => $t('APC'), - 'value' => $apc_enabled ? ($meets_version ? phpversion('apc') : $t('APC needs version >=3.1.1')) : $t('Not available'), + 'title' => $name, + 'value' => $apc_enabled ? ($meets_version ? $version : $description) : $t('Not available'), 'severity' => $apc_enabled && $meets_version ? ($cache['num_entries'] ? REQUIREMENT_OK : REQUIREMENT_WARNING) : REQUIREMENT_ERROR, ); if ($apc_enabled) { - $requirements['apc']['description'] = $t('APC has been running for !duration. Currently caching !num_entries entries (!memory_size).', + $requirements['apc']['description'] = $t('!name has been running for !duration. Currently caching !num_entries entries (!memory_size).', array( + '!name' => $name, '!duration' => format_interval(time() - $cache['start_time']), '!num_entries' => $cache['num_entries'], '!memory_size' => format_size($cache['mem_size']), @@ -28,7 +51,12 @@ function apc_requirements($phase) { ); } else { - $requirements['apc']['description'] = $t('The APC module needs the apc extension see: !link.', array('!link' => 'http://www.php.net/apc')); + $requirements['apc']['description'] = $t('The APC module needs the APC or the APCu extension.', + array( + '!apc_link' => 'http://www.php.net/apc', + '!apcu_link' => 'https://github.com/krakjoe/apcu', + ) + ); } return $requirements; diff --git a/apc.module b/apc.module index 31c5f2c..03a1924 100644 --- a/apc.module +++ b/apc.module @@ -92,11 +92,14 @@ function apc_form_system_performance_settings_alter(&$form, $form_state) { '#value' => t('Clear APC user cache'), '#submit' => array('apc_clear_user_cache'), ); - $form['clear_cache']['apc_opcode'] = array( - '#type' => 'submit', - '#value' => t('Clear APC opcode cache'), - '#submit' => array('apc_clear_opcode_cache'), - ); + + if (!extension_loaded('apcu')) { + $form['clear_cache']['apc_opcode'] = array( + '#type' => 'submit', + '#value' => t('Clear APC opcode cache'), + '#submit' => array('apc_clear_opcode_cache'), + ); + } } /** -- 1.8.5.2 (Apple Git-48)