PHP Warning: Zend OPcache can’t be temporary enabled

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, March 24, 2016

Follow me on Twitter as @mattiasgeniar

I recently ran into this problem on a PHP server and I figure I’d share the solution.

The logs were being filled with this alert:

[24-Mar-2016 Europe/Brussels] PHP Warning:  Zend OPcache can't be temporary enabled (it may be only disabled till the end of request) in Unknown on line 0
[24-Mar-2016 Europe/Brussels] PHP Warning:  Zend OPcache can't be temporary enabled (it may be only disabled till the end of request) in Unknown on line 0
[24-Mar-2016 Europe/Brussels] PHP Warning:  Zend OPcache can't be temporary enabled (it may be only disabled till the end of request) in Unknown on line 0

The interesting problem here is that, by default, OPcache was enabled. The default php.ini contained this value:

$ grep opcache /etc/php.ini
opcache.enable = 1

The problem occurred when I tried to enable the OPcache again. This time, from within the PHP-FPM pool configuration.

$ grep opcache /etc/php-fpm.d/*
php_admin_value[opcache.enable] = on

It appears that PHP isn’t amused when you try to enable the OPcache again, when it’s already enabled. It does appear to be just a cosmetic issue and doesn’t actually impact the functionality of the PHP code itself.

Either way, in this case the fix was to just remove the OPcache setting from PHP-FPM and keep it enabled in the default php.ini file.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.