Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP with APC: Fatal errors: Cannot redeclare class

Tags:

php

apc

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 APC improves the performance great! Is there a known bug or could I do something else to prevent these errors? I'm using Ubuntu 8.04 LTS with PHP 5.2.4.


Edit/Update (from comments):

I use the Zend Framework Autoloader and these error never occurred before I enabled APC. A few moments ago I get for example that error: Fatal error: require(): Cannot redeclare class zend_db_adapter_abstract in /paths/app/lib/Zend/Db/Select.php on line 27

like image 955
Poru Avatar asked Jan 01 '11 19:01

Poru


3 Answers

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

like image 60
Peter Avatar answered Sep 21 '22 20:09

Peter


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

like image 42
Coalpaw Avatar answered Sep 20 '22 20:09

Coalpaw


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.

like image 45
Fred Lovine Avatar answered Sep 20 '22 20:09

Fred Lovine