2

I'm currently setting up a shared staging environment for one of our applications, written in PHP5.3 and using the Symfony2 framework.

If I only host a single instance of the application per server, everything works as it should.

However, if I then deploy additional instances of the application (which may or may not share the exact same code, dependent on client customisations), I get errors like this:

[Tue Nov 06 10:19:23 2012] [error] [client 127.0.0.1] PHP Warning:  require(/var/www/vhosts/application1/httpdocs/vendor/doctrine-common/lib/Doctrine/Common/Annotations/AnnotationRegistry.php): failed to open stream: Operation not permitted in /var/www/vhosts/application2/httpdocs/app/bootstrap.php.cache on line 1193
[Tue Nov 06 10:19:23 2012] [error] [client 127.0.0.1] PHP Fatal error:  require(): Failed opening required '/var/www/vhosts/application1/httpdocs/app/../vendor/doctrine-common/lib/Doctrine/Common/Annotations/AnnotationRegistry.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/vhosts/application2/httpdocs/app/bootstrap.php.cache on line 1193

Basically, the second site is trying to require the files from the first site, but due to open_basedir restrictions it can't do that. I'm not willing to disable open_basedir as that is only masking the problem instead of solving it, and creates a dependency between applications that should not be present.

I initially believed this was related to a Symfony2 error, but I've now tracked it down to an issue with APC; disabling APC also solves the error, but I'm concerned about the performance impact of doing so.

Does anyone have any suggestions on what I might be able to do?

Steve Hill
  • 141
  • 4

1 Answers1

1

Ok, this turned out to be a problem with our own code, rather than anything specifically wrong with either APC or Symfony2.

For the reference of anyone else who might run across this one:

  1. We were using the ApcUniversalClassLoader component from Symfony2.

  2. That allows you to specify a prefix for your cache files.

  3. This prefix was the same across each instance of our application; which is why it worked fine so long as there was only one instance per server.

  4. Because the prefix was the same, APC attempted to load the classes belonging to the first instance of the application which had been accessed immediately after the server had been restarted.

  5. Changing the prefix to be different per-instance of the application makes this behave correctly, loading the classes from the correct folders.

Hopefully, this will prevent anyone else from banging their head off the desk when they realise why it's not working :)

Steve Hill
  • 141
  • 4
  • Run into the exact same problem. Thanks very much for pointing me to a working solution. – cb0 Feb 21 '14 at 14:24