Problem/Motivation

Drupal 8 can be anything up to 2-3 times faster with an opcode cache. I've seen pages take 180ms with opcache enabled, and 480ms without.

Also after doing some memory profiling I forgot to disable opcache (actually I re-enabled it, but in a file that was overridden by another php.ini elsewhere that had it disabled), and was shocked how slow everything was.

Proposed resolution

Add a hook_requirements() that checks for either APC or Opcache, and warns if neither are enabled, this should be both on install and runtime.

We could also get a rough idea of the memory allocation required for standard profile and warn if it's under that too - since Drupal usually requires more than the default and especially APC hates having a full cache.

Remaining tasks

Decide if this is a good idea. The only drawback is that some hosts may not provide an opcode cache, and then users will be stuck with a warning they can't do anything about. But at this point they are probably better off changing hosting if this isn't resolvable.

User interface changes

Yes.

API changes

No.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moshe weitzman’s picture

+1.

There could be a module that alters away the warning for sites that dont are stuck or dont care.

cilefen’s picture

For runtime, are we are talking about the system status report? If so, +1.

umarzaffer’s picture

Status: Active » Needs review
FileSize
1.39 KB

Submitting initial patch, however need suggestions for the following -

  • In case OP Caching is already available, should we show the user (on admin/reports/status page) the type of OP cache installed in addition to the 'Enabled' status?
  • In case we find that more than one OP caching is installed, should we alert about the same since this might cause server errors?

Thanks

dawehner’s picture

In case OP Caching is already available, should we show the user (on admin/reports/status page) the type of OP cache installed in addition to the 'Enabled' status?

What about telling users, which don't have it installed, how to enable OP cache, like linking to some specific page.
Btw. http://php.net/manual/de/opcache.installation.php is not entirely 100% helpful

cilefen’s picture

The cache that ought to be used depends on the PHP version. I could be wrong, but < 5.5 should use APC and >= 5.5 should use Zend Opcache.

cilefen’s picture

Wim Leers’s picture

#6: you beat me to it by 8 minutes :D

kfitz’s picture

What about telling users, which don't have it installed, how to enable OP cache, like linking to some specific page.
Btw. http://php.net/manual/de/opcache.installation.php is not entirely 100% helpful

In case we find that more than one OP caching is installed, should we alert about the same since this might cause server errors?

I agree with both of these comments. Linking to documentation will be helpful for users, as will informing on status if more then one OP cache is installed; perhaps the former warrants throwing another warning.

As per the Proposed Resolution:

We could also get a rough idea of the memory allocation required for standard profile and warn if it's under that too - since Drupal usually requires more than the default and especially APC hates having a full cache

The patch has not quite addressed this aspect of the issue yet, but other than that everything looks good!

Wim Leers’s picture

Given #2296557-145: [policy] Require PHP 5.5, where Dries has decided to ship Drupal 8 with requiring PHP 5.5, this issue no longer needs to be fixed, because 5.5 ships with the OpCache extension enabled by default.

But… it's still possible to disable that extension. So… perhaps we should still do this?

dawehner’s picture

Given #2296557-145: [policy] Require PHP 5.5, where Dries has decided to ship Drupal 8 with requiring PHP 5.5, this issue no longer needs to be fixed, because 5.5 ships with the OpCache extension enabled by default.

Its not only that, you can also just configure it and I think on ubuntu it hasn't been enabled by default.

catch’s picture

Yes I think we need to check specifically for opcache.enable - no good having the extension enabled and actual opcode caching disabled.

Also in a follow-up, we could check opcache.memory_consumption and opcache_get_status() and warn people if the cache is full.

moshe weitzman’s picture

Priority: Normal » Major

We would save significant hassles with this I think.

cilefen’s picture

This is a reworking of #3, now that APC is out of the picture.

Status: Needs review » Needs work

The last submitted patch, 13: add_a-2502507-13.patch, failed testing.

catch’s picture

Could probably check for #2551309: Increase opcache.max_accelerated_files here too.

Status: Needs work » Needs review

cilefen queued 13: add_a-2502507-13.patch for re-testing.

serg2’s picture

In regard to the max-accelerated files side of it, 16228 as the minimum value to look for would makes sense.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Lets just get this bit in. I'd rather bikeshed other limits in a new issue.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

If I disable opcache using

opcache.enable=0

in php.ini this still reports opcache as being on.

cilefen’s picture

How DARE you actually check the patches? Ha ha. We need a new runtime test.

cilefen’s picture

Status: Needs work » Needs review
FileSize
2.22 KB
1.29 KB

This one actually works!

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

opcache_get_status()['opcache_enabled'] == TRUE

The == TRUE part is superflous. Can be fixed on commit if cilefen doesn't get to it.

cilefen’s picture

cilefen’s picture

@moshe weitzman Thank you for reviewing.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed f617434 and pushed to 8.0.x. Thanks!

  • alexpott committed f617434 on 8.0.x
    Issue #2502507 by cilefen, umarzaffer: Add a hook_requirements() warning...

Status: Fixed » Closed (fixed)

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

omega8cc’s picture

Status: Closed (fixed) » Needs work

The current check is too demanding and as a consequence, doesn't allow to use more secure settings, like opcache.restrict_api protection, because it will in turn auto-disable opcache_get_status(). We should instead use the check Symfony already has in place:

'zend_opcache_enabled' => extension_loaded('Zend OPcache') && ini_get('opcache.enable'),

This allows to configure any restrictions the server admin wants to avoid data leaks (like paths to scripts between sites on the same system) which are available if you allow opcache_get_status() to satisfy Drupal current requirements.

omega8cc’s picture

In fact, we could even re-use the check we already have for the only opcache function used in core:

if (function_exists('opcache_invalidate')) {}

cilefen’s picture

Status: Needs work » Closed (fixed)
Related issues: +#2421451: Drupal needs comments in opcache

@omega8cc Good idea, but open a followup for this and refer to it here please. The reason is that similar syntax is used in #2421451: Drupal needs comments in opcache and we may as well fix them both.

omega8cc’s picture

cilefen’s picture