The current check introduced in #2502507: Add a hook_requirements() warning if no opcode cache is enabled 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'),
It can be used via public function PhpConfigDataCollector::hasZendOpcache
In fact, we could even re-use the same simple and reliable check we already have for the only opcache function used in core:
if (function_exists('opcache_invalidate')) {}
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.
Any change is required in system requirements and install.php.
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | 2639878.patch | 2.64 KB | robloach |
| #21 | 2639878-opcache-8.2.x.patch | 2.64 KB | robloach |
| #17 | 2639878-opcache-8.2.x.patch | 2.73 KB | robloach |
| #14 | 2639878-opcache-check-8.2.patch | 1.61 KB | robloach |
| #13 | 2639878-opcache-check.patch | 1.61 KB | robloach |
Comments
Comment #2
omega8cc commentedIt should also affect similar check introduced in #2421451: Drupal needs comments in opcache
Comment #3
cilefen commentedComment #4
omega8cc commentedA patch for review attached.
Comment #5
omega8cc commentedStatus update.
Comment #6
cilefen commentedIs it possible checking for opcache_invalidate isn't good enough? I seem to remember the function can exist without opcache being really enabled.
Comment #7
omega8cc commentedYes, we can add the extra ini check, but I also have to fix the logical error I have introduced.
Comment #8
omega8cc commentedNote that everywhere we use
opcache_invalidate()in core we don't check for anything else, so maybe we should extend the check also elsewhere to match the logic used in Symfony, but it should be a separate issue then, I think?Comment #9
omega8cc commentedBetter patch attached for review.
Comment #10
cilefen commentedComment #13
robloachThis issue is persistent in PHP7, even though opcode comes with PHP7 by default. I've updated the patch to make sure there aren't any git conflicts.
Comment #14
robloachAnd here it is for Drupal 8.2.
Comment #15
joelpittetThis seems like a reasonable change for 8.1.x as a bug report.
Comment #16
alexpottReading the docs...
I don't see how using the existence of the
opcache_invalidate()is any different from usingopcache_get_status(). How about just adding a static method to\Drupal\Component\Utility\OpCodeCachecalledisEnabledthat just checksreturn extension_loaded('Zend OPcache') && ini_get('opcache.enable');and then using this in the two locations. I don't think we need to usePhpConfigDataCollectorthat does far more than we need it too.Comment #17
robloachMoves to an
OpCodeCache::isEnabled()function, also touched it up to useopcache_get_status().Updated the PR at https://github.com/RobLoach/drupal/pull/8 . Applies cleanly against 8.1.x and 8.2.x.
Comment #19
joelpittetLooks like unrelated migrate test failures
Comment #20
joelpittet@RobLoach why not check with the code Alex mentioned?
return extension_loaded('Zend OPcache') && ini_get('opcache.enable');The cleanup with the static is nice btw!
Comment #21
robloachMissed that one, thanks.
Comment #23
robloachUpdated.
Comment #24
omega8cc commented@alexpott -- re: "I don't see how using the existence of the opcache_invalidate() is any different from using opcache_get_status()" -- I have explained this at the top of this issue -- you can't use opcache_get_status() when opcache.restrict_api is used. But you can still use opcache_invalidate(), so it provides enough confirmation that it is loaded, without conflicting with opcache.restrict_api
Comment #25
memtkmcc commented#23 works great and applies cleanly -- see the screenshot. Thanks!
Comment #26
xjmThis issue includes a small API addition, so raising visibility for the beta deadline.
Comment #27
catchCommitted/pushed to 8.2.x, thanks!
Comment #29
omega8cc commentedThank you!