Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Warning: Zend OPcache API is restricted by "restrict_api" #733

Closed
raamdev opened this issue Apr 9, 2016 · 9 comments
Closed

PHP Warning: Zend OPcache API is restricted by "restrict_api" #733

raamdev opened this issue Apr 9, 2016 · 9 comments
Assignees
Labels
Milestone

Comments

@raamdev
Copy link
Contributor

raamdev commented Apr 9, 2016

In some scenarios src/includes/closures/Shared/SysUtils.php#L85 may throw the following warning:

PHP Warning: Zend OPcache API is restricted by "restrict_api" configuration directive in /www/wp-content/plugins/comet-cache/src/includes/closures/Shared/SysUtils.php on line 85

This is most likely the result of stringent rules put in place with opcache.restrict_api. So while functionIsPossible('opcache_get_status') on the previous line, the actual call to opcache_get_status() fails with a Warning.

I recommend that we suppress these warnings with @:

    if (!is_array($status = @opcache_get_status(false)) || !$status) {
        return ($status = false);
    }

Referencing: https://wordpress.org/support/topic/zend-opcache-api-is-restricted

@raamdev raamdev added the todo label Apr 9, 2016
@raamdev raamdev added this to the Next Release milestone Apr 27, 2016
@raamdev
Copy link
Contributor Author

raamdev commented Apr 27, 2016

@jaswsinc Any opposition to suppressing warnings from opcache_get_status() here?

@jaswrks
Copy link

jaswrks commented Apr 27, 2016

I have no problem with that, no.

Alternatively, you could add a specific check for that scenario here: https://github.com/websharks/comet-cache/blob/160227/src/includes/closures/Shared/ConditionalUtils.php#L345-L347

The idea would be to check the opcache.restrict_api INI setting and then decide if the function is disabled or not. If it is, add it to the $disabled_functions array there. Then, before you call upon opcache_get_status, check if it can be called upon first.

if ($this->functionIsPossible('opcache_get_status')) {

}

@raamdev
Copy link
Contributor Author

raamdev commented Apr 27, 2016

@jaswsinc writes...

Alternatively, you could add a specific check for that scenario here:

I like that idea better. I was just reviewing the docs for opcache.restrict_api:

opcache.restrict_api
Allows calling OPcache API functions only from PHP scripts which path is started from specified string. The default "" means no restriction.

So, to support this properly we should be checking to see if opcache.restrict_api is blank (i.e., Comet Cache will be allowed) or if opcache.restrict_api contains a path that has partial match to the path to the Comet Cache plugin.

That said, the docs are not clear on whether or not partial matches apply here, e.g., if opcache.restrict_api is set to /srv/www/ and the script is in /srv/www/wordpress/wp-content/plugins/comet-cache-pro/, will that be considered allowed? Or would the script have to literally be in /srv/www/? I assume the former behavior, but we need to run some tests to confirm.

@jaswrks
Copy link

jaswrks commented Apr 27, 2016

Noting that this would make a nice addition here also.

@raamdev
Copy link
Contributor Author

raamdev commented Apr 27, 2016

I see, so it looks like the path of the script just needs to start with the path defined in opcache.restrict_api (i.e., if opcache.restrict_api is set to /srv/www/ and the script is in /srv/www/wordpress/wp-content/plugins/comet-cache-pro/, that will be allowed).

@jaswrks
Copy link

jaswrks commented Apr 27, 2016

Yes, I confirmed that locally also.

@raamdev raamdev modified the milestones: Next Release, Future Release May 11, 2016
@raamdev raamdev modified the milestones: Future Release, Next Release Jun 20, 2016
@raamdev raamdev modified the milestones: Next Release, Future Release Aug 24, 2016
@raamdev raamdev modified the milestones: Next Release, Future Release Oct 11, 2016
jaswrks pushed a commit to wpsharks/core that referenced this issue Dec 7, 2016
jaswrks pushed a commit to wpsharks/comet-cache-pro that referenced this issue Dec 7, 2016
jaswrks pushed a commit to wpsharks/comet-cache-pro that referenced this issue Dec 7, 2016
…onsidering INI option `opcache.restrict_api`. Comet Cache is now smart enough to avoid the error: _PHP Warning: Zend OPcache API is restricted by "restrict_api" configuration directive_. See [Issue #733](wpsharks/comet-cache#733).
@renzms
Copy link

renzms commented Dec 16, 2016

@raamdev @jaswsinc

Confirmed Working

When restricting Zend OPcache API by opcache.restrict_api = /foo/bar

The PHP warning does not appear in the WP Dashboard with Comet Cache active.

Double checking this with OP Cache Dashboard plugin, this shows up in the error log:

Warning: Zend OPcache API is restricted by "restrict_api" configuration directive in /app/src/wp-content/plugins/opcache/opcache.php on line 238 
Call Stack: 0.0003 389536 
1. {main}() /app/src/wp-admin/admin.php:0 0.1710 3769296 
2. do_action() /app/src/wp-admin/admin.php:222 0.1710 3769672 
3. WP_Hook->do_action() /app/src/wp-includes/plugin.php:453 0.1710 3769672 
4. WP_Hook->apply_filters() /app/src/wp-includes/class-wp-hook.php:323 0.1710 3770800 
5. OPcache_dashboard->render_admin_page() /app/src/wp-includes/class-wp-hook.php:298 0.1710 3770800 6. opcache_get_configuration() /app/src/wp-content/plugins/opcache/opcache.php:238 

raamdev added a commit that referenced this issue Dec 21, 2016
- **Bug Fix:** Improving PHP OPcache detection. Now considering the INI option `opcache.restrict_api`. Comet Cache is now smart enough to avoid generating the PHP Warning: _PHP Warning: Zend OPcache API is restricted by "restrict_api" configuration directive_. See [Issue #733](#733).
- **New Feature (Pro): Mobile Mode.** This release adds a new feature that is designed to improve compatibility with Adaptive themes for mobile devices. To learn more, please see: **Dashboard → Comet Cache Pro → Plugin Options → Mobile Mode**. See also: [Issue #471](#471).
- **Enhancement: Auto-Clearing Author Page Cache.** This release makes Comet Cache smart enough to detect when a user is deleted (or removed from a child blog in a Network), at which time the Author page for that user will be cleared from the cache so it can be regenerated automatically. See [Issue #304](#304).
- **Enhancement: Multibyte Compatibility.** This release improves support for WordPress Permalinks that contain UTF-8 symbols (or emojis) in them. More specifically, this release adds the `/u` flag to all `preg_*()` calls in cache clearing routines that generate cache paths from Watered-Down Regex patterns entered by a site owner. See: [Issue #611](#611).
- **Enhancement: Widget Change Detection.** Comet Cache can now detect when **Appearance → Widgets** are added/edited/removed, and Comet Cache will automatically clear the cache so that your site remains up-to-date. See [Issue #411](#411).
- **Enhancement (Pro): Static CDN Filters and `srcset`.** This release enhances Static CDN Filters in Comet Cache Pro. Static CDN Filters are now smart enough to filter all image sources included in an `srcset=""` attribute that is generated by WordPress. See [Issue #660](#660). If you'd like to learn more about `srcset=""`, see [this article at WordPress.org](https://make.wordpress.org/core/2015/11/10/responsive-images-in-wordpress-4-4/).
- **Enhancement (Pro): Automatic Background Updates.** It is now possible to enable automatic background updates that occur quietly in the background whenever new features, bug fixes, or security issues are addressed by our developers. See: **Dashboard → Comet Cache Pro → Config. Options → Update Credentials**. See also: [Issue #827](#827).
- **Enhancement (Pro): HTML Compressor + Accelerated Mobile Pages (AMP).** Updated to the latest available release of the HTML Compressor (v161208) with improved support for [Accelerated Mobile Pages](https://www.ampproject.org/). See: [Issue #695](#695). See also: [HTML Compressor v161208 changelog](https://github.com/websharks/html-compressor/releases/tag/161208).
- **Enhancement (Pro): HTML Compressor / AMP Compatibility.** Improved compatibility with [Accelerated Mobile Pages](https://www.ampproject.org/). There is a new HTML Compressor option that is enabled by default and it makes Comet Cache smart enough to auto-detect and selectively disable portions of the HTML Compressor that are incompatible with the AMP spec; i.e., routines that are not necessary when serving APMd pages. In short, if the URI being compressed ends with `/amp/`, or the document contains a top-level `<html ⚡>` tag (`<html amp>` is accepted as well), then features which are incompatible with [Accelerated Mobile Pages](https://www.ampproject.org/) will be disabled accordingly.
- **Compatibility:** Avoid deprecated `wp_get_sites()` and use `get_sites()` instead. See [Issue #848](#848).
- **Documentation:** Added Watered-Down Regex documentation notes to the inline documentation (in the software) about the use of `^` and `$` in some places where these special characters are not fully supported. Also adding the same notes to the [Watered-Down Regex KB Article](https://cometcache.com/r/watered-down-regex-syntax/). See also: [Issue #611](#611).
@raamdev
Copy link
Contributor Author

raamdev commented Dec 21, 2016

Comet Cache v161221 has been released and includes changes from this GitHub Issue. See the v161221 announcement for further details.


This issue will now be locked to further updates. If you have something to add related to this GitHub Issue, please open a new GitHub Issue and reference this one (#733).

@raamdev raamdev closed this as completed Dec 21, 2016
@wpsharks wpsharks locked and limited conversation to collaborators Dec 21, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants