lando / lando

A development tool for all your projects that is fast, easy, powerful and liberating
https://lando.dev
GNU General Public License v3.0
4.08k stars 543 forks source link

The xdebug config option doesn't work "right" #760

Closed fchris82 closed 5 years ago

fchris82 commented 6 years ago

We have a complex project which can became very slow when the xdebug is loaded. Currently the developers can switch ON or OFF the xdebug in the docer-compose.yml:

# docker-compose.yml
services:
    # [...]
    app:
        # [...]
        environment:
            PHP_IDE_CONFIG: "serverName=Docker"
            XDEBUG_ENABLED: 0

And we have an entrypoint.sh file with this part:

        if [[ $XDEBUG_ENABLED != 1 ]]; then
            # Disable xdebug
            XDEBUG_INI_BASE=`php --ini | grep -oh ".*xdebug.ini"`
            XDEBUG_INI=$([ -h ${XDEBUG_INI_BASE} ] && readlink ${XDEBUG_INI_BASE} || echo ${XDEBUG_INI_BASE})
            # We add a ';' comment sign to "xdebug.so" --> the xdebug won't load
            sed -i "s/\([^;]*zend_extension=.*xdebug.so\)/;\\1/" $XDEBUG_INI
        else
            # Set remote IP
            HOST_IP=`/sbin/ip route|awk '/default/ { print $3 }'`
            # We have xdebug.ini.dist files for xdebug's config, which won't load when we don't want to use xdebug
            for file in $(egrep -lir --include=xdebug.ini.dist "remote" /usr/local/etc/php); do
                cp $file $(dirname $file)/xdebug.ini
                sed -i "s/\(xdebug.remote_host *= *\).*/\\1${HOST_IP}/" $(dirname $file)/xdebug.ini
            done
        fi

As I can see in the plugins/lando-services/services/php/php.js file, now if the config xdebug value is false, the program doesn't set the remote parameters:

    // Add in our xdebug config
    if (config.xdebug) {

      // Conf
      var xconfig = [
        'remote_enable=true',
        'remote_host=' + lando.config.env.LANDO_ENGINE_REMOTE_IP
      ];

      // Add the conf
      php.environment.XDEBUG_CONFIG = xconfig.join(' ');

    }

But it won't have an effect on the performance, and I can't switch off the xdebug, when I don't want to use it; and switch on, when I want it. In this form it is not very helpful. I think an else is required to really switch off xdebug.

pirog commented 6 years ago

@fchris82 yup, i think i agree with this. we should completely disable/enable the extension vs disabling/enabling the remote settings

ataylorme commented 5 years ago

I am trying to run Behat inside of Lando and keep getting this:

Background:                                # features/admin-login.feature:6
    Given I am logged in as an administrator # PaulGibbs\WordpressBehatExtension\Context\UserContext::iAmLoggedInAsRole()
      Fatal error: Maximum function nesting level of '256' reached, aborting! (Behat\Testwork\Call\Exception\FatalThrowableError)

I’ve only seen Maximum function nesting level style errors before when xdebug is on. I do not have xdebug defined in my .lando.yml and have also tried to explicitly set it to false but it seems xdebug is still running.

Tried a restart, rebuild and even deleted my local Docker image to force container images to re-download but no luck.

ataylorme commented 5 years ago

It turned out to be the lh-hsts plugin. I am running Behat tests with a wp-cli driver and the plugin sends the site into a redirect loop as the wp-cli driver tries to authenticate with WordPress.

unknownterritory commented 5 years ago

I've found a workaround to completely disable xdebug and ensure it doesn't get loaded:

lando ssh appserver --user=root
php --ini
apt-get update && apt-get install nano
nano /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
# comment out the only extension in that file
# exit and save
# logout from your ssh connection into appserver
lando restart

An easier way to accomplish this is using a build step in your lando recipe:

  appserver:
    type: php:7.1
    config:
      conf: config/php/php.ini
    # xdebug: true
    install_dependencies_as_root:
      - "mkdir /usr/local/etc/php/conf.d/disabled_extensions && mv -vf /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/disabled_extensions/docker-php-ext-xdebug.ini"

To apply the changes, you need to run lando rebuild. When you need xdebug again, you invert the mv instruction and un-comment the xdebug setting:

  appserver:
    type: php:7.1
    config:
      conf: config/php/php.ini
    xdebug: true
    install_dependencies_as_root:
      - "mv -vf /usr/local/etc/php/conf.d/disabled_extensions/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini "

To avoid rebuilding your app, I guess you can also log into appserver as root lando ssh appserver --user=root and run...

mkdir /usr/local/etc/php/conf.d/disabled_extensions && mv -vf /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/disabled_extensions/docker-php-ext-xdebug.ini

... and then run lando restart.

The gains in performance, so far, seem really worth it. I hope this may help.

blakethomp commented 5 years ago

@unknownterritory thanks for the tip! You could also use the -p parameter mkdir -p to only create the directory if it doesn't exist if you don't want to have to worry about changing that line.

pirog commented 5 years ago

We have changed the behavior here so that the xdebug extension is actually disabled by default and enabled when xdebug: true is set. This will be rolled out in RC2