diff --git a/src/Psalm/Internal/Cli/Psalm.php b/src/Psalm/Internal/Cli/Psalm.php index 43b8afe5f81..98c16d5c23a 100644 --- a/src/Psalm/Internal/Cli/Psalm.php +++ b/src/Psalm/Internal/Cli/Psalm.php @@ -431,8 +431,8 @@ public static function getThreads(array $options, Config $config, bool $in_ci, b } if ($for_scan) { - if (isset($options['scanThreads'])) { - $threads = max(1, (int)$options['scanThreads']); + if (isset($options['scan-threads'])) { + $threads = max(1, (int)$options['scan-threads']); } elseif (isset($options['debug']) || $in_ci) { $threads = 1; } elseif ($config->scan_threads) { diff --git a/src/Psalm/Internal/Fork/ForkContext.php b/src/Psalm/Internal/Fork/ForkContext.php index 2e08fc1f952..1a10ddef811 100644 --- a/src/Psalm/Internal/Fork/ForkContext.php +++ b/src/Psalm/Internal/Fork/ForkContext.php @@ -13,6 +13,7 @@ use Amp\Parallel\Context\Internal\ExitFailure; use Amp\Parallel\Context\Internal\ExitSuccess; use Amp\Parallel\Ipc\IpcHub; +use Amp\Serialization\NativeSerializer; use Amp\Serialization\SerializationException; use Amp\TimeoutCancellation; use Error; @@ -25,6 +26,7 @@ use function Amp\Parallel\Ipc\connect; use function count; use function define; +use function extension_loaded; use function fwrite; use function is_file; use function is_string; @@ -63,6 +65,10 @@ public static function start( ?Cancellation $cancellation = null, int $childConnectTimeout = self::DEFAULT_START_TIMEOUT, ): self { + $serializer = extension_loaded('igbinary') + ? new IgbinarySerializer + : new NativeSerializer; + $key = $ipcHub->generateKey(); // Fork @@ -74,10 +80,10 @@ public static function start( if ($pid > 0) { try { $socket = $ipcHub->accept($key, $cancellation); - $ipcChannel = new StreamChannel($socket, $socket); + $ipcChannel = new StreamChannel($socket, $socket, $serializer); $socket = $ipcHub->accept($key, $cancellation); - $resultChannel = new StreamChannel($socket, $socket); + $resultChannel = new StreamChannel($socket, $socket, $serializer); } catch (Throwable $exception) { $cancellation?->throwIfRequested(); @@ -98,10 +104,10 @@ public static function start( try { $socket = connect($uri, $key, $connectCancellation); - $ipcChannel = new StreamChannel($socket, $socket); + $ipcChannel = new StreamChannel($socket, $socket, $serializer); $socket = connect($uri, $key, $connectCancellation); - $resultChannel = new StreamChannel($socket, $socket); + $resultChannel = new StreamChannel($socket, $socket, $serializer); } catch (Throwable $exception) { trigger_error($exception->getMessage(), E_USER_ERROR); } diff --git a/src/Psalm/Internal/Fork/IgbinarySerializer.php b/src/Psalm/Internal/Fork/IgbinarySerializer.php new file mode 100644 index 00000000000..3c5744abf6d --- /dev/null +++ b/src/Psalm/Internal/Fork/IgbinarySerializer.php @@ -0,0 +1,52 @@ +getMessage(), + ), + 0, + $exception, + ); + } + } + + public function unserialize(string $data): mixed + { + try { + return igbinary_unserialize($data); + } catch (Throwable $exception) { + throw new SerializationException( + 'Exception thrown when unserializing data', + 0, + $exception, + ); + } + } +} diff --git a/src/Psalm/Internal/Fork/Pool.php b/src/Psalm/Internal/Fork/Pool.php index 78252943624..d045645459c 100644 --- a/src/Psalm/Internal/Fork/Pool.php +++ b/src/Psalm/Internal/Fork/Pool.php @@ -18,7 +18,7 @@ use AssertionError; use Closure; use Psalm\Progress\Progress; -use Throwable; +use Revolt\EventLoop; use function Amp\Future\await; use function array_map; @@ -95,8 +95,11 @@ public function run( if ($task_done_closure) { $f->map($task_done_closure); } - $f->catch(fn(Throwable $e) => throw $e); - $f->map(function () use (&$cnt, $total): void { + $id = EventLoop::delay(10.0, function () use ($file): void { + $this->progress->write(PHP_EOL."Processing $file is taking more than 10 seconds...".PHP_EOL); + }); + $f->map(function () use (&$cnt, $total, $id): void { + EventLoop::cancel($id); $cnt++; if (!($cnt % 10)) { $percent = (int) (($cnt*100) / $total);