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

Command icon 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:

Comments

eporama created an issue. See original summary.

solideogloria’s picture

I have this problem, too, in Drupal 10.3. I didn't have this warning until I updated to 10.3.2

mfb made their first commit to this issue’s fork.

mfb’s picture

Status: Active » Needs review
bas123’s picture

Drupal 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.

php_value apc.shm_size 64MB

However, my Status Report still shows the same error:

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.

Issue Solved: See #27 below

cilefen’s picture

apc.shm_size is an INI_SYSTEM configuration value. You can’t set it in .htaccess files.

mfb’s picture

Issue summary: View changes

Clarify the proposed resolutions.

dhendriks’s picture

I have this problem as well:

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.
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Small change but seems like something need test coverage for

mfb’s picture

It 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.

holljac’s picture

I'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.

catch’s picture

Re #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.

mfb’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Yes 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.

smustgrave’s picture

Is the gitlab setup reason the test-only feature could be passing?

mfb’s picture

@smustgrave yes the test-only will fail only on environments with the default php config, not the CI environment.

smustgrave’s picture

Cool will test locally in the morning

catch’s picture

Although it might make sense to flush it somehow, but I guess that's easier said than done?

You 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.

mfb’s picture

Yeah 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..

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
1) Drupal\Tests\system\Functional\System\StatusTest::testStatusPage
Failed asserting that true is false.

Verifying test coverage locally.

catch’s picture

Status: Reviewed & tested by the community » Needs work

Needs work for that feedback.

mfb’s picture

Status: Needs work » Needs review

Alternate resolution which seems less verbose

mfb’s picture

Issue summary: View changes
catch’s picture

Status: Needs review » Needs work

Unless 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?

mfb’s picture

Status: Needs work » Needs review

Back to needs review

andypost’s picture

Status: Needs review » Needs work

The 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

bas123’s picture

Referencing #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:

The apc.shm_size setting can only be adjusted in system-level ini files, so I had to create a special configuration file to update the setting:

*SERVER*@az1-ls2 [~]# cat /etc/cl.php.d/alt-php83/custom.ini
apc.shm_size = 64M

https://YOURWEBSITE.net/info.php now shows 64MB of memory. Please let us know if there are any other issues we can help with.

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.

PHP APCu available caching: Memory available: 45.48 MB.
PHP APCu caching: Enabled (64 MB)

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!

mfb’s picture

Status: Needs work » Needs review

I 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 displaying ByteSizeMarkup::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')]

taran2l made their first commit to this issue’s fork.

taran2l’s picture

@mfb thanks for applying the suggestions. I think the result will be different if someone has more than 1 segment for APCu.

mfb’s picture

Issue summary: View changes

Yes 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.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Actually got hit by this on a client project and the MR does fix the issue.

  • catch committed 7bd49923 on 10.3.x
    Issue #3466399 by mfb, taran2l, eporama: APCu requirement for 32M is...

  • catch committed d7a02d8c on 10.4.x
    Issue #3466399 by mfb, taran2l, eporama: APCu requirement for 32M is...

  • catch committed a4d0e692 on 11.0.x
    Issue #3466399 by mfb, taran2l, eporama: APCu requirement for 32M is...

  • catch committed 8705b9ab on 11.x
    Issue #3466399 by mfb, taran2l, eporama: APCu requirement for 32M is...
catch’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x and cherry-picked back through to 10.3.x, thanks!

ronraney’s picture

Can someone please tell me how to implement a merge request? I'm used to patches. Is this a matter of updating Drupal itself? Thanks

solideogloria’s picture

cilefen’s picture

@rraney Are you asking how to use the code changes that are in this issue before they are officially released?

ronraney’s picture

I 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?

solideogloria’s picture

Yes. 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.

cilefen’s picture

@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.

catch’s picture

@rraney this will go out with the next patch release of Drupal 10.3 which will be the first Wednesday of September.

joaomachado’s picture

@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.

zieder’s picture

Regarding #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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

paintingguy’s picture

it's back after latest D10 update My bad, I needed to clear my cache which turned off the warning. Cheers to all

karenann’s picture

I 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.

PHP APCu caching. Enabled (128 MB)
Depending on your configuration, Drupal can run with a 128 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.

I have cleared the cache.

godotislate’s picture

@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.