Disabling xdebug when running composer

前端 未结 18 1196
北海茫月
北海茫月 2021-01-29 21:18

When running composer diagnose, I get the following error :

The xdebug extension is loaded, this can slow down Composer a little. Disablin

18条回答
  •  抹茶落季
    2021-01-29 21:32

    Direct manipulation of PHP config

    Here's my contribution based on a Homebrew-installed PHP installation on Mac OS X.

    It's a shell-script wrapper, designed to be saved as an executable file at /usr/local/bin/composer, with the Composer binary at /usr/local/bin/composer.phar:

    #!/bin/sh
    sed -i '' -e 's:zend_extension="/usr/local/opt/php55-xdebug/xdebug.so":;zend_extension="/usr/local/opt/php55-xdebug/xdebug.so":' /usr/local/etc/php/5.5/conf.d/ext-xdebug.ini
    /usr/local/bin/php /usr/local/bin/composer.phar "$@"
    sed -i '' -e 's:;zend_extension="/usr/local/opt/php55-xdebug/xdebug.so":zend_extension="/usr/local/opt/php55-xdebug/xdebug.so":' /usr/local/etc/php/5.5/conf.d/ext-xdebug.ini
    

    Theory of Operation

    The wrapper script:

    • uses sed to temporarily modify the configuration file, disabling Xdebug (line 2)
    • executes Composer, passing through args to the command (line 3)
    • uses sed to restore the configuration file, re-enabling Xdebug (line 4)

    The script is coupled to an OS X/Homebrew installation of PHP 5.5. The paths should be adjusted to work with other PHP versions and other operating systems' and package managers' directory layouts. Note also that some versions of sed do not need the empty-string argument following the -i option.

    Caveat Utilitor

    The script is straightforward, in that it works directly on the main PHP configuration files, however this is also a drawback: Xdebug will also be disabled for any scripts that happen to be executed concurrently with this script.

    In my development environment, this is an acceptable trade-off, given that Composer is executed manually and only occasionally; however you may not want to use this technique if executing Composer as part of an automated deployment process.

提交回复
热议问题