如何禁用 XDebug
我认为自从安装了 XDebug 以来我的服务器变得很慢。 因此,为了检验我的假设,我想完全禁用 XDebug。 我一直在寻找有关如何执行此操作的教程,但找不到此类信息。
I think that my server became slow since I installed XDebug.
So, in order to test my hypothesis I want to disable XDebug completely.
I've been searching for tutorials on how to do this but I can't find such information.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(28)
找到您的
php.ini
并查找 XDebug。将 xdebug autostart 设置为 false
禁用分析器
请注意,可能会有 即使禁用 xdebug 也会造成性能损失,但已加载。要禁用扩展本身的加载,您需要在 php.ini 中对其进行注释。找到一个如下所示的条目:
并添加
;
对其进行注释,例如;zend_extension = ...
。查看这篇文章 XDebug,如何禁用远程调试单个 .php 文件?
提示:此答案适用于 xdebug 2。请务必检查 xdebug 3 答案
Find your
php.ini
and look for XDebug.Set xdebug autostart to false
Disable your profiler
Note that there can be a performance loss even with xdebug disabled but loaded. To disable loading of the extension itself, you need to comment it in your php.ini. Find an entry looking like this:
and put a
;
to comment it, e.g.;zend_extension = …
.Check out this post XDebug, how to disable remote debugging for single .php file?
HINT: This answer is for xdebug 2. Make sure to check for xdebug 3 answers
一个在类似于 Ubuntu 的 Linux 发行版上运行的简单解决方案
An easy solution working on Linux distributions similar to Ubuntu
在带有 PHP 5 的 Linux Ubuntu(也许还有另一个 - 尚未测试)发行版中,您可以使用:
以及 PHP 7 >=
之后,请重新启动服务器:
In Linux Ubuntu(maybe also another - it's not tested) distribution with PHP 5 on board, you can use:
And with PHP 7 >=
And after that, please restart the server:
此外,您还可以将
xdebug_disable()
添加到您的代码中。尝试:<代码>
if(function_exists('xdebug_disable')) { xdebug_disable(); }
Also, you can add
xdebug_disable()
to your code. Try:if(function_exists('xdebug_disable')) { xdebug_disable(); }
自从 xdebug 3 发布以来,
pnp.ini
中的设置略有变化。设置:
将禁用所有 处理 根据文档:
Since xdebug 3 came out the settings in
pnp.ini
have slightly changed.Setting:
Will disable all processing According to the docs:
我重命名了配置文件并重新启动了服务器:
它确实对我有用。
I renamed the config file and restarted server:
It did work for me.
在 php.ini 中注释扩展并重新启动 Apache。这是一个简单的脚本(您可以为其指定快捷方式)
xdebug-toggle.php
Comment extension in php.ini and restart Apache. Here is a simple script (you can assign shortcut to it)
xdebug-toggle.php
如果您使用 php-fpm ,以下内容应该足够了:
注意,您需要根据您的 php 版本进行调整。例如运行 php 7.0 你会这样做:
因为你正在运行 php-fpm ,所以不需要重新启动实际的网络服务器。在任何情况下,如果您不使用 fpm,那么您可以简单地使用以下任何命令重新启动您的网络服务器:
If you are using
php-fpm
the following should be sufficient:Notice, that you will need to tweak this depending on your php version. For instance running php 7.0 you would do:
Since, you are running php-fpm there should be no need to restart the actual webserver. In any case if you don't use fpm then you could simply restart your webserver using any of the below commands:
在 xubuntu 中,我完全禁用了 CLI 的 xdebug...
in xubuntu I totally disabled xdebug for the CLI with this...
在 Windows (WAMP) 上,CLI ini 文件中:
X:\wamp\bin\php\php5.x.xx\php.ini
注释行
Apache 将处理
xdebug
,并且作曲家不会。On Windows (WAMP) in CLI ini file:
X:\wamp\bin\php\php5.x.xx\php.ini
comment line
Apache will process
xdebug
, and composer will not.您可以在运行时使用
-d
标志在 PHP CLI 上禁用 Xdebug:php -d xdebug.mode=off -i | grep xdebug.mode
结果:
xdebug.mode =>关=> off
例如,在禁用 Xdebug 的情况下运行单元测试,因此速度更快:
php -d xdebug.mode=off ./vendor/bin/phpunit
您还可以为其创建一个别名,以便使用起来更方便。
You can disable Xdebug on PHP CLI on runtime using the
-d
flag:php -d xdebug.mode=off -i | grep xdebug.mode
Result:
xdebug.mode => off => off
Example, running unit tests with Xdebug disabled, so it's faster:
php -d xdebug.mode=off ./vendor/bin/phpunit
You can also create an alias for it to make it easier to use.
Ubuntu 16.04 从 PHP 中删除了 xdebug。
找到您的 php.ini 文件并确保 xdebug 存在:
这可能会出现不同的版本,如果是这样,请运行 php -v 来查找您的版本。
编辑 php.ini 文件,例如:
注释行:
保存文件
Ubuntu 16.04 remove xdebug from PHP.
Find your php.ini file and make sure xdebug is there:
This might come up with different versions, if so run
php -v
to find your version.Edit the php.ini file, like:
Comment the line:
Save the file
受到 PHPStorm 的启发,右键单击文件 ->调试-> ...
重要的是
-dxdebug.remote_enable=0 -dxdebug.default_enable=0
Inspired by PHPStorm right click on a file -> debug -> ...
the important stuff is
-dxdebug.remote_enable=0 -dxdebug.default_enable=0
两个选项:
1:在初始化脚本中添加以下代码:
2:将以下标志添加到 php.ini
推荐第一个选项。
Two options:
1: Add following code in the initialization Script:
2: Add following flag to php.ini
1st option is recommended.
找到 PHP.ini 并查找 XDebug。
通常在 Ubuntu 中,它的路径是
进行以下更改(最好通过在开头添加 ; 来注释它们),
然后重新启动服务器
再次针对 Ubuntu
Find your PHP.ini and look for XDebug.
normally in Ubuntu its path is
Make following changes (Better to just comment them by adding ; at the beginning )
then restart your server
again for Ubuntu
禁用 xdebug
对于 PHP 7:
sudo nano /etc/php/7.0/cli/conf.d/20-xdebug.ini
对于 PHP 5:
sudo nano / etc/php5/cli/conf.d/20-xdebug.ini
然后注释掉所有内容并保存。
更新——仅对 CLI 禁用
根据 @igoemon 的评论,这是一个更好的方法:
PHP 7.0 (NGINX)
注意:更新 PHP 版本的路径。
Disable xdebug
For PHP 7:
sudo nano /etc/php/7.0/cli/conf.d/20-xdebug.ini
For PHP 5:
sudo nano /etc/php5/cli/conf.d/20-xdebug.ini
Then comment out everything and save.
UPDATE -- Disable for CLI only
As per @igoemon's comment, this is a better method:
PHP 7.0 (NGINX)
Note: Update the path to your version of PHP.
我创建了这个 bash 脚本来切换 xdebug。我认为它至少应该在 Ubuntu / Debian 上工作。这是针对 PHP7+ 的。对于 PHP5,请使用 php5dismod / php5enmod。
I created this bash script for toggling xdebug. I think it should work at least on Ubuntu / Debian. This is for PHP7+. For PHP5 use php5dismod / php5enmod.
我遇到了类似的问题。有时,您在 php.ini 中找不到 xdebug.so。在这种情况下,请在 php 文件中执行
phpinfo()
并检查已解析的其他 .ini 文件
。在这里您将看到更多 ini 文件。其中之一是 xdebug 的 ini 文件。只要删除(或重命名)这个文件,重新启动apache,这个扩展名就会被删除。I ran into a similar issue. Sometimes, you wont find xdebug.so in php.ini. In which case, execute
phpinfo()
in a php file and check forAdditional .ini files parsed
. Here you'll see more ini files. One of these will be xdebug's ini file. Just remove (or rename) this file, restart apache, and this extension will be removed.我有以下问题:
即使我设置了
Xdebug-Error-Message-Decoration 也会显示。
我的解决方案:
只有当我使用这个标志时,Xdebug 才会被禁用。
I had following Problem:
Even if I set
Xdebug-Error-Message-Decoration was shown.
My solution:
Only if I use this Flag, Xdebug was disabled.
(适用于 CentOS)
重命名配置文件并重新启动 apache。
执行相反的操作即可重新启用。
(This is for CentOS)
Rename the config file and restart apache.
Do the reverse to re-enable.
对于 WAMP,请左键单击任务栏托盘中的 Wamp 图标。将鼠标悬停在 PHP 上,然后单击 php.ini 并在文本编辑器中打开它。
现在,搜索短语“zend_extension”并添加 ; (分号)在它前面。
重新启动 WAMP,一切顺利。
For WAMP, click left click on the Wamp icon in the taskbar tray. Hover over PHP and then click on php.ini and open it in your texteditor.
Now, search for the phrase 'zend_extension' and add ; (semicolon) in front it.
Restart the WAMP and you are good to go.
仅对某些 PHP 版本或 sapi 禁用 xdebug。
在本例中 PHP 7.2 fpm
Disable xdebug only for certain PHP version or sapi.
On this case PHP 7.2 fpm
如果您在 Mac OS X 上使用 MAMP Pro,则可以通过 MAMP 客户端取消选中 PHP 选项卡下的激活 Xdebug 来完成:
If you are using MAMP Pro on Mac OS X it's done via the MAMP client by unchecking Activate Xdebug under the PHP tab:
所以,是的,您需要的一切,只需在 INI 文件中注释行,如 zend_extension=xdebug.so 或类似的。
可以通过添加分号进行注释。
但是,这样的答案已经添加了,我想分享现成的解决方案来切换 Xdebug 状态。
我为 Xdebug 制作了快速切换器。也许这对某人有用。
Xdebug 切换器
So, yeah, all what you need, just comment line in INI file like
zend_extension=xdebug.so
or similar.Comments can be made by adding semicolon.
But, such kind of answer already added, and I'd like to share ready solution to switch Xdebug status.
I've made quick switcher for Xdebug. Maybe it would be useful for someone.
Xdebug Switcher
Apache/2.4.33 (Win64) PHP/7.2.4 myHomeBrew 堆栈
在 php.ini 末尾,我使用以下内容来管理 Xdebug 以与 PhpStorm 一起使用
Apache/2.4.33 (Win64) PHP/7.2.4 myHomeBrew stack
At end of php.ini I use the following to manage Xdebug for use with PhpStorm
对于那些有兴趣在 codeship 中禁用它的人,请在运行测试之前运行此脚本:
我收到此错误:
现在已经消失了!
For those interested in disabling it in codeship, run this script before running tests:
I was receiving this error:
which is now gone!
在 CLI 中:
禁用 xdebug
启用 xdebug
并重新启动服务器
In CLI:
disable xdebug
enable xdebug
And restart the server
就我而言,我想制作一个 php 实用程序脚本,该脚本不会受到任何 xdebug 设置甚至已安装的 xdebug 版本的影响(特别是在处理遗留代码时)。
我想在 Linux shell 会话上始终禁用 xdebug 来运行。
因此,我的方法是将 php 脚本包装在一些 bash 代码中:
整个想法是以某种方式将代码存储到变量中,并使用管道在完全禁用 xdebug 的情况下执行它。如果满足以下条件,这是一种有用的方法:
可以使用此方法的示例如下:
https://github.com/pc-magas/docker_php_dev/blob/ master/utils/get_xdebug_ip
这个脚本我检测xdebug监听的ip。为此,我想使用一些 php 代码以避免安装额外的依赖项。我还希望代码运行时不会受到 xdebug 的影响。
因此,对我来说,使用 bash 的独立解决方案似乎是一个好方法。
In my case I wanted to make a php utility script that won't be affected by any xdebug settings or even the installed xdebug version (expecially when dealing with legacy code).
I wanted to ALWAYS run with xdebug disabled upon Linux shell sessions.
Therefore, my approach was to wrap the php script around some bash code:
The whole idea is to somehow store the code into a variable and use pipe to execute it with xdebug completely disabled. This is a usefull approach if:
A exaple where this approach can be used is in:
https://github.com/pc-magas/docker_php_dev/blob/master/utils/get_xdebug_ip
This script I detect the ip where xdebug listens to. For that I wanted to use some php code in order to avoid installing extra dependencies. Also I wanted the code to run without being affected via xdebug.
Therefore, using a self-contained solution using bash seemed a good approach 2 me.