Skip to content

Commit f90740e

Browse files
authored
Disable xdebug (phpactor#408)
* Disable XDebug * Execute new process in benchmarking tests * Rebased * Allow XDebug to be disabled in configuration * Use tagged xdebug handler * Updated doc * Allow XDebug when running PHPUnit
1 parent 1f0644a commit f90740e

File tree

13 files changed

+92
-17
lines changed

13 files changed

+92
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ Changelog
33

44
## Unreleased
55

6+
Features:
7+
8+
- [Application] Disable XDebug by default, very much improve performance.
9+
Fixes #317
10+
611
Improvements:
712

813
- [Completion] Do not evaluate left operand when completing expression,

bin/phpactor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use Symfony\Component\Debug\Debug;
55
use Symfony\Component\Console\Input\ArgvInput;
66
use Symfony\Component\Console\Output\ConsoleOutput;
77
use Phpactor\Application;
8+
use Composer\XdebugHandler\XdebugHandler;
89

910
foreach ([
1011
__DIR__ . '/../../../autoload.php',

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"symfony/yaml": "^3.3",
1818
"microsoft/tolerant-php-parser": "dev-master",
1919
"monolog/monolog": "^2.0@dev",
20-
"phpactor/completion": "^1.0@dev"
20+
"phpactor/completion": "^1.0@dev",
21+
"composer/xdebug-handler": "^1.1"
2122
},
2223
"config": {
2324
"platform": {

composer.lock

Lines changed: 45 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/configuration.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ path. The autoloader helps Phpactor locate classes.
5151

5252
*Default*: `true`
5353

54-
By default Phpactor will deregister the included autoloader to prevent
5554
any potential conflicts. However, some autoloaders may add global dependencies
55+
By default Phpactor will deregister the included autoloader to prevent
5656
on the code available through that autoloader (e.g. Drupal). In such cases
5757
set this to `false` and hope that everything is *fine*.
5858

@@ -86,6 +86,13 @@ The default logging level.
8686

8787
Where the log file is
8888

89+
#### xdebug_disable
90+
91+
*Default*: `true`
92+
93+
Disable XDebug if it's enabled. This can (likely will) have a very positive
94+
effect on performance.
95+
8996
### Code Transform Extension
9097

9198
#### code_transform.class_new.variants

lib/Extension/Core/Application/Status.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public function check(): array
3939
$diagnostics['bad'][] = 'Git not detected. Some operations which would have been better scoped to your project repository will now include vendor paths.';
4040
}
4141

42+
if (extension_loaded('xdebug')) {
43+
$diagnostics['bad'][] = 'XDebug is enabled. XDebug has a negative effect on performance.';
44+
} else {
45+
$diagnostics['good'][] = 'XDebug is disabled. XDebug has a negative effect on performance.';
46+
}
47+
4248
return $diagnostics;
4349
}
4450
}

lib/Extension/Core/CoreExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class CoreExtension implements Extension
3939
const LOGGING_ENABLED = 'logging.enabled';
4040
const LOGGING_FINGERS_CROSSED = 'logging.fingers_crossed';
4141
const AUTOLOAD_DEREGISTER = 'autoload.deregister';
42+
const XDEBUG_DISABLE = 'xdebug_disable';
4243

4344
public static $autoloader;
4445

@@ -54,6 +55,7 @@ public function configure(Schema $schema)
5455
self::LOGGING_FINGERS_CROSSED => true,
5556
self::LOGGING_PATH => 'phpactor.log',
5657
self::LOGGING_LEVEL => LogLevel::WARNING,
58+
self::XDEBUG_DISABLE => true,
5759
]);
5860
}
5961

lib/Phpactor.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
use Symfony\Component\Console\Input\InputInterface;
1919
use Phpactor\Config\Paths;
2020
use Phpactor\Extension\ClassToFile\ClassToFileExtension;
21+
use Composer\XdebugHandler\XdebugHandler;
2122

2223
class Phpactor
2324
{
2425
public static function boot(InputInterface $input): PhpactorContainer
2526
{
27+
2628
$config = [];
2729

2830
$configLoader = new ConfigLoader();
@@ -32,6 +34,12 @@ public static function boot(InputInterface $input): PhpactorContainer
3234
$config['cwd'] = $input->getParameterOption([ '--working-dir', '-d' ]);
3335
}
3436

37+
if (!isset($config[CoreExtension::XDEBUG_DISABLE]) || $config[CoreExtension::XDEBUG_DISABLE]) {
38+
$xdebug = new XdebugHandler('PHPACTOR', '--ansi');
39+
$xdebug->check();
40+
unset($xdebug);
41+
}
42+
3543
$extensionNames = [
3644
CoreExtension::class,
3745
ClassToFileExtension::class,

phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@
2222
</whitelist>
2323
</filter>
2424

25+
<php>
26+
<env name="PHPACTOR_ALLOW_XDEBUG" value="1"/>
27+
</php>
28+
2529
</phpunit>

tests/Benchmark/BaseBenchCase.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
use Phpactor\Application;
77
use Symfony\Component\Console\Output\BufferedOutput;
88
use Symfony\Component\Console\Input\ArrayInput;
9+
use Symfony\Component\Process\Process;
910

1011
class BaseBenchCase extends IntegrationTestCase
1112
{
12-
protected function runCommand(array $input): BufferedOutput
13+
protected function runCommand(string $command): string
1314
{
1415
chdir($this->workspaceDir());
15-
$application = new Application();
16-
$output = new BufferedOutput();
17-
$application->setAutoExit(false);
18-
$application->run(new ArrayInput($input), $output);
19-
return $output;
16+
17+
$process = new Process(__DIR__ . '/../../bin/phpactor ' . $command);
18+
$process->setWorkingDirectory($this->workspaceDir());
19+
$process->run();
20+
return $process->getOutput();
2021
}
2122
}

0 commit comments

Comments
 (0)