PHP Warning: Zend OPcache can’t be temporary enabled

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.