Skip to content

Commit

Permalink
Fixed an issue where the PCRE JIT on PHP 7.3 caused PHPCS to die when…
Browse files Browse the repository at this point in the history
… using the parallel option (ref #2304)
  • Loading branch information
gsherwood committed Apr 9, 2019
1 parent dd3f6e0 commit c09a4e1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
2 changes: 2 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD 3-Clause License</license>
<notes>
- Squiz.Arrays.ArrayDeclaration now has improved handling of syntax errors
- Fixed an issue where the PCRE JIT on PHP 7.3 caused PHPCS to die when using the parallel option
-- PHPCS now disables the PCRE JIT before running
- Fixed bug #2368 : MySource.PHP.AjaxNullComparison throws error when first function has no doc comment
- Fixed bug #2414 : Indention false positive in switch/case/if combination
- Fixed bug #2423 : Squiz.Formatting.OperatorBracket.MissingBrackets error with static
Expand Down
42 changes: 30 additions & 12 deletions src/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ public function init()
// be detected properly for files created on a Mac with the /r line ending.
ini_set('auto_detect_line_endings', true);

// Disable the PCRE JIT as this caused issues with parallel running.
ini_set('pcre.jit', false);

// Check that the standards are valid.
foreach ($this->config->standards as $standard) {
if (Util\Standards::isInstalledStandard($standard) === false) {
Expand Down Expand Up @@ -536,7 +539,10 @@ private function run()
}//end if
}//end for

$this->processChildProcs($childProcs);
$success = $this->processChildProcs($childProcs);
if ($success === false) {
throw new RuntimeException('One or more child processes failed to run');
}
}//end if

restore_error_handler();
Expand Down Expand Up @@ -709,20 +715,35 @@ private function processChildProcs($childProcs)
$numProcessed = 0;
$totalBatches = count($childProcs);

$success = true;

while (count($childProcs) > 0) {
foreach ($childProcs as $key => $procData) {
$res = pcntl_waitpid($procData['pid'], $status, WNOHANG);
if ($res === $procData['pid']) {
if (file_exists($procData['out']) === true) {
include $procData['out'];
if (isset($childOutput) === true) {
$this->reporter->totalFiles += $childOutput['totalFiles'];
$this->reporter->totalErrors += $childOutput['totalErrors'];
$this->reporter->totalWarnings += $childOutput['totalWarnings'];
$this->reporter->totalFixable += $childOutput['totalFixable'];
$this->reporter->totalFixed += $childOutput['totalFixed'];

unlink($procData['out']);
unset($childProcs[$key]);

$numProcessed++;

if (isset($childOutput) === false) {
// The child process died, so the run has failed.
$file = new DummyFile(null, $this->ruleset, $this->config);
$file->setErrorCounts(1, 0, 0, 0);
$this->printProgress($file, $totalBatches, $numProcessed);
$success = false;
continue;
}

$this->reporter->totalFiles += $childOutput['totalFiles'];
$this->reporter->totalErrors += $childOutput['totalErrors'];
$this->reporter->totalWarnings += $childOutput['totalWarnings'];
$this->reporter->totalFixable += $childOutput['totalFixable'];
$this->reporter->totalFixed += $childOutput['totalFixed'];

if (isset($debugOutput) === true) {
echo $debugOutput;
}
Expand All @@ -733,11 +754,6 @@ private function processChildProcs($childProcs)
}
}

unlink($procData['out']);
unset($childProcs[$key]);

$numProcessed++;

// Fake a processed file so we can print progress output for the batch.
$file = new DummyFile(null, $this->ruleset, $this->config);
$file->setErrorCounts(
Expand All @@ -752,6 +768,8 @@ private function processChildProcs($childProcs)
}//end foreach
}//end while

return $success;

}//end processChildProcs()


Expand Down

0 comments on commit c09a4e1

Please sign in to comment.