diff --git a/docs/running_psalm/configuration.md b/docs/running_psalm/configuration.md index 077068cb6e3..198ab3b974f 100644 --- a/docs/running_psalm/configuration.md +++ b/docs/running_psalm/configuration.md @@ -396,6 +396,13 @@ Whether or not to allow `require`/`include` calls in your PHP. Defaults to `true ``` Allows you to hard-code a serializer for Psalm to use when caching data. By default, Psalm uses `ext-igbinary` *if* the version is greater than or equal to 2.0.5, otherwise it defaults to PHP's built-in serializer. +#### threads +```xml + +``` +Allows you to hard-code the number of threads Psalm will use (similar to `--threads` on the command line). This value will be used in place of detecting threads from the host machine, but will be overridden by using `--threads` or `--debug` (which sets threads to 1) on the command line ## Project settings diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index 8e0f8a75c17..c80ca64de65 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -563,6 +563,9 @@ class Config */ public $internal_stubs = []; + /** @var ?int */ + public $threads; + protected function __construct() { self::$instance = $this; @@ -1222,6 +1225,10 @@ private static function fromXmlAndPaths( } } + if (isset($config_xml->threads)) { + $config->threads = (int)$config_xml->threads; + } + return $config; } diff --git a/src/Psalm/Internal/Cli/Psalm.php b/src/Psalm/Internal/Cli/Psalm.php index b512574332b..70893dddc4a 100644 --- a/src/Psalm/Internal/Cli/Psalm.php +++ b/src/Psalm/Internal/Cli/Psalm.php @@ -249,7 +249,7 @@ public static function run(array $argv): void $options['long-progress'] = true; } - $threads = self::detectThreads($options, $in_ci); + $threads = self::detectThreads($options, $config, $in_ci); self::emitMacPcreWarning($options, $threads); @@ -913,12 +913,14 @@ private static function restart(array $options, Config $config, int $threads): v } } - private static function detectThreads(array $options, bool $in_ci): int + private static function detectThreads(array $options, Config $config, bool $in_ci): int { if (isset($options['threads'])) { $threads = (int)$options['threads']; } elseif (isset($options['debug']) || $in_ci) { $threads = 1; + } elseif ($config->threads) { + $threads = $config->threads; } else { $threads = max(1, ProjectAnalyzer::getCpuCount() - 1); }