28

I'm try to move symfony to shared host.

I moved symfony structure to / and my web folder is /public_html.

Warning: require(/home/user/app/cache/prod/doctrine/orm/Proxies/__CG__UserBundleEntityUser.php): failed to open stream: No such file or directory in /home/user/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php on line 209

Warning: require(/home/user/app/cache/prod/doctrine/orm/Proxies/__CG__UserBundleEntityUser.php): failed to open stream: No such file or directory in /home/user/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php on line 209

Fatal error: require(): Failed opening required '/home/user/app/cache/prod/doctrine/orm/Proxies/__CG__UserBundleEntityUser.php' (include_path='.:/opt/php55/lib/php') in /home/user/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php on line 209

This error occurs only in the prod environment. The exception is not thrown in the dev environment.

I tried the following:

rm -rf /app/cache + chmod 777
app/console cache:warmup

I use Symfony 2.8.3. The following directories are present locally and on the server:

LOCAL CACHE: - /annotations, /twig, /vich_uploader + /doctrine, /translations

SERVER CACHE: - /annotations, /twig, /vich_uploader

If I upload my local cache to the server, the exception disappears.

Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130
Luiz Brz Developer
  • 428
  • 1
  • 4
  • 14

3 Answers3

82

You did not create the proxy classes before you tried to access your application. This is usually done by:

app/console cache:warmup --env=prod

The auto-generation of proxy-classes is disabled by default in the prod environment. You can enable automatic generation of proxy-classes similar to the dev environment by adding this to your config:

app/config/config_prod.yml

doctrine:
    orm:
        auto_generate_proxy_classes:  true # <- change to true
        proxy_dir:            '%kernel.cache_dir%/doctrine/orm/Proxies'
        proxy_namespace:      Proxies
tchap
  • 3,412
  • 3
  • 29
  • 46
Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130
  • **This solved the problem.** Before my config have only this auto_generate_proxy_classes: "%kernel.debug%". **Thanks** – Luiz Brz Developer Mar 28 '16 at 12:46
  • There's a typo on the first line, it's `doctrine:` :) – Gravis Jun 22 '16 at 00:31
  • 1
    "The auto-generation of proxy-classes is disabled by default in the prod environment" why is that? should i let it enabled forever or disabled it again? – Kakashi Nov 15 '16 at 17:05
  • In my case, I didn't manage to warn my cache using the command, but setting it to auto did actually work (dooh ?). – Balmipour Mar 20 '17 at 13:58
  • 4
    If auto_generate_proxy_classes is on, it will generate the proxy files on each request! You want that in development so you have not to do this manually each time you change something. You don't want this in production because it will kill your server at a certain amount of requests (which happened to a product I worked on at around 1k requests per second ;) – Mischa Jul 16 '20 at 21:00
  • @Mischa but without this setting turned on it won't create Proxy in general. What would you suggest instead? – itinance Oct 12 '21 at 12:34
  • 1
    @itinance I suggest to read this [Doctrine Cookbook for advanced configuration](https://www.doctrine-project.org/projects/doctrine-orm/en/2.9/reference/advanced-configuration.html#development-vs-production-configuration), as it explains it in detail much better then I could :) – Mischa Oct 14 '21 at 14:31
1

/app/config/doctrine.yml

Change from:

  orm:
    auto_generate_proxy_classes: "%kernel.debug%"

To:

  orm:
    auto_generate_proxy_classes: true

Works!

-1

I have changed all files that refer to the expression 'auto_generate_proxy_classes' (I've changed the value from 'false' to 'true') and this fixed the issue:

  1. ... /vendor/doctrine/doctrine-bundle/DoctrineBundle.php
  2. ... /vendor/doctrine/doctrine-bundle/Resources/doc/configuration.rst
  3. ... /vendor/doctrine/doctrine-bundle/DependencyInjection/Configuration.php
  4. ... /vendor/doctrine/doctrine-bundle/DependencyInjection/DoctrineExtension.php
  5. ... /app/config/config.php
  6. ... /app/cache/prod/appProdProjectContainer.php
ZF007
  • 3,708
  • 8
  • 29
  • 48