运行composer时禁用xdebug [英] Disabling xdebug when running composer
问题描述
运行 composer diagnose
时,会出现以下错误:
When running composer diagnose
, I get the following error :
xdebug扩展加载,这可以减慢Composer一点。推荐使用Composer时禁用它。
The xdebug extension is loaded, this can slow down Composer a little. Disabling it when using Composer is recommended.
我如何在运行Composer时禁用xdebug? p>
How can I disable xdebug only when I'm running Composer?
推荐答案
我不认为有一个配置PHP的选项,所以它可以根据目标脚本加载不同的配置。至少,不是没有重复的.ini文件...
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...
但是,当使用php运行composer时,可以添加those选项:
However, you can add thoses options when running composer with php:
php -n -d extension=needed_ext.so composer.phar
-n
会告诉PHP忽略任何php.ini。这将阻止xdebug加载这个命令。
-n
will tell PHP to ignore any php.ini. This will prevent xdebug from loading for this very command.
-d
选项允许您添加任何选项(例如,激活needed_ext.so)。您可以使用多个 -d
选项。当然,这是可选的,你可能不需要它。
-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.
一个典型的解决方案(因为composer需要json):
A typical solution (because composer needs json):
php -n -d extension=json.so composer.phar
greg0ire>我的解决方案,基于:
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
它看起来很丑陋(我试过,没有做到与xargs),但工作...我不得不禁用一些扩展,否则我得到以下警告:
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
这篇关于运行composer时禁用xdebug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!