proper opcache configuration for CLI

144 views Asked by At

what is the proper opcache configuration when using PHP for CLI only?

I find very confusing/old resources and am not sure this is the proper conf:

[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.file_cache=/tmp/php-opcache

More specifically: the doc describe opcache.file_cache as a second level cache, SHM memory being the 1st level. But I can't find any recent resource indicating whether the SHM memory is shared across PHP's cli invocations depending on this, either opcache.file_cache isn't nescessary or opcache.file_cache_only is required.

Secondly, I'd like to determine the required management over the content of the directory that opcache.file_cache points to

  • it should be created beforehand with the proper rights
  • should it be emptied of old files manually?
  • ...
1

There are 1 answers

0
Bruno On

Thanks to @Chris Haas comments, I've got some informations, but don't consider this answer as comprehensive: there are a lot of unknown around using the opcache for CLI.

Properly enabling the opcache for CLI only require this conf:

[opcache]
opcache.enable_cli=1
opcache.file_cache=/tmp/php-opcache
opcache.file_cache_only=1

notes:

  • you must also configure another settings like opcache.validate_timestamps/opcache.revalidate_freq, but the choice will depend for example of your environment (dev/prod)
  • some php function won't work, like opcache_reset()/opcache_invalidate() this is counter intuitive, so be cautious!
  • some settings are probably ignored, like max_wasted_percentage (just to be clear: the doc don't state this, it's just an educated guess)
  • you will have to administrate the directory that opcache.file_cache point to:
  • it must exist, and be writable by the current user
  • you probably have to delete prune files older than X in this directory

interesting ressources:

Personally, I convinced my team to not enable this feature "opcache for CLI", because I think there a too much dark corners.