Composer and APC


After setting up a new working environment I usually run into the following error message as soon as I try to use Composer:

PHP Fatal error:  Cannot redeclare class Composer\Package\CompletePackageInterface in phar:///opt/local/bin/composer/src/Composer/Package/CompletePackageInterface.php on line 20

This message is a bit misleading, since the root cause is something very different: APC is enabled for the command line. Composer is (probably due to a bug in APC) not compatible if APC is enabled via the php.ini setting apc.enable_cli = 1. This is an issue which has been long discussed a year ago and still lacks a real solution.

Now, you might argue that APC for the command line does not offer any benefits. That is mostly true, at least in terms of speed gains. But, there is at least one valid reason for enabling APC for CLI which makes it a blocker in my case: I'd like to run functional tests which use APC functionality.

Instead of turning APC on and off all the time, I created a bash script in /opt/local/bin/ simply called composer which turns off APC before executing the original Composer Phar file:

#!/bin/sh
/opt/local/bin/php -d "apc.enable_cli=0" /opt/local/bin/composer.phar "$@"

That's it - now I can just use Composer globally by running "composer" and keep APC enabled for the command line, too.


Leave a reply