Problem/Motivation
After setting apc.shm_size to 32M, I was getting the warning:
PHP APCu caching. Enabled (32 MB)
Depending on your configuration, Drupal can run with a 32 MB APCu limit. However, a 32 MB APCu limit (the default) or above is recommended, especially if your site uses additional custom or contributed modules.
This is confusing because the site is set to the recommendation.
Steps to reproduce
Setting `apc.shm_size` in `php.ini` will allocate that memory to apcu. The amount of memory allocated to the segment size for apcu reported as `seg_size` from `apcu_sma_info(TRUE)`. However, depending on which version of PHP you’re using (and possibly other unknowns) the values aren’t the same.
$ drush ev 'print ini_get("apc.shm_size") . PHP_EOL;'
32M
According to [PHP's documentation on short values](https://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes), 32M should be 32*1048576 (32*1024*1024) which would be: `33554432`
$ drush ev 'print apcu_sma_info(TRUE)["seg_size"].PHP_EOL;'
33554304
This value being returned for seg_size is not quite the same because of how PHP/APC actually make the allocation. Since it happens to be 128 bytes smaller, it causes a warning.
This leads to a very small discrepancy, however with the changes made in #3142928: Status report wrongly warns of APCu memory limit when admin language is not English we check the value by converting to bytes and making a direct greater than comparison.
In addition, the APCu status check calculations do not take into account that more than one shared memory segment may be configured.
Proposed resolution
For the check against "recommendations", we should check the value of Bytes::toNumber(ini_get('apc.shm_size')) * ini_get('apc.shm_segments'). The calculations for % used are appropriate to use seg_size. In both cases, the seg_size and shm_size must be multiplied by the number of segments.
Release notes snippet
Issue fork drupal-3466399
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3466399-apcu-requirement-for
changes, plain diff MR !9149
Comments
Comment #2
solideogloria commentedI have this problem, too, in Drupal 10.3. I didn't have this warning until I updated to 10.3.2
Comment #5
mfbComment #6
bas123 commentedDrupal Version: 10.3.2
PHP Version: 8.3.9 - Memory limit: 4G
As others above, this error has been present through several recent updates of Drupal Core and other key modules, but always resolved after clearing caches, however since updating to D 10.3.2, it doesn't go away!
I asked my hosting company to increase this limit to 64 MG and they complied with no hesitation.
Their method was to add the following line to the document root (public_html) folder's .htaccess file.
However, my Status Report still shows the same error:
Issue Solved: See #27 below
Comment #7
cilefen commentedapc.shm_size is an INI_SYSTEM configuration value. You can’t set it in .htaccess files.
Comment #8
mfbClarify the proposed resolutions.
Comment #9
dhendriks commentedI have this problem as well:
Comment #10
smustgrave commentedSmall change but seems like something need test coverage for
Comment #11
mfbIt looks like the CI environment sets the APCu size to 3GB - whoa, that seems like a huge waste of memory, or could tests actually use that much APCu cache somehow? So, I don't think it will be easy to reproduce this exact bug there, unless there's a way for tests to modify the php config files, but we could add a test that verifies this case in test environments using the default config.
Comment #12
holljac commentedI'm getting the same warning since updating to 10.3.2. I'm using php 8.3.6. My site is hosted on Bluehost. Is there any way to eliminate this warning?
PHP APCu cachingEnabled (32 MB)
Depending on your configuration, Drupal can run with a 32 MB APCu limit. However, a 32 MB APCu limit (the default) or above is recommended, especially if your site uses additional custom or contributed modules.
Comment #13
catchRe #11 I don't know the history of why it's configured like that, but given we run dozens of tests 24 at a time on a single machine it might be necessary to prevent apcu filling up and then fragmenting. Each test will get its own unique apcu prefix and there's no way to flush all prefixed items efficiently.
Comment #14
mfbYes I can see how the APCu cache will fill up as tests are run (literally, I can see this happening locally). Although it might make sense to flush it somehow, but I guess that's easier said than done? Anyways, I added a functional test.
Comment #15
smustgrave commentedIs the gitlab setup reason the test-only feature could be passing?
Comment #16
mfb@smustgrave yes the test-only will fail only on environments with the default php config, not the CI environment.
Comment #17
smustgrave commentedCool will test locally in the morning
Comment #18
catchYou can clear the entire cache, but because we run tests concurrently and tests can take anything from a few seconds to a couple of minutes each, flushing at the end of each test run would mean clearing the cache for all the other tests that are still running every few seconds. We could open an issue to see how performance and reliability looks like if we just set it a bit lower and let it fill up occasionally - went ahead and opened on here: #3467490: Investigate setting the apcu cache size lower.
Comment #19
mfbYeah I meant flush the entries that can be flushed, pertaining to a discrete test run that is over, not flushing everything. But idk how that'd be done, since a testrunner is a cli process that doesn't have access to APCu..
Comment #20
smustgrave commentedVerifying test coverage locally.
Comment #21
catchNeeds work for that feedback.
Comment #22
mfbAlternate resolution which seems less verbose
Comment #23
mfbComment #24
catchUnless I'm missing something that will re-introduce the original multilingual bug from #3142928: Status report wrongly warns of APCu memory limit when admin language is not English?
Comment #25
mfbBack to needs review
Comment #26
andypostThe check and the value rendered in status report must be the same, otherwise no way to get a reason of warning
See #3142928-69: Status report wrongly warns of APCu memory limit when admin language is not English
Comment #27
bas123 commentedReferencing #6,
UPDATE: Exclusive of any Drupal Core Code adjustments affecting the reporting of this issue, my case was resolved via the Hosting Provider, A2 Hosting (Advanced Tech Support)
Here's how:
This seems to have solved the reporting issue as all my Drupal Status Reports on the server no longer show the error and in fact report accurate information regarding the APCu settings.
I will be doing a new update today on for Drupal sites under this server to see if this has modification truly resolved the error, if there is anything untoward, I will update, otherwise from my end it is closed!
Comment #28
mfbI don't see a problem in practice with displaying
ByteSizeMarkup::create($memory_info['seg_size'] * $memory_info['num_seg'])to the end user, as it's generally going to be the same as displayingByteSizeMarkup::create(Bytes::toNumber(ini_get('apc.shm_size')) * ini_get('apc.shm_segments')). The difference between configured size and reported size should be tiny enough that ByteSizeMarkup doesn't care.Either way works for me, really. So if folks are adamant about displaying
ByteSizeMarkup::create(Bytes::toNumber(ini_get('apc.shm_size')) * ini_get('apc.shm_segments')), sounds good to me.[EDITED to add
* ini_get('apc.shm_segments')]Comment #30
taran2l@mfb thanks for applying the suggestions. I think the result will be different if someone has more than 1 segment for APCu.
Comment #31
mfbYes I guess this was a long-standing bug, that segments weren't taken into account. I'm updating the issue summary to also mention this bug.
Comment #32
smustgrave commentedActually got hit by this on a client project and the MR does fix the issue.
Comment #37
catchCommitted/pushed to 11.x and cherry-picked back through to 10.3.x, thanks!
Comment #39
ronraney commentedCan someone please tell me how to implement a merge request? I'm used to patches. Is this a matter of updating Drupal itself? Thanks
Comment #40
solideogloria commented@rraney Introduction | Using GitLab to Contribute to Drupal
Comment #41
cilefen commented@rraney Are you asking how to use the code changes that are in this issue before they are officially released?
Comment #42
ronraney commentedI just want to know how to fix this issue @cilefen
I used the link to documentation provided by @solideogloria
It provided info on how to get a diff/patch which I applied
As for long-term fix, I assume it will be merged into future version of Drupal, correct?
Comment #43
solideogloria commentedYes. Make sure you download the patch and put it in a project folder, e.g. "./patches/filename.patch". Don't use the URL for a Merge Request patch, as it can change/break over time.
Comment #44
cilefen commented@rraney That's correct. With Drupal, maintainers commit changes to supported development branches then later, release managers distribute tagged releases as new versions. Before the releases, you must patch.
Comment #45
catch@rraney this will go out with the next patch release of Drupal 10.3 which will be the first Wednesday of September.
Comment #46
joaomachado commented@bas123 #27 is correct, in order to increase the memory it has to be added to the Global php.ini file, but most important, make sure you rebuild PHP-FPM or the changes will not take effect, atleast no on a cPanel system.
Comment #47
zieder commentedRegarding #27, A2 Hosting told me they could not increase the size of APCu cache on shared hosting. It is stuck at 32MB. I am assuming from subsequent posts this "Warning" will go away with the next release, or at least on coming up soon.
Comment #49
paintingguy commentedit's back after latest D10 updateMy bad, I needed to clear my cache which turned off the warning. Cheers to allComment #50
karenann commentedI don't want to reopen in case it's just me, but I see this error in 10.4.3, 10.5.1 and 10.5.2 hosted on Pantheon.
I have cleared the cache.
Comment #51
godotislate@karenann see #3538854: APCu requirement for 32MB always displays since APCu 5.1.25. It should be fixed in the next patch release for 10.5+. 10.4 is on security support only, but you can see if the commit for 10.5 applies as a patch to 10.4.