Dominik Kukacka
Dominik Kukacka

Reputation: 567

Symfony2 "FatalErrorException: Compile Error: Cannot redeclare class" from time to time

today I got an very odd situation. I am implementing a simple 1:m relation between two entites in Doctrine Symfony2.

There are Users and Groups. Each User should be added to exactly one Group.

But every 3-4 reload my controller spits out an error.

FatalErrorException: Compile Error: Cannot redeclare class Proxies\__CG__\Creativebrains\AthleteBundle\Entity\Group in /var/www/symfony2/app/cache/dev/doctrine/orm/Proxies/__CG__CreativebrainsAthleteBundleEntityGroup.php line 8

And a reload later I get the normal JSON output

{
    id: 1,
    username: "dominik",
    email: "[email protected]",
    enabled: true,
    displayname: "Dominik",
    group: {
        name: "asd"
        ...
    }
}

I think it is some sort of caching error but I cannot understand why.

Hopefully some one knows an answer. Have a nice day!

Upvotes: 3

Views: 2822

Answers (1)

David Stone
David Stone

Reputation: 578

The problem is related to APC opcode cache. I've been experiencing it just as you described, it seems to happen most with multiple simultaneous requests. Disabling APC solves the problem but it's not ideal. You can disable it just for these generated proxies by adding this to your php.ini file:

apc.filters = '-.*__CG__.*'

This solved the problem for me. It was only ever an issue in the dev environment so it shouldn't be used on production.

Upvotes: 3

Related Questions