• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dg / dresscode / 41044778467

30 Oct 2026 10:08AM UTC coverage: 97.234% (-0.3%) from 97.495%
41044778467

push

github

dg
upgrade: a decision only the data of the target version turn on belongs to the jump, the project as it is today resolved without narrowing, so that the plan no longer fixes it in the bridge, where nothing runs it

837123ff-7353-45e9-8cd7-ba68b373e93e

5 of 5 new or added lines in 1 file covered. (100.0%)

160 existing lines in 33 files now uncovered.

27315 of 28092 relevant lines covered (97.23%)

0.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.45
/src/Engine/WorkerPool.php
1
<?php declare(strict_types=1);
2

3
/**
4
 * This file is part of the DressCode, a coding style and upgrade tool for PHP (https://dresscode.run)
5
 * Copyright (c) 2026 David Grudl (https://davidgrudl.com)
6
 */
7

8
namespace DressCode\Engine;
9

10
use DressCode\FileResult;
11
use function array_key_exists, count, function_exists, in_array, is_array, strlen;
12
use const PHP_OS_FAMILY, PHP_SAPI;
13

14

15
/**
16
 * Processes files in worker processes: a TCP server on the loopback hands the paths out one at a time,
17
 * a worker sends each result back as a line of JSON. The parent keeps the cache and the baseline, a worker
18
 * only processes and, when fixing, writes.
19
 * @internal
20
 */
21
final class WorkerPool
22
{
23
        /** microseconds the wait for the workers lasts at most while the progress is watched, so that a spinner turns */
24
        private const ProgressInterval = 100_000;
25

26
        /**
27
         * The listening socket: from ext/sockets when available, because the stream layer on Windows waits 500 ms
28
         * for a socket to become writable before closing it, which a listening one never does.
29
         * @var \Socket|resource|null
30
         */
31
        private mixed $server = null;
32

33
        /** @var array<int, resource>  connected workers by socket id */
34
        private array $sockets = [];
35

36
        /** @var array<int, string>  what a worker sent after its last complete line, by socket id */
37
        private array $buffers = [];
38

39
        /** workers that have connected so far */
40
        private int $accepted = 0;
41

42
        /** workers started once the first has connected */
43
        private int $pending = 0;
44

45
        /** the address the workers connect to */
46
        private string $address = '';
47

48
        /** @var array<int, array{string, float, string}>  path in progress with the time it started and its content, by socket id */
49
        private array $inProgress = [];
50

51
        /** @var ?\Closure(string): string  path => content, read when the path is handed out */
52
        private ?\Closure $read = null;
53

54
        /** @var list<array{resource, string}>  process, file with its output */
55
        private array $workers = [];
56

57
        /** when the last worker was started */
58
        private float $spawnedAt = 0;
59

60
        /** @var list<string> */
61
        private array $queue = [];
62

63
        /** @var array<int, true>  workers asked for what they measured last, by socket id */
64
        private array $finishing = [];
65

66
        /** @var array<string, true>  the files the results depend on, as the workers sent them */
67
        private array $dependencies = [];
68

69
        /** @var array<string, true>  what the analyses of the workers tell the user about the run */
70
        private array $warnings = [];
71

72

73
        public function __construct(
74
                /** @var list<string> the worker command line; --worker with the address is appended */
75
                private readonly array $command,
1 ✔
76
                private readonly int $jobs,
1 ✔
77
                /** working directory of the workers */
78
                private readonly ?string $cwd = null,
1 ✔
79
                /** seconds a worker may spend on one file before the run fails, since a rule has most likely looped */
80
                private readonly int $taskTimeout = 300,
1 ✔
81
                /** seconds a worker may take to connect, the first one filling the cache the others share among them */
82
                private readonly int $connectTimeout = 300,
1 ✔
83
                /** with it, every worker hands over what it measured last once nothing is left, one that got no file among them */
84
                private readonly ?Profiler $profiler = null,
1 ✔
85
                /** the first worker fills a cache the others share before it connects, and they start after that */
86
                private readonly bool $warmFirst = false,
1 ✔
87
        ) {
88
        }
1 ✔
89

90

91
        /**
92
         * The workers a run of the files takes by default: a worker costs about the processing of a few files to start, so one
93
         * for every four files at most, and no more than the processors.
94
         */
95
        public static function countDefaultJobs(int $files): int
96
        {
97
                return max(1, min(self::detectCpuCount(), intdiv($files, 4)));
1 ✔
98
        }
99

100

101
        /** Processors the machine has, 1 when unknown. */
102
        public static function detectCpuCount(): int
103
        {
104
                $count = (int) getenv('NUMBER_OF_PROCESSORS');
1 ✔
105
                if ($count < 1 && is_readable('/proc/cpuinfo')) {
1 ✔
106
                        $count = preg_match_all('~^processor\s*:~m', (string) file_get_contents('/proc/cpuinfo'));
1 ✔
107
                }
108

109
                if ($count < 1 && in_array(PHP_OS_FAMILY, ['Darwin', 'BSD'], true) && function_exists('shell_exec')) {
1 ✔
UNCOV
110
                        $count = (int) @shell_exec('sysctl -n hw.ncpu 2>/dev/null'); // @ a failed command gives no count
×
111
                }
112

113
                return max(1, $count);
1 ✔
114
        }
115

116

117
        /**
118
         * The PHP a worker is started with: the same binary with the same ini file, the binary alone loading the default
119
         * one, and the settings the process has beyond it; null where no CLI binary is found to start one.
120
         * @return ?list<string>
121
         */
122
        public static function buildPhpCommand(): ?array
123
        {
124
                $binary = self::findCliBinary();
1 ✔
125
                if ($binary === null) {
1 ✔
UNCOV
126
                        return null;
×
127
                }
128

129
                $ini = php_ini_loaded_file();
1 ✔
130
                $php = [$binary, ...($ini === false ? (php_ini_scanned_files() === false ? ['-n'] : []) : ['-c', $ini])];
1 ✔
131
                return [...$php, ...self::findIniOverrides($php)];
1 ✔
132
        }
133

134

135
        /** The binary of the process, or under another SAPI than CLI, such as CGI, the CLI binary beside it. */
136
        private static function findCliBinary(): ?string
137
        {
138
                if (PHP_SAPI === 'cli') {
1 ✔
139
                        return PHP_BINARY;
1 ✔
140
                }
141

UNCOV
142
                $path = dirname(PHP_BINARY) . '/php' . (PHP_OS_FAMILY === 'Windows' ? '.exe' : '');
×
UNCOV
143
                return is_file($path) ? $path : null;
×
144
        }
145

146

147
        /**
148
         * The settings the process has and the PHP of the command alone would not, those given by -d above all, as the
149
         * options -d that give them to a worker; PHP tells no process the options it started with, so the PHP of the
150
         * command is asked for its settings and they are compared.
151
         * @param  list<string>  $php
152
         * @return list<string>
153
         */
154
        private static function findIniOverrides(array $php): array
155
        {
156
                $null = PHP_OS_FAMILY === 'Windows' ? 'NUL' : '/dev/null';
1 ✔
157
                $process = @proc_open([...$php, '-r', 'echo serialize(ini_get_all(null, false));'], [1 => ['pipe', 'w'], 2 => ['file', $null, 'w']], $pipes); // @ no settings then
1 ✔
158
                if ($process === false) {
1 ✔
UNCOV
159
                        return [];
×
160
                }
161

162
                $base = @unserialize((string) stream_get_contents($pipes[1])); // @ a PHP that failed to start gives none
1 ✔
163
                fclose($pipes[1]);
1 ✔
164
                proc_close($process);
1 ✔
165
                $own = ini_get_all(details: false);
1 ✔
166
                if (!is_array($base) || $own === false) {
1 ✔
UNCOV
167
                        return [];
×
168
                }
169

170
                $options = [];
1 ✔
171
                foreach ($own as $name => $value) {
1 ✔
172
                        if (array_key_exists($name, $base) && $base[$name] !== $value) {
1 ✔
173
                                $options[] = '-d';
1 ✔
174
                                $options[] = "$name=$value";
1 ✔
175
                        }
176
                }
177

178
                return $options;
1 ✔
179
        }
180

181

182
        /**
183
         * The results by path, each as soon as it arrives; the content of a file is read when it is handed out, so that
184
         * only the files in progress are held.
185
         * @param  list<string>  $paths
186
         * @param  \Closure(string): string  $read  path => content
187
         * @param  ?\Closure(int, array<string, float>): void  $onProgress  files done and the paths in progress
188
         * @return \Generator<string, FileResult>
189
         * @throws \RuntimeException  when a worker fails
190
         */
191
        public function process(array $paths, \Closure $read, ?\Closure $onProgress = null): \Generator
1 ✔
192
        {
193
                $address = $this->listen();
1 ✔
194
                $this->queue = $paths;
1 ✔
195
                $this->read = $read;
1 ✔
196
                $done = 0;
1 ✔
197
                try {
198
                        $count = min($this->jobs, count($this->queue));
1 ✔
199
                        $this->address = $address;
1 ✔
200
                        $this->pending = $this->warmFirst ? $count - 1 : 0;
1 ✔
201
                        for ($i = $count - $this->pending; $i > 0; $i--) {
1 ✔
202
                                $this->workers[] = $this->spawn($address);
1 ✔
203
                        }
204

205
                        while ($done < count($paths) || $this->isFinishing()) {
1 ✔
206
                                foreach ($this->await(watched: $onProgress !== null) as $stream) {
1 ✔
207
                                        foreach ($this->receive((int) $stream) as $path => $result) {
1 ✔
208
                                                $done++;
1 ✔
209
                                                yield $path => $result;
1 ✔
210
                                        }
211
                                }
212

213
                                $this->checkWorkers($done < count($paths));
1 ✔
214
                                if ($onProgress !== null) {
1 ✔
UNCOV
215
                                        $onProgress($done, $this->getInProgress());
×
216
                                }
217
                        }
218

219
                } finally {
1 ✔
220
                        foreach ($this->sockets as $socket) {
1 ✔
221
                                fclose($socket);
1 ✔
222
                        }
223

224
                        $this->closeServer();
1 ✔
225
                        $this->stop();
1 ✔
226
                }
227
        }
1 ✔
228

229

230
        /**
231
         * The files the results of the workers depend on beyond the configuration, as they sent them.
232
         * @return list<string>
233
         */
234
        public function getDependencies(): array
235
        {
236
                return array_keys($this->dependencies);
1 ✔
237
        }
238

239

240
        /**
241
         * What the analyses of the workers tell the user about the run, each thing once.
242
         * @return list<string>
243
         */
244
        public function getWarnings(): array
245
        {
246
                return array_keys($this->warnings);
1 ✔
247
        }
248

249

250
        /** @return string  the address the workers connect to */
251
        private function listen(): string
252
        {
253
                if (function_exists('socket_create')) {
1 ✔
254
                        $server = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
1 ✔
255
                        if (
256
                                $server === false
1 ✔
257
                                || !socket_bind($server, '127.0.0.1')
1 ✔
258
                                || !socket_listen($server, $this->jobs)
1 ✔
259
                                || !socket_getsockname($server, $ip, $port)
1 ✔
260
                        ) {
UNCOV
261
                                throw new \RuntimeException('Cannot start the worker server: ' . socket_strerror(socket_last_error()));
×
262
                        }
263

264
                        $this->server = $server;
1 ✔
265
                        return "$ip:$port";
1 ✔
266
                }
267

UNCOV
268
                $context = stream_context_create(['socket' => ['tcp_nodelay' => true]]); // Nagle would delay every small message by an ACK
×
UNCOV
269
                $server = @stream_socket_server('tcp://127.0.0.1:0', $errno, $error, context: $context); // @ is escalated to exception
×
UNCOV
270
                if ($server === false) {
×
UNCOV
271
                        throw new \RuntimeException("Cannot start the worker server: $error");
×
272
                }
273

UNCOV
274
                $this->server = $server;
×
UNCOV
275
                return (string) stream_socket_get_name($server, remote: false);
×
276
        }
277

278

279
        /**
280
         * Waits for messages from the workers, accepting the ones that connect meanwhile; the listening socket
281
         * from ext/sockets is closed as soon as the last worker is in.
282
         * @param  bool  $watched  the progress is drawn, so the wait is short
283
         * @return list<resource>  connections with a message waiting
284
         */
285
        private function await(bool $watched): array
286
        {
287
                $read = array_values($this->sockets);
1 ✔
288
                $write = $except = [];
1 ✔
289
                $seconds = $watched ? 0 : 1;
1 ✔
290
                $microseconds = $watched ? self::ProgressInterval : 0;
1 ✔
291
                $server = $this->server;
1 ✔
292
                if ($server instanceof \Socket) {
1 ✔
293
                        $this->acceptPending($server, blocking: $read === []);
1 ✔
294
                        if ($this->accepted === count($this->workers)) {
1 ✔
295
                                $this->closeServer();
1 ✔
296
                        } else { // short waits while workers may still be connecting
297
                                $seconds = 0;
1 ✔
298
                                $microseconds = 10_000;
1 ✔
299
                        }
300
                } elseif ($server !== null) {
1 ✔
UNCOV
301
                        $read[] = $server;
×
302
                }
303

304
                if ($read === []) { // nothing connected: the workers are still starting, or they are gone
1 ✔
305
                        return [];
1 ✔
306
                }
307

308
                if (@stream_select($read, $write, $except, $seconds, $microseconds) === false) { // @ is escalated to exception
1 ✔
UNCOV
309
                        throw new \RuntimeException('Waiting for the workers failed.');
×
310
                }
311

312
                $streams = [];
1 ✔
313
                foreach ($read as $stream) {
1 ✔
314
                        if ($stream === $server) {
1 ✔
315
                                $this->acceptStream($stream);
×
316
                        } else {
317
                                $streams[] = $stream;
1 ✔
318
                        }
319
                }
320

321
                return $streams;
1 ✔
322
        }
323

324

325
        /** Accepts every worker waiting to connect; with nothing to do otherwise, waits for the first one. */
326
        private function acceptPending(\Socket $server, bool $blocking): void
327
        {
328
                while (true) {
1 ✔
329
                        $read = [$server];
1 ✔
330
                        $write = $except = null;
1 ✔
331
                        if (socket_select($read, $write, $except, $blocking ? 1 : 0) !== 1) {
1 ✔
332
                                return;
1 ✔
333
                        }
334

335
                        $blocking = false;
1 ✔
336
                        $connection = socket_accept($server);
1 ✔
337
                        if ($connection === false) {
1 ✔
UNCOV
338
                                return;
×
339
                        }
340

341
                        socket_set_option($connection, SOL_TCP, TCP_NODELAY, 1); // Nagle would delay every small message by an ACK
1 ✔
342
                        $stream = socket_export_stream($connection);
1 ✔
343
                        if ($stream === false) {
1 ✔
UNCOV
344
                                throw new \RuntimeException('Cannot use the connection of a worker.');
×
345
                        }
346

347
                        $this->acceptConnection($stream);
1 ✔
348
                }
UNCOV
349
        }
×
350

351

352
        /** @param resource $server */
353
        private function acceptStream($server): void
354
        {
UNCOV
355
                $socket = @stream_socket_accept($server, 0); // @ a false alarm is harmless
×
UNCOV
356
                if ($socket !== false) {
×
UNCOV
357
                        $this->acceptConnection($socket);
×
358
                }
UNCOV
359
        }
×
360

361

362
        /**
363
         * Registers the connection, starts the workers that waited for it, and hands it a path. It is read without
364
         * blocking: a worker may have sent only a part of its line, and waiting for the rest would stop the parent from
365
         * hearing the others and from noticing a worker that is stuck.
366
         * @param resource $socket
367
         */
368
        private function acceptConnection($socket): void
369
        {
370
                stream_set_blocking($socket, enable: false);
1 ✔
371
                $this->accepted++;
1 ✔
372
                for (; $this->pending > 0; $this->pending--) {
1 ✔
373
                        $this->workers[] = $this->spawn($this->address);
1 ✔
374
                }
375

376
                $id = (int) $socket;
1 ✔
377
                $this->sockets[$id] = $socket;
1 ✔
378
                $this->assign($id);
1 ✔
379
        }
1 ✔
380

381

382
        private function closeServer(): void
383
        {
384
                if ($this->server instanceof \Socket) {
1 ✔
385
                        socket_close($this->server);
1 ✔
386
                } elseif ($this->server !== null) {
1 ✔
UNCOV
387
                        fclose($this->server);
×
388
                }
389

390
                $this->server = null;
1 ✔
391
        }
1 ✔
392

393

394
        /**
395
         * The results the worker has finished sending, by path: every line answers the path in progress, and a line
396
         * about any other one is a failure, as is an ended worker with a path in progress.
397
         * @return array<string, FileResult>
398
         */
399
        private function receive(int $id): array
400
        {
401
                $socket = $this->sockets[$id] ?? null;
1 ✔
402
                if ($socket === null) {
1 ✔
UNCOV
403
                        return [];
×
404
                }
405

406
                $chunk = fread($socket, 1 << 20);
1 ✔
407
                if ($chunk === false || ($chunk === '' && feof($socket))) {
1 ✔
UNCOV
408
                        if (isset($this->inProgress[$id])) {
×
UNCOV
409
                                throw new \RuntimeException("A worker ended while processing `{$this->inProgress[$id][0]}`." . $this->collectErrors());
×
410
                        }
411

UNCOV
412
                        $this->disconnect($id);
×
UNCOV
413
                        return [];
×
414
                }
415

416
                $buffer = ($this->buffers[$id] ?? '') . $chunk;
1 ✔
417
                $results = [];
1 ✔
418
                while (($end = strpos($buffer, "\n")) !== false) {
1 ✔
419
                        $data = json_decode(substr($buffer, 0, $end), associative: true);
1 ✔
420
                        $buffer = substr($buffer, $end + 1);
1 ✔
421
                        if (isset($this->finishing[$id]) && is_array($data['profile'] ?? null)) {
1 ✔
422
                                $this->profiler?->merge($data['profile']);
1 ✔
423
                                $this->disconnect($id);
1 ✔
424
                                break;
1 ✔
425
                        }
426

427
                        [$path, , $code] = $this->inProgress[$id] ?? [null, null, ''];
1 ✔
428
                        if (!is_array($data) || $path === null || ($data['path'] ?? null) !== base64_encode($path)) {
1 ✔
429
                                throw new \RuntimeException('A worker sent an unexpected message.' . $this->collectErrors());
1 ✔
430
                        }
431

432
                        unset($this->inProgress[$id]);
1 ✔
433
                        foreach (is_array($data['dependencies'] ?? null) ? $data['dependencies'] : [] as $file) {
1 ✔
434
                                $this->dependencies[(string) $file] = true;
1 ✔
435
                        }
436

437
                        foreach (is_array($data['runWarnings'] ?? null) ? $data['runWarnings'] : [] as $warning) {
1 ✔
438
                                $this->warnings[(string) $warning] = true;
1 ✔
439
                        }
440

441
                        [$results[$path], $profile] = WorkerCodec::decode($data, $code);
1 ✔
442
                        if ($profile !== null) {
1 ✔
443
                                $this->profiler?->merge($profile);
1 ✔
444
                        }
445

446
                        $this->assign($id);
1 ✔
447
                }
448

449
                if (isset($this->sockets[$id]) && strlen($buffer)) {
1 ✔
450
                        $this->buffers[$id] = $buffer;
1 ✔
451
                } else {
452
                        unset($this->buffers[$id]);
1 ✔
453
                }
454

455
                return $results;
1 ✔
456
        }
457

458

459
        /** Hands the next path to the worker; when there is none, asks it for what it measured last, or closes its connection. */
460
        private function assign(int $id): void
461
        {
462
                $path = array_shift($this->queue);
1 ✔
463
                if ($path === null && $this->profiler !== null) {
1 ✔
464
                        $this->finishing[$id] = true;
1 ✔
465
                        fwrite($this->sockets[$id], json_encode(['finish' => true], JSON_THROW_ON_ERROR) . "\n");
1 ✔
466
                        return;
1 ✔
467
                } elseif ($path === null) {
1 ✔
468
                        $this->disconnect($id);
1 ✔
469
                        return;
1 ✔
470
                }
471

472
                $read = $this->read ?? throw new \LogicException('No run is in progress.');
1 ✔
473
                $this->inProgress[$id] = [$path, microtime(as_float: true), $read($path)];
1 ✔
474
                fwrite($this->sockets[$id], json_encode(['path' => base64_encode($path)], JSON_THROW_ON_ERROR) . "\n"); // a path need not be UTF-8
1 ✔
475
        }
1 ✔
476

477

478
        /** @return array<string, float>  path in progress => the time it started */
479
        private function getInProgress(): array
480
        {
UNCOV
481
                $paths = [];
×
UNCOV
482
                foreach ($this->inProgress as [$path, $since]) {
×
UNCOV
483
                        $paths[$path] = $since;
×
484
                }
485

UNCOV
486
                return $paths;
×
487
        }
488

489

490
        private function disconnect(int $id): void
491
        {
492
                fclose($this->sockets[$id]);
1 ✔
493
                unset($this->sockets[$id], $this->inProgress[$id], $this->buffers[$id], $this->finishing[$id]);
1 ✔
494
        }
1 ✔
495

496

497
        /**
498
         * Whether the run still waits for what the workers measured last: from one asked for it, and from one still
499
         * starting, which gets nothing to process but has its peak memory.
500
         */
501
        private function isFinishing(): bool
502
        {
503
                if ($this->profiler === null) {
1 ✔
504
                        return false;
1 ✔
505
                } elseif ($this->finishing !== []) {
1 ✔
506
                        return true;
1 ✔
507
                }
508

509
                // which process a connection belongs to is unknown, so a worker done with its work is waited for too, until it exits
510
                return $this->accepted < count($this->workers)
1 ✔
511
                        && array_any($this->workers, fn(array $worker) => proc_get_status($worker[0])['running']);
1 ✔
512
        }
513

514

515
        /** @return array{resource, string}  process, file with its output */
516
        private function spawn(string $address): array
517
        {
518
                $output = (string) tempnam(sys_get_temp_dir(), 'dresscode-worker-');
1 ✔
519
                $process = @proc_open( // @ is escalated to exception
1 ✔
520
                        [...$this->command, '--worker', $address],
1 ✔
521
                        [0 => ['pipe', 'r'], 1 => ['file', $output, 'a'], 2 => ['file', $output, 'a']],
1 ✔
522
                        $pipes,
523
                        $this->cwd,
1 ✔
524
                );
525
                if ($process === false) {
1 ✔
UNCOV
526
                        throw new \RuntimeException('Cannot start a worker process: `' . implode(' ', $this->command) . '`');
×
527
                }
528

529
                fclose($pipes[0]);
1 ✔
530
                $this->spawnedAt = microtime(as_float: true);
1 ✔
531
                return [$process, $output];
1 ✔
532
        }
533

534

535
        /**
536
         * A worker that exited with an error, one that has spent longer than the timeout on a file, a worker the run waits
537
         * for that has not connected within its timeout, or every worker gone while results are missing fails the run.
538
         */
539
        private function checkWorkers(bool $resultsMissing): void
540
        {
541
                $running = false;
1 ✔
542
                foreach ($this->workers as [$process]) {
1 ✔
543
                        $status = proc_get_status($process);
1 ✔
544
                        if ($status['running']) {
1 ✔
545
                                $running = true;
1 ✔
546
                        } elseif ($status['exitcode'] !== 0) {
1 ✔
UNCOV
547
                                throw new \RuntimeException("A worker exited with code {$status['exitcode']}." . $this->collectErrors());
×
548
                        }
549
                }
550

551
                foreach ($this->inProgress as [$path, $since]) {
1 ✔
552
                        if (microtime(as_float: true) - $since > $this->taskTimeout) {
1 ✔
553
                                throw new \RuntimeException("A worker has spent more than $this->taskTimeout s on `$path`; a rule has most likely looped." . $this->collectErrors());
1 ✔
554
                        }
555
                }
556

557
                if (
558
                        $this->sockets === []
1 ✔
559
                        && $this->accepted < count($this->workers)
1 ✔
560
                        && microtime(as_float: true) - $this->spawnedAt > $this->connectTimeout
1 ✔
561
                ) {
562
                        throw new \RuntimeException("A worker has not connected within $this->connectTimeout s." . $this->collectErrors());
1 ✔
563
                }
564

565
                if (!$running && $resultsMissing) {
1 ✔
UNCOV
566
                        throw new \RuntimeException('The workers ended before processing every file.' . $this->collectErrors());
×
567
                }
568
        }
1 ✔
569

570

571
        private function collectErrors(): string
572
        {
573
                $errors = '';
1 ✔
574
                foreach ($this->workers as [, $output]) {
1 ✔
575
                        $errors .= trim((string) @file_get_contents($output)); // @ file may have been deleted meanwhile
1 ✔
576
                }
577

578
                return $errors === '' ? '' : "\n$errors";
1 ✔
579
        }
580

581

582
        private function stop(): void
583
        {
584
                foreach ($this->workers as [$process, $output]) {
1 ✔
585
                        if (proc_get_status($process)['running']) {
1 ✔
586
                                proc_terminate($process);
1 ✔
587
                        }
588

589
                        proc_close($process);
1 ✔
590
                        @unlink($output); // @ file may have been deleted meanwhile
1 ✔
591
                }
592

593
                $this->workers = $this->sockets = $this->inProgress = $this->buffers = [];
1 ✔
594
                $this->accepted = $this->pending = 0;
1 ✔
595
                $this->read = null;
1 ✔
596
        }
1 ✔
597
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc