Disabling xdebug when running composer

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

提交回复
热议问题