1
votes

When to fold PROD cache on the server get the error Doctrine Proxy, while on the local host, all performed without error. Reset DEV cache on both hosts also successfully reset.

"require": {
    "php": ">=5.3.3",
    "symfony/symfony": "v2.7.3",
    "doctrine/orm": "v2.5.0",
    "doctrine/doctrine-bundle": "v1.5.1",
    "twig/extensions": "v1.3.0",
    "symfony/assetic-bundle": "v2.3.1",
    "symfony/swiftmailer-bundle": "v2.3.8",
    "symfony/monolog-bundle": "v2.7.1",
    "sensio/distribution-bundle": "v3.0.30",
    "sensio/framework-extra-bundle": "v3.0.10",
    "incenteev/composer-parameter-handler": "v2.1.1",
    "friendsofsymfony/user-bundle": "v2.0.0-alpha3",
    "knplabs/knp-paginator-bundle": "2.5.0",
    "gregwar/image-bundle": "v2.0.21",
    "sensio/buzz-bundle": "v1.0.0",
    "whiteoctober/breadcrumbs-bundle": "1.2.0",
    "sonata-project/admin-bundle": "2.3.3",
    "sonata-project/doctrine-orm-admin-bundle": "2.3.2",
    "sonata-project/translation-bundle": "1.0.0",
    "sonata-project/doctrine-extensions": "1.0.2",
    "iphp/filestore-bundle" : "v0.2.5",
    "sonata-project/intl-bundle": "2.2.2",
    "oro/doctrine-extensions": "1.0.8",
    "devcookies/signgen": "^1.0",
    "gedmo/doctrine-extensions": "^2.4"
},

My observations №1

Run the console command for clearing PROD cache:

sudo php app/console cache:clear -e prod

get error

PHP Warning: require(/var/www/site.com/www/app/cache/pro_/doctrine/orm/Proxies/__CG__AppMerchantBundleEntityProject.php): failed to open stream: No such file or directory in /var/www/site.com/www/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php on line 209 PHP Fatal error: require(): Failed opening required '/var/www/site.com/www/app/cache/pro_/doctrine/orm/Proxies/__CG__AppMerchantBundleEntityProject.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/site.com/www/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php on line 209 [2016-01-29 10:30:55] php.CRITICAL: Fatal Compile Error: require(): Failed opening required '/var/www/site.com/www/app/cache/pro_/doctrine/orm/Proxies/__CG__AppMerchantBundleEntityProject.php' (include_path='.:/usr/share/php:/usr/share/pear') {"type":64,"file":"/var/www/site.com/www/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php","line":209,"level":6143,"stack":[]} {"request_ip":"unavailable","client_ip":"unavailable"} PHP Fatal error: Uncaught exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Compile Error: require(): Failed opening required '/var/www/site.com/www/app/cache/pro_/doctrine/orm/Proxies/__CG__AppMerchantBundleEntityProject.php' (include_path='.:/usr/share/php:/usr/share/pear')' in /var/www/site.com/www/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php:209 Stack trace:

0 {main} thrown in /var/www/site.com/www/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php

on line 209

Run the console command for clearing DEV cache:

sudo php app/console cache:clear -e dev

It's all right, and no errors


My observations №2

When in the configuration file, change the setting Doctrine

doctrine:
dbal:
    driver:   "%database_driver%"
    host:     "%database_host%"
    port:     "%database_port%"
    dbname:   "%database_name%"
    user:     "%database_user%"
    password: "%database_password%"
    charset:  UTF8
    types:
        json: Sonata\Doctrine\Types\JsonType
    mapping_types:
        enum: string
orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    ...

Changed config:

doctrine:
dbal:
    driver:   "%database_driver%"
    host:     "%database_host%"
    port:     "%database_port%"
    dbname:   "%database_name%"
    user:     "%database_user%"
    password: "%database_password%"
    charset:  UTF8
    types:
        json: Sonata\Doctrine\Types\JsonType
    mapping_types:
        enum: string
orm:
    auto_generate_proxy_classes: true
    ...

PROD cache is flushed without an error


My observations №3

The recent amendments of code that actually all broken and added two related entities:

Project entity

<?php

namespace App\MerchantBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use App\CoreBundle\Entity\Cashbox;
use App\PaymentBundle\Entity\Cash\Template;
use App\MerchantBundle\Entity\Project\Terminal;

/**
 * Project
 *
 * @ORM\Table(name="merchant_projects", uniqueConstraints={@ORM\UniqueConstraint(name="id_UNIQUE", columns={"id"}), @ORM\UniqueConstraint(name="secret_key_UNIQUE", columns={"secret_key"}), @ORM\UniqueConstraint(name="merchant_id_UNIQUE", columns={"merchant_id"})})
 * @ORM\Entity
 */
class Project
{

    ...

    /**
     * @ORM\OneToMany(targetEntity="\App\MerchantBundle\Entity\Project\Domain", mappedBy="project")
     */
    private $domains;
    ...

And Domain entity

<?php

namespace App\MerchantBundle\Entity\Project;

use Doctrine\ORM\Mapping as ORM;

/**
 * Domain
 *
 * @ORM\Table(name="merchant_project_domains")
 * @ORM\Entity
 */
class Domain
{
    ...

    /**
     * @var \App\MerchantBundle\Entity\Project
     *
     * @ORM\ManyToOne(targetEntity="\App\MerchantBundle\Entity\Project", inversedBy="domains")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="project_id", referencedColumnName="id")
     * })
     */
    private $project;

If you remove a connection Domain entity

    /**
     * @var \App\MerchantBundle\Entity\Project
     */
    private $project;

It's all right, and no errors

4

4 Answers

1
votes

Did you try force remove cache by

rm -rf app/cache/*

and then (of course db dump it will be nice)

php app/console doctrine:schema:update --force
1
votes

The cause was found.

For dynamic conditions for route, I get a list of allowed domains from the database. To do this, I use CompilerPassInterface. And if there are entries in the table I am getting the error, and if the table to clear the cache was successfully cleared.

I expect that the data from the database tries to cache before the cache time to creators and project entities

Screen of my CompilerPass class

Please tell me how to store the settings in the database and then use them in a mustache for route?

0
votes

I found following sequence of commands to work:

chmod -R 777 ./app/cache 
rm -rf app/cache/*
php app/console cache:clear --env=prod  --no-warmup --no-debug
php app/console cache:warmup --env=prod --no-debug
chmod -R 777 ./app/cache
php app/console doctrine:generate:entities yourBundleName --no-backup
php app/console doctrine:schema:update --force

Also if you use apache, you should set the correct owner to cache folder:

sudo chown -R apache:apache app/cache
0
votes

You clear the cache on DEV enviroment which will also create the Doctrine proxies classes for you:

bin/console cache:clear --env=dev

However, while on PROD enviroment one have to warm-up the cache instead of cleaning it, which would translate in the following command:

bin/console cache:warmup --env=prod --no-debug

The other comments the other users made above regarding the ./var permissions are obvious and common-sense, if you want your web server (Apache/Nginx/whatever) to be able to access the cached/logs files. So make sure you always run the below commands if you use to clean/warm-up the cache interactively in terminal (see the note below):

sudo chown -R <your-local-user>:<your-webserver-user> var/
sudo chmod -R 0770 var/

where:

  • <your-local-user> is the owner of the files (like your Linux username)
  • <your-webserver-user> is the usergroup that can access the files (eg. apache/httpd/www-data, whatever)

Note: if you are cleaning/warming-up the cache via a web request/action - yes, it's possible! - then the above chown/chmod should not be necessary since these folders/files will be created using the running instance (webserver) owner:group.