Reputation: 17208
When Xdebug is loaded as a PHP module, it takes a heavy performance toll even when completely disabled. [1]
Is it possible to load Xdebug module without ANY performance overhead?
Considering, of course, that it HAS a performance overhead when it's actively debugging (through the presence of a debug cookie in HTTP requests, or, in CLI, through a series of -dxdebug
parameters to enable it) or while profiling.
I was investigating poor performance issues when running an integration test suite. It was taking 2 minutes to run the whole suite. I had disabled everything there was to disable on Xdebug, until I finally decided to completely remove the module itself from PHP. When I did that, the integration suite took 56 seconds to run. Almost twice as fast.
I started digging into it and saw that this is a common issue. Again [1] as a reference. These are the settings that I'm using:
xdebug.remote_autostart = Off
xdebug.default_enable = Off
xdebug.profiler_enable_trigger = Off
xdebug.remote_enable = Off
xdebug.remote_handler = dbgp
xdebug.remote_port = 9000
xdebug.idekey = PHPSTORM
xdebug.remote_log = /var/log/php/xdebug.log
And this is the PHP / Xdebug version:
PHP 7.4.2 (cli) (built: Feb 1 2020 19:47:36) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.2, Copyright (c), by Zend Technologies
with Xdebug v2.9.2, Copyright (c) 2002-2020, by Derick Rethans
I saw this difference in PHP CLI.
[1] Related:
Upvotes: 1
Views: 1350
Reputation: 17208
Okay, I got it, at least for PHP CLI.
This will disable Xdebug on web requests, but you will be able to run CLI commands with and without Xdebug. If you are writing many automated tests, it might be worth it.
First, disable Xdebug completely. Run php --version
to confirm you don't see a line like this "with Xdebug v2.9.2, Copyright (c) 2002-2020, by Derick Rethans".
Then, run php -i | grep ^extension_dir
to find out where your PHP extensions are stored. CD into that folder and check if you can find xdebug.so there.
Now, run php
with the parameter -dzend_extension=YOUR_XDEBUG.SO_PATH
to have Xdebug loaded. Example:
php --version
Gives:
PHP 7.4.2 (cli) (built: Feb 1 2020 19:47:36) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.2, Copyright (c), by Zend Technologies
php -dzend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so --version
Gives:
PHP 7.4.2 (cli) (built: Feb 1 2020 19:47:36) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.2, Copyright (c), by Zend Technologies
with Xdebug v2.9.2, Copyright (c) 2002-2020, by Derick Rethans
In my case, I have made it an bash alias, with a few more parameters for a more granular control:
alias phpx='PHP_IDE_CONFIG="serverName=someServerNameInPHPStorm" php -dzend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so -dxdebug.remote_autostart=1 -dxdebug.remote_enable=1 -dxdebug.default_enable=1 -dxdebug.remote_connect_back=1 -dxdebug.remote_handler=dbgp -dxdebug.remote_port=9000 -dxdebug.idekey=PHPSTORM -dxdebug.remote_host=127.0.0.1';
So I use it like: phpx run_something.php
to run with Xdebug, and php run_something.php
without, for optimal performance.
Thanks @LazyOne for the tip, and I hope Xdebug fixes this performance issue, because as I said, this workaround won't work for web requests.
Upvotes: 5