Skip to content

Commit

Permalink
Disable xdebug by default to improve performance (#6119)
Browse files Browse the repository at this point in the history
  • Loading branch information
webflo authored Oct 2, 2024
1 parent de459b4 commit c3a70a1
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 14 deletions.
1 change: 1 addition & 0 deletions .ddev/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ web_environment:
# - UNISH_DB_URL=pgsql://db:db@db:5432?module=pgsql
- DRUSH_OPTIONS_URI=$DDEV_PRIMARY_URL
- EDITOR=nano
- DRUSH_ALLOW_XDEBUG=1
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"security": "https://github.com/drush-ops/drush/security/advisories"
},
"bin": [
"drush"
"drush",
"drush.php"
],
"repositories": {
"drupal_org": {
Expand Down
8 changes: 8 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,11 @@ With this configuration in place, global commands may be placed as described in
1. The directory above `Commands` must be one of:
1. A Folder listed in the 'include' option. Include may be provided via [config](#global-drush-commands) or via CLI.
1. ../drush, /drush or /sites/all/drush. These paths are relative to Drupal root.

Xdebug
------------

Drush disables Xdebug by default. This improves performance substantially, because developers are often debugging something other than Drush and they still need to clear caches, import config, etc. There are two equivalent ways to override Drush's disabling of Xdebug:

- Pass the `--xdebug` global option.
- Set an environment variable: `DRUSH_ALLOW_XDEBUG=1 drush [command]`
36 changes: 33 additions & 3 deletions drush
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
#!/usr/bin/env php
<?php
#!/usr/bin/env sh

require __DIR__ . '/drush.php';
if [ -z "$COMPOSER_RUNTIME_BIN_DIR" ]; then
# This branch is for the development of Drush itself.
# @see https://stackoverflow.com/questions/4774054
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
DRUSH_PHP="$SCRIPTPATH/drush.php"
else
DRUSH_PHP="$COMPOSER_RUNTIME_BIN_DIR/drush.php"
fi

parse_commandline()
{
while test $# -gt 0
do
_key="$1"
case "$_key" in
--xdebug)
DRUSH_ALLOW_XDEBUG=1
return
;;
esac
shift
done
}

parse_commandline "$@"

if [ "$DRUSH_ALLOW_XDEBUG" != 1 ]
then
export XDEBUG_MODE=off
fi

"$DRUSH_PHP" "$@"
5 changes: 0 additions & 5 deletions drush.bat

This file was deleted.

1 change: 1 addition & 0 deletions drush.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env php
<?php

use Drush\Drush;
Expand Down
5 changes: 5 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public function configureGlobalOptions()
->addOption(
new InputOption('--define', '-D', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Define a configuration item value.', [])
);

$this->getDefinition()
->addOption(
new InputOption('--xdebug', null, InputOption::VALUE_NONE, 'Drush turns off Xdebug to achieve better performance. Pass this option to keep Xdebug enabled.')
);
}

public function bootstrapManager()
Expand Down
8 changes: 7 additions & 1 deletion src/Config/ConfigLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,13 @@ public function addSitewideConfig(string $siteRoot): ?self
// Remember that we've seen this location.
$this->siteRoots[] = $siteRoot;

$this->addConfigPaths(self::DRUPAL_CONTEXT, [ dirname($siteRoot) . '/drush', "$siteRoot/drush", "$siteRoot/sites/all/drush" ]);
$paths = [
dirname($siteRoot) . '/drush',
"$siteRoot/drush",
"$siteRoot/sites/all/drush",
];
$paths = array_filter($paths, is_dir(...));
$this->addConfigPaths(self::DRUPAL_CONTEXT, $paths);
return $this;
}

Expand Down
5 changes: 5 additions & 0 deletions src/Preflight/Preflight.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ public function preflight($argv): array
// Now that we know the value, set debug flag.
$this->logger()->setDebug($this->preflightArgs->get(PreflightArgs::DEBUG, false));

// Give hint if a developer might be trying to debug Drush.
if (extension_loaded('xdebug')) {
$this->logger()->log(strtr('Drush disables Xdebug by default. To override this, see !url', ['!url' => 'https://www.drush.org/latest/commands/#xdebug']));
}

// Do legacy initialization (load static includes, define old constants, etc.)
$this->init();

Expand Down
8 changes: 4 additions & 4 deletions tests/functional/SqlSyncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ public function testSimulatedSqlSync()
$this->drush(SqlSyncCommands::SYNC, ['@synctest.remote', '@synctest.local'], $options, '@synctest.local');
$output = $this->getSimplifiedErrorOutput();
$this->assertStringContainsString("[notice] Simulating: ssh -o PasswordAuthentication=whatever [email protected] '/path/to/drush sql:dump --no-interaction --strict=0 --gzip --result-file=auto --format=json --uri=remote", $output);
$this->assertStringContainsString("[notice] Simulating: __DIR__/drush core:rsync @synctest.remote:/simulated/path/to/dump.tgz @synctest.local:__SANDBOX__/tmp/dump.tgz --yes --uri=local -- --remove-source-files", $output);
$this->assertStringContainsString("[notice] Simulating: __DIR__/drush sql:query --no-interaction --strict=0 --file=__SANDBOX__/tmp/dump.tgz --file-delete --uri=local", $output);
$this->assertStringContainsString("[notice] Simulating: __DIR__/drush.php core:rsync @synctest.remote:/simulated/path/to/dump.tgz @synctest.local:__SANDBOX__/tmp/dump.tgz --yes --uri=local -- --remove-source-files", $output);
$this->assertStringContainsString("[notice] Simulating: __DIR__/drush.php sql:query --no-interaction --strict=0 --file=__SANDBOX__/tmp/dump.tgz --file-delete --uri=local", $output);

// Test simulated simple sql:sync local-to-remote
$this->drush(SqlSyncCommands::SYNC, ['@synctest.local', '@synctest.remote'], $options, '@synctest.local');
$output = $this->getSimplifiedErrorOutput();
$this->assertStringContainsString("[notice] Simulating: __DIR__/drush sql:dump --no-interaction --strict=0 --gzip --result-file=auto --format=json --uri=local", $output);
$this->assertStringContainsString("[notice] Simulating: __DIR__/drush core:rsync @synctest.local:/simulated/path/to/dump.tgz @synctest.remote:/tmp/dump.tgz --yes --uri=local -- --remove-source-files", $output);
$this->assertStringContainsString("[notice] Simulating: __DIR__/drush.php sql:dump --no-interaction --strict=0 --gzip --result-file=auto --format=json --uri=local", $output);
$this->assertStringContainsString("[notice] Simulating: __DIR__/drush.php core:rsync @synctest.local:/simulated/path/to/dump.tgz @synctest.remote:/tmp/dump.tgz --yes --uri=local -- --remove-source-files", $output);
$this->assertStringContainsString("[notice] Simulating: ssh -o PasswordAuthentication=whatever [email protected] '/path/to/drush sql:query --no-interaction --strict=0 --file=/tmp/dump.tgz --file-delete --uri=remote'", $output);

// Test simulated remote invoke with a remote runner.
Expand Down

0 comments on commit c3a70a1

Please sign in to comment.