PHP composer xdebug 警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33909559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP composer xdebug warning
提问by user275157
New to PHP. Working on a PHP project and have xdebug enabled to be able to debug my php applications. The production server does not have xdebug enabled because it is handled by another team. On my local machine, when I run composer it gives me a warning saying
PHP 新手。在 PHP 项目上工作并启用 xdebug 以便能够调试我的 php 应用程序。生产服务器没有启用 xdebug,因为它由另一个团队处理。在我的本地机器上,当我运行 composer 它给我一个警告说
You are running composer with xdebug enabled. This has a major impact on
runtime performance.
I do not want to disable xdebug when I am developing. Just wanted to confirm that running xdebug in dev environment should have no impacton the composer installing libraries/performance of the app on the production server.
我不想在开发时禁用 xdebug。只是想确认在开发环境中运行 xdebug 应该不会影响Composer 在生产服务器上安装应用程序的库/性能。
回答by Jens A. Koch
I do not want to disable xdebug when I am developing. Just wanted to confirm that running xdebug in dev environment should have no impacton the composer installing libraries/performance of the app on the production server.
我不想在开发时禁用 xdebug。只是想确认在开发环境中运行 xdebug 应该不会影响Composer 在生产服务器上安装应用程序的库/性能。
There is a huge impact of just loading Xdebug. It slows the Composer run down by 3x or 4x, even when the profiling feature is not enabled.
仅仅加载 Xdebug 就会产生巨大的影响。即使未启用分析功能,它也会使 Composer 运行速度降低 3 倍或 4 倍。
In other words: xdebug is invaluable for debugging, but increases the memory used and processing time of Composer.
换句话说:xdebug 对于调试来说是无价的,但会增加 Composer 的内存使用和处理时间。
How to disable Xdebug for Composer runs?
如何为 Composer 运行禁用 Xdebug?
My suggestion is to write a little invocation helper for running Composer.
我的建议是编写一个小的调用助手来运行 Composer。
The helper is a bash or batch script calling PHP with a custom php.ini
, especially configured for Composer. Lets call it: php.ini-composer
.
帮助程序是一个 bash 或批处理脚本,它使用自定义 调用 PHP php.ini
,特别是为 Composer 配置。让我们称之为:php.ini-composer
。
You could copy your current php.ini
and adjust it for the Composer run, by removing xdebug or commenting it out, like so: ;zend_extension = "/path/to/my/xdebug.so"
.
您可以复制当前的php.ini
调整它的作曲家来说,通过消除了XDebug或注释掉它,像这样:;zend_extension = "/path/to/my/xdebug.so"
。
While you are at it: setting memory_limit=-1
is helpful, too.
当你在做的时候:设置memory_limit=-1
也很有帮助。
The full command looks like so on Windows: php.exe -c php.ini-composer composer.phar %*
Windows 上的完整命令如下所示: php.exe -c php.ini-composer composer.phar %*
Just clone the idea for a bash script.
只需克隆 bash 脚本的想法。
And you may find the full answer to your question in the Composer FAQ.
您可以在 Composer 常见问题解答中找到您问题的完整答案。
https://getcomposer.org/doc/articles/troubleshooting.md#xdebug-impact-on-composer
https://getcomposer.org/doc/articles/troubleshooting.md#xdebug-impact-on-composer
It was added/updated just a few hours ago.
它是在几个小时前添加/更新的。
Some alternatives (instead of using seperate ini file) are also mentioned here.
回答by Revenant
Like with web scripts, expect CLI scripts to run slower as well.
与 Web 脚本一样,CLI 脚本的运行速度也会变慢。
If you need the added runtime performance, you can disable XDebug on CLI only. Set your PHP installation so that it uses different ini files for CLI and your server, as this answer suggests.
如果您需要增加运行时性能,则只能在 CLI 上禁用 XDebug。设置您的 PHP 安装,以便它为 CLI 和您的服务器使用不同的 ini 文件,正如这个答案所建议的那样。
回答by ojrask
Modern versions of Composer can work around having XDebug enabled by default for the CLI SAPI. It spawns a new PHP process with the XDebug extension disabled in case it is detected.
现代版本的 Composer 可以解决默认情况下为 CLI SAPI 启用 XDebug 的问题。它会生成一个新的 PHP 进程,并禁用 XDebug 扩展以防被检测到。
You can disable this behaviour by setting the following environment variable:
您可以通过设置以下环境变量来禁用此行为:
COMPOSER_ALLOW_XDEBUG=1
Found this in the documentation: https://getcomposer.org/doc/articles/troubleshooting.md#xdebug-impact-on-composer
在文档中找到了这个:https: //getcomposer.org/doc/articles/troubleshooting.md#xdebug-impact-on-composer
回答by iniravpatel
To fix this, prior to PHP 7 people would suggest to comment out the extension from your php.ini file. However, in PHP 7they are no longer in there.
为了解决这个问题,在 PHP 7 之前,人们会建议从你的 php.ini 文件中注释掉扩展名。但是,在PHP 7 中它们不再存在。
Instead, we use the phpdismod
command.
相反,我们使用phpdismod
命令。
sudo phpdismod -s cli xdebug
The -s flag tells it to disable Xdebug for the CLI SAPI (/etc/php/7.0/cli) and not FPM.
-s 标志告诉它禁用 CLI SAPI (/etc/php/7.0/cli) 的 Xdebug 而不是 FPM。
And just like that, the warning message should be gone. No need to restart PHP.
就这样,警告信息应该消失了。无需重新启动 PHP。
In addition to this, there is a pluginthat downloads packages in parallel to speed up the installation process.
除此之外,还有一个插件可以并行下载软件包以加快安装过程。
回答by PHPst
Create a file named php-composer.ini
somewhere with the following content (the minimum php config for composer):
创建一个名为php-composer.ini
某处的文件,内容如下(作曲家的最低 php 配置):
extension_dir = "D:/php/ext/" ;according to your system
extension=php_openssl.dll
memory_limit=-1 ;optional
Now create a file named cmz.bat
with the following contents. (edit paths accordingly)
现在创建一个以cmz.bat
以下内容命名的文件。(相应地编辑路径)
@ECHO OFF
php -c "D:\php-composer.ini" "C:\ProgramData\ComposerSetup\bin\composer.phar" %*
add this file to your system path or your project root.
Now use cmz
instead of composer
and you will not see that message and hopefully the composer speed would be increased.
将此文件添加到您的系统路径或项目根目录。现在使用cmz
代替,composer
您将不会看到该消息,希望作曲家的速度会提高。
note: Some package need specific php extensions. you need to add them to php-compsoer.ini
file or appending --ignore-platform-reqs
switch to cmz.bat
file
注意:有些包需要特定的 php 扩展。您需要将它们添加到php-compsoer.ini
文件或附加--ignore-platform-reqs
开关到cmz.bat
文件
回答by Dan Blows
On a fresh download of Symfony 3.1 and PHP 7.0, you can run the following (having edited it to include the path to your composer.phar file):
在新下载的 Symfony 3.1 和 PHP 7.0 上,您可以运行以下命令(编辑它以包含您的 composer.phar 文件的路径):
php -n -d extension=json.so -d extension=phar.so -d extension=pdo.so -d extension=ctype.so /path/to/composer update
If you have any extra vendors to your composer.json
file, you might find that they have a dependency on an extension, so you need to include that by adding -d extension=name_of_extension.so
to the list.
如果您的composer.json
文件中有任何额外的供应商,您可能会发现他们依赖于扩展名,因此您需要通过将其添加-d extension=name_of_extension.so
到列表中来包含它。
What's happening here is the -n
flag goes with PHP defaults - it doesn't load any ini
PHP config files, so XDebug is never loaded. Then each of the -d
flags allows you to dynamically set config values, so you can include extensions.
这里发生的事情是该-n
标志与 PHP 默认值一致 - 它不加载任何ini
PHP 配置文件,因此永远不会加载 XDebug。然后每个-d
标志都允许您动态设置配置值,因此您可以包含扩展。