polidog lab++

Blog

composer使う時はapcを有効にしてはいけない

Dec 28, 2013 | tech | composer PHP

おはようございます。
年末年始の休暇に入ったので朝からのんびりプログラミングしている僕です。
さて、先ほど出会ったトラブルの一つをご紹介しようと思います。

最近cakephpを触ってないなーとか思った僕ですが、ACSの操作をcakeで出来たら面白いかなと思ったので、開発環境を準備していました。
composer.jsonはこんな感じです。

composer.json

{
    "repositories": [
        {
            "type": "pear",
            "url": "http://pear.cakephp.org"
        },
        {
            "type": "package",
            "package": {
                "name":"cakebaker/oauth-consumer",
                "version": "dev-master",
                "source": {
                    "url": "https://github.com/cakebaker/oauth-consumer",
                    "type": "git",
                    "reference": "origin/master"
                }
            }

        }
    ],
    "require": {
        "pear-cakephp/cakephp": ">=2.3.4",
        "cakedc/migrations": "dev-feature/migrations-from-cli",
        "cakebaker/oauth-consumer": "dev-master"
    },
    "require-dev": {
        "cakephp/debug_kit": "2.2.*"
    },
    "config": {
        "vendor-dir": "Vendor/"
    }
}

で、以下のようにインストールしてみたら。。。

$ composer install

PHP Fatal error:  Cannot redeclare class Composer\Repository\CompositeRepository in phar:///Users/polidog/bin/composer/src/Composer/Repository/CompositeRepository.php on line 22
PHP Stack trace:
PHP   1. {main}() /Users/polidog/bin/composer:0
PHP   2. require() /Users/polidog/bin/composer:15
PHP   3. Composer\Console\Application->run() phar:///Users/polidog/bin/composer/bin/composer:43
PHP   4. Symfony\Component\Console\Application->run() phar:///Users/polidog/bin/composer/src/Composer/Console/Application.php:83
PHP   5. Composer\Console\Application->doRun() phar:///Users/polidog/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:121
PHP   6. Symfony\Component\Console\Application->doRun() phar:///Users/polidog/bin/composer/src/Composer/Console/Application.php:117
PHP   7. Symfony\Component\Console\Application->doRunCommand() phar:///Users/polidog/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:191
PHP   8. Symfony\Component\Console\Command\Command->run() phar:///Users/polidog/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:897
PHP   9. Composer\Command\UpdateCommand->execute() phar:///Users/polidog/bin/composer/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:244
PHP  10. Composer\Installer->run() phar:///Users/polidog/bin/composer/src/Composer/Command/UpdateCommand.php:118
PHP  11. Composer\Installer->doInstall() phar:///Users/polidog/bin/composer/src/Composer/Installer.php:210
PHP  12. Composer\DependencyResolver\Pool->addRepository() phar:///Users/polidog/bin/composer/src/Composer/Installer.php:337
PHP  13. Composer\Repository\ArrayRepository->getPackages() phar:///Users/polidog/bin/composer/src/Composer/DependencyResolver/Pool.php:158
PHP  14. Composer\Repository\VcsRepository->initialize() phar:///Users/polidog/bin/composer/src/Composer/Repository/ArrayRepository.php:170
PHP  15. Composer\Repository\VcsRepository->getDriver() phar:///Users/polidog/bin/composer/src/Composer/Repository/VcsRepository.php:113
PHP  16. Composer\Autoload\ClassLoader->loadClass() phar:///Users/polidog/bin/composer/src/Composer/Repository/VcsRepository.php:0
PHP  17. include() phar:///Users/polidog/bin/composer/vendor/composer/ClassLoader.php:185
PHP  18. Composer\Autoload\ClassLoader->loadClass() phar:///Users/polidog/bin/composer/vendor/composer/ClassLoader.php:0
PHP  19. include() phar:///Users/polidog/bin/composer/vendor/composer/ClassLoader.php:185

Fatal error: Cannot redeclare class Composer\Repository\CompositeRepository in phar:///Users/polidog/bin/composer/src/Composer/Repository/CompositeRepository.php on line 22

Cannot redeclare classって…なんでだろう。。。
基本的にcomposerな訳だし、そんなこと言われても・・・って感じでしたが、よく考えたらapcがcliでも有効になってるからかなーとか思った訳です。
ということで以下のようにapcの設定を修正しました。

[apc]
extension="/usr/local/php54-apc/3.1.10/apc.so"
apc.enabled=1
apc.shm_segments=1
apc.shm_size=64M
apc.ttl=7200
apc.user_ttl=7200
apc.num_files_hint=1024
apc.mmap_file_mask=/tmp/apc.XXXXXX
apc.enable_cli=0 #ここを1から0に

これで再度composer installすればうまくいくはずです。

$ composer install
Loading composer repositories with package information
Initializing PEAR repository http://pear.cakephp.org
Installing dependencies (including require-dev)
  - Installing composer/installers (v1.0.8)
    Loading from cache

  - Installing cakedc/migrations (dev-feature/migrations-from-cli 14cdc86)
    Cloning 14cdc86b3d4d3ef83509db4e9e52fe400623925f

  - Installing cakebaker/oauth-consumer (dev-master origin/master)
    Cloning origin/master

  - Installing pear-pear.cakephp.org/cakephp (2.4.4)
    Loading from cache
  - Installing cakephp/debug_kit (2.2.2)
    Loading from cache

参考

https://github.com/composer/composer/issues/264

comments powered by Disqus

関連記事

© 2017 polidog lab++