PHP 7.0.1 and Opcache File Cache Only

Cyberdevil

Verified User
Joined
Sep 16, 2007
Messages
40
I am using custombuild 2.0 to compile PHP 7.0.1 with OpCache support.
This works except for one specific configuration which is the following:

Code:
cat custom/opcache/opcache.ini 
opcache.memory_consumption=32
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=3000
opcache.revalidate_freq=60
opcache.fast_shutdown=0
opcache.enable_cli=1
opcache.file_cache_only=1
opcache.file_cache=/tmp/.opcache/

Compiled PHP 7 with opcache and opcache-file support like this:
Code:
cat custom/fastcgi/configure.php70
#!/bin/sh
./configure \
...
        --enable-opcache \
        --enable-opcache-file \

Results:
Code:
tail -n 2 /var/log/httpd/error_log
Wed Jan  6 16:53:01 2016 (846663): Fatal Error opcache.file_cache_only is set without a proper setting of opcache.file_cache
Wed Jan  6 16:53:03 2016 (846686): Fatal Error opcache.file_cache_only is set without a proper setting of opcache.file_cache


If I change opcache.file_cache_only back to opcache.file_cache_only=0, it does not show the error.

PHP info Opcache parts shows:
Code:
Zend OPcache

Opcode Caching => Up and Running
Optimization => Enabled
SHM Cache => Enabled
File Cache => Enabled
Startup => OK
Shared memory model => mmap
Cache hits => 0
Cache misses => 0
Used memory => 18044896
Free memory => 15509536
Wasted memory => 0
Interned Strings Used memory => 157136
Interned Strings Free memory => 8231472
Cached scripts => 0
Cached keys => 0
Max keys => 3907
OOM restarts => 0
Hash keys restarts => 0
Manual restarts => 0

Directive => Local Value => Master Value
opcache.blacklist_filename => no value => no value
opcache.consistency_checks => 0 => 0
opcache.dups_fix => Off => Off
opcache.enable => On => On
opcache.enable_cli => On => On
opcache.enable_file_override => Off => Off
opcache.error_log => no value => no value
opcache.fast_shutdown => 0 => 0
opcache.file_cache => /tmp/.opcache/ => /tmp/.opcache/
opcache.file_cache_consistency_checks => 0 => 0
opcache.file_cache_only => 1 => 1


In the PHP source code, I see this:

PHP:
#ifdef HAVE_OPCACHE_FILE_CACHE
	} else if (!ZCG(accel_directives).file_cache) {
		accel_startup_ok = 0;
		zend_accel_error(ACCEL_LOG_FATAL, "opcache.file_cache_only is set without a proper setting of opcache.file_cache");
		return SUCCESS;
	}

So for some reason, this setting is set correctly according to phpinfo but not according to the log output.

Could someone try to replicate?
 
Changing opcache.file_cache=/tmp/.opcache/ to opcache.file_cache=/home/admin/public_html/.opcache actually solved the issue.
Which is strange as rights on /tmp/.opcache are 777 and changed to owner to admin:admin which also didn't solve it.

open_basedir /home/admin/:/tmp:/var/tmp:/usr/local/lib/php/:/usr/local/php70/lib/php/
 
I did it the normal way. Only had to change the configure file so it will compile it with opcache enabled.

Code:
cat custom/fastcgi/configure.php70
#!/bin/sh
./configure \
...
        --enable-opcache \
        --enable-opcache-file \
 
When I add opcache.file_cache=/home/admin/tmp/.opcache to opcache.ini, it only works for the webapps user. Only the webapps user get files added to /home/admin/tmp/.opcache - still trying to figure this out so it can work for all users. Please share if you know the solution.
 
Solved the problem by setting a per-user custom path /home/USER/.opcache
 
Last edited:
How?
in htaccess file ?

To get file cache for users I created /usr/local/directadmin/data/templates/custom/php-fpm.conf and added this line:

Code:
php_admin_value[opcache.file_cache] = |HOME|/.opcache

To get file cache for webapps I created this file: /usr/local/directadmin/custombuild/custom/opcache/opcache.ini and added this line:

Code:
opcache.file_cache=/var/www/tmp/.opcache

You also need to create the directory .opcache at /var/www/tmp/.opcache and create the directory /home/USER/.opcache for every user on your server (this can be automated on new user creation by adding code to /usr/local/directadmin/scripts/custom/user_create_post.sh)

Please note this is NOT a how to. You need to adjust your opcache.ini settings with many changes, and also everytime there is a new PHP version, you need to delete all the old opcache files in every users directory. Again, this is not a how to, a lot more adjustment should be made. You need to study that your self if you are going to use opcache with file cache in addition to regular cache in RAM.
 
Back
Top