Disabling xdebug when running composer

前端 未结 18 1145
北海茫月
北海茫月 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:30

    As noted in Joyce's answer, this issue no longer exists in the latest version of Composer.

    The Composer documentation has been updated to note this. It details how you can enable xdebug with Composer (if required).

    You can update your version of Composer by utilising self-update.

    On my Mac I had to do: sudo php /opt/local/bin/composer self-update

    Further details about this in the context of a Homebrew PHP install can be found in this issue.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-29 21:33

    My quick solution for a macports installation, with multiple versions of PHP was to write this simple shell wrapper for Composer:

    /user/local/bin/composer-nodebug.sh
    
    #!/bin/bash
    
    sudo mv /opt/local/var/db/php53/xdebug.ini /opt/local/var/db/php53/xdebug.NOT
    sudo mv /opt/local/var/db/php54/xdebug.ini /opt/local/var/db/php54/xdebug.NOT
    sudo mv /opt/local/var/db/php55/xdebug.ini /opt/local/var/db/php55/xdebug.NOT
    composer $1 $2 $3 $4 $5 $6 $7
    sudo mv /opt/local/var/db/php53/xdebug.NOT /opt/local/var/db/php53/xdebug.ini
    sudo mv /opt/local/var/db/php54/xdebug.NOT /opt/local/var/db/php54/xdebug.ini
    sudo mv /opt/local/var/db/php55/xdebug.NOT /opt/local/var/db/php55/xdebug.ini
    

    Then run any composer commands like so:

    sudo composer-nodebug.sh update
    

    Drawbacks:

    • requires sudo (unless you chmod the INI files)
    • if you kill it mid-way the INI files are modified
    • will require future PHP versions added.
    • while it's running other PHP processes are affected

    Not elegant, but simple.

    0 讨论(0)
  • 2021-01-29 21:34

    You can disable Xdebug setting an environment variable:

    XDEBUG_MODE=off composer install
    

    It's available using XDebug 3.

    0 讨论(0)
  • 2021-01-29 21:37

    I don’t think there is an option to configure PHP so it can load different configurations according to the targeted script. At least, not without duplicating .ini files...

    However, you can add thoses options when running composer with php:

    php -n -d extension=needed_ext.so composer.phar
    

    -n will tell PHP to ignore any php.ini. This will prevent xdebug from loading for this very command.

    -d options permits you to add any option you want (for exemple, activate needed_ext.so). You can use multiple -d options. Of course, this is optional, you might not need it.

    Then you can create an alias, to make it sugary again.

    A typical solution (because composer needs json):

    php -n -d extension=json.so composer.phar
    

    greg0ire > my solution, based on that:

    #!/bin/bash
    options=$(ls -1 /usr/lib64/php/modules| \
    
        grep --invert-match xdebug| \
    
        # remove problematic extensions
        egrep --invert-match 'mysql|wddx|pgsql'| \
    
        sed --expression 's/\(.*\)/ --define extension=\1/'| \
    
        # join everything together back in one big line
        tr --delete '\n'
    )
    
    # build the final command line
    php --no-php-ini $options ~/bin/composer $*
    
    alias composer=/path/to/bash/script.sh
    

    It looks ugly (I tried and failed to do that with xargs), but works… I had to disable some extensions though, otherwise I get the following warnings:

    PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mysqli.so' - /usr/lib64/php/modules/mysqli.so: undefined symbol: mysqlnd_connect in Unknown on line 0
    PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pdo_mysql.so' - /usr/lib64/php/modules/pdo_mysql.so: undefined symbol: pdo_parse_params in Unknown on line 0
    PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pdo_pgsql.so' - /usr/lib64/php/modules/pdo_pgsql.so: undefined symbol: pdo_parse_params in Unknown on line 0
    PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/wddx.so' - /usr/lib64/php/modules/wddx.so: undefined symbol: php_XML_SetUserData in Unknown on line 0
    
    0 讨论(0)
  • 2021-01-29 21:38

    I came up with an answer that works pretty well for OSX, and could probably be adapted for any PHP version that loads its extensions using individual .ini files in the "additional ini dir":

    #!/bin/sh
    
    function php-no-xdebug {
        local temporaryPath="$(mktemp -t php-no-debug)"
    
        find /opt/local/etc/$1/php.ini /opt/local/var/db/$1/*.ini ! -name xdebug.ini | xargs cat > "$temporaryPath"
        php -n -c "$temporaryPath" "${@:2}"
        rm -f "$temporaryPath"
    }
    
    alias composer="php-no-xdebug php56 ~/bin/composer"
    
    0 讨论(0)
提交回复
热议问题