PHP with APC: Fatal errors: Cannot redeclare class

后端 未结 7 1942
甜味超标
甜味超标 2020-12-24 07:57

Since I installed APC for PHP with PECL I get sometimes these errors: Cannot redeclare class xxx

xxx changes from time to time. I could disable APC but

相关标签:
7条回答
  • 2020-12-24 08:11

    I had the same problem with a bunch of PHP libraries as soon as I enabled APC. After a lot of hair pulling I found that setting apc.include_once_override = 0 cleared things up. Still monitoring but haven't had a the problem re-occur (before that I was able to induce the error by clearing the apc cache).

    0 讨论(0)
  • 2020-12-24 08:12

    I just had this happen to me, and I didn't find the solution suggested in any of the other answers. I am using various autoloaders including Composer autoloader and an older version of the Zend Framework Autoloader.

    The problem turned out to be caused by a slight name mismatch between the file name and the class name. One character different between the class name and the file name - a discrepancy that a human could easily miss but the a couple of autoloaders successively included the same file, causing the error.

    0 讨论(0)
  • 2020-12-24 08:14

    The combination of the following configs fixed it for me:

    apc.include_once_override = 0
    apc.canonicalize = 0
    apc.stat = 0
    

    Without all 3, I'd constantly get the error, but with all three I seem to no longer get the error :)!

    0 讨论(0)
  • 2020-12-24 08:18

    Download the latest apc version and use:

    [APC]
    apc.cache_by_default = 0
    

    With apc.stat = 0 the server loads the php files in cache, if you modify it, php still loads the same.

    More info:

    • https://bugs.php.net/bug.php?id=58878#1275406932
    • http://www.php.net/manual/en/apc.configuration.php
    0 讨论(0)
  • 2020-12-24 08:19

    This error happened when using Amazon's AWS SDK for PHP2 in a php script running under cron. One solution was to disable apc via -d apc.enabled=0 as shown below:

    /usr/bin/php -d apc.enabled=0 /path/to/myshelljob.php
    

    For more info.

    0 讨论(0)
  • 2020-12-24 08:24

    Hmmm, seems to be a common issue:

    • Opcode (APC/XCache), Zend, Doctrine, and Autoloaders
    • http://forums.zend.com/viewtopic.php?f=69&t=813
    • http://framework.zend.com/issues/browse/ZF-8588

    What I just noticed from your specific error message is that you wrote zend_db_adapter_abstract in all-lowercase. A problem with the horrid framework naming schemes and autoloaders is that they keep files in mixed case and expect it so. If your code tried to instantiate it this way, the autoloader might not have found it. APC might be more peculiar here, since it overrides include_once internally, maybe with side-effects.

    A solution would be to adapt the Zend autoloader, and manually keep a list of loaded classes and (absolute and lowercased) filenames to proofcheck in lieu of include_once.

    Otherwise, try excessive xdebug-ing. Without access to your setup, all we can do is guess here.

    0 讨论(0)
提交回复
热议问题