PHP with APC: Fatal errors: Cannot redeclare class

陌路散爱 提交于 2019-11-29 23:34:51

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 :)!

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).

Fred Lovine

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.

mario

Hmmm, seems to be a common issue:

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.

Well it is a known problem with apc that it mixes up include_once directivse that are called relatively from different locations.

So if you do include_once myclass.php and then in a subdirectory do include_once ../myclass.php apc could mix this up and think its different files and loads it twice.

However this is fixed in later versions.

If you can drill down your code to the class that is loaded twice you could do some checking if the class is already loaded with class_defined or some callable stuff.

You can also use the apc.filter directive to prevent certain files from beeing cached at all.

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:

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!