PHP FPM 5.5 - Does Opcache run Per Domain

2.6k Views Asked by At

I have PHP FPM 5.5 running with Opcache - below are my Opcache settings (very standard):

; Opcache Configuration
opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=50000
opcache.fast_shutdown=1
opcache.revalidate_freq=120

Under PHP FPM I have a number of different domains running that have different pools using dynamic to start a min/max etc number of processes - this is running fine.

I wanted to ask: does opcache run per domain like APC?

Its been hard to find any information on the per domain factor of Opcache.

thankyou

1

There are 1 best solutions below

0
On

If you want to use OpCache per domain (VirtualHost) you have to create php-wrapper for every domain and set PHPRC variable with different directory to php.ini.

Two wrappers for two VirtualHosts:

foo wrapper - /var/www/foo/cgi-bin/php5-wrapper:

#!/bin/sh
PHPRC=/etc/php5/foo/
export PHPRC
#export PHP_FCGI_MAX_REQUESTS=5000
#export PHP_FCGI_CHILDREN=8
exec /usr/lib/cgi-bin/php

and create /etc/php5/foo/php.ini file

bar wrapper - /var/www/bar/cgi-bin/php5-wrapper:

#!/bin/sh
PHPRC=/etc/php5/bar/
export PHPRC
#export PHP_FCGI_MAX_REQUESTS=5000
#export PHP_FCGI_CHILDREN=8
exec /usr/lib/cgi-bin/php

and create /etc/php5/bar/php.ini file

You can simply test it.

  1. Download this app: https://github.com/PeeHaa/OpCacheGUI
  2. Set two VirtualHosts for OpCacheGUI: foo.opcache (with foo wrapper) and bar.opcache (with bar wrapper)
  3. Set two VirtualHosts for test application: foo.app (with foo wrapper) and bar.app (with bar wrapper). Use two different apps or the same app but different dirs.
  4. Do some request on foo.app and bar.app.
  5. Check "Cached scripts" tab in OpCacheGUI in foo.opcache and bar.opcache.

It's working for php-fcgid.