@@ -460,10 +460,7 @@ private function run()
460460 if ($ pid === -1 ) {
461461 throw new RuntimeException ('Failed to create child process ' );
462462 } else if ($ pid !== 0 ) {
463- $ childProcs [] = [
464- 'pid ' => $ pid ,
465- 'out ' => $ childOutFilename ,
466- ];
463+ $ childProcs [$ pid ] = $ childOutFilename ;
467464 } else {
468465 // Move forward to the start of the batch.
469466 $ todo ->rewind ();
@@ -536,7 +533,7 @@ private function run()
536533
537534 $ output .= "; \n? " .'> ' ;
538535 file_put_contents ($ childOutFilename , $ output );
539- exit ($ pid );
536+ exit ();
540537 }//end if
541538 }//end for
542539
@@ -719,54 +716,53 @@ private function processChildProcs($childProcs)
719716 $ success = true ;
720717
721718 while (count ($ childProcs ) > 0 ) {
722- foreach ($ childProcs as $ key => $ procData ) {
723- $ res = pcntl_waitpid ($ procData ['pid ' ], $ status , WNOHANG );
724- if ($ res === $ procData ['pid ' ]) {
725- if (file_exists ($ procData ['out ' ]) === true ) {
726- include $ procData ['out ' ];
727-
728- unlink ($ procData ['out ' ]);
729- unset($ childProcs [$ key ]);
730-
731- $ numProcessed ++;
732-
733- if (isset ($ childOutput ) === false ) {
734- // The child process died, so the run has failed.
735- $ file = new DummyFile ('' , $ this ->ruleset , $ this ->config );
736- $ file ->setErrorCounts (1 , 0 , 0 , 0 );
737- $ this ->printProgress ($ file , $ totalBatches , $ numProcessed );
738- $ success = false ;
739- continue ;
740- }
741-
742- $ this ->reporter ->totalFiles += $ childOutput ['totalFiles ' ];
743- $ this ->reporter ->totalErrors += $ childOutput ['totalErrors ' ];
744- $ this ->reporter ->totalWarnings += $ childOutput ['totalWarnings ' ];
745- $ this ->reporter ->totalFixable += $ childOutput ['totalFixable ' ];
746- $ this ->reporter ->totalFixed += $ childOutput ['totalFixed ' ];
719+ $ pid = pcntl_waitpid (0 , $ status );
720+ if ($ pid > 0 ) {
721+ $ out = $ childProcs [$ pid ];
722+ unset($ childProcs [$ pid ]);
723+ if (file_exists ($ out ) === true ) {
724+ include $ out ;
747725
748- if (isset ($ debugOutput ) === true ) {
749- echo $ debugOutput ;
750- }
726+ unlink ($ out );
751727
752- if (isset ($ childCache ) === true ) {
753- foreach ($ childCache as $ path => $ cache ) {
754- Cache::set ($ path , $ cache );
755- }
756- }
728+ $ numProcessed ++;
757729
758- // Fake a processed file so we can print progress output for the batch.
730+ if (isset ($ childOutput ) === false ) {
731+ // The child process died, so the run has failed.
759732 $ file = new DummyFile ('' , $ this ->ruleset , $ this ->config );
760- $ file ->setErrorCounts (
761- $ childOutput ['totalErrors ' ],
762- $ childOutput ['totalWarnings ' ],
763- $ childOutput ['totalFixable ' ],
764- $ childOutput ['totalFixed ' ]
765- );
733+ $ file ->setErrorCounts (1 , 0 , 0 , 0 );
766734 $ this ->printProgress ($ file , $ totalBatches , $ numProcessed );
767- }//end if
735+ $ success = false ;
736+ continue ;
737+ }
738+
739+ $ this ->reporter ->totalFiles += $ childOutput ['totalFiles ' ];
740+ $ this ->reporter ->totalErrors += $ childOutput ['totalErrors ' ];
741+ $ this ->reporter ->totalWarnings += $ childOutput ['totalWarnings ' ];
742+ $ this ->reporter ->totalFixable += $ childOutput ['totalFixable ' ];
743+ $ this ->reporter ->totalFixed += $ childOutput ['totalFixed ' ];
744+
745+ if (isset ($ debugOutput ) === true ) {
746+ echo $ debugOutput ;
747+ }
748+
749+ if (isset ($ childCache ) === true ) {
750+ foreach ($ childCache as $ path => $ cache ) {
751+ Cache::set ($ path , $ cache );
752+ }
753+ }
754+
755+ // Fake a processed file so we can print progress output for the batch.
756+ $ file = new DummyFile ('' , $ this ->ruleset , $ this ->config );
757+ $ file ->setErrorCounts (
758+ $ childOutput ['totalErrors ' ],
759+ $ childOutput ['totalWarnings ' ],
760+ $ childOutput ['totalFixable ' ],
761+ $ childOutput ['totalFixed ' ]
762+ );
763+ $ this ->printProgress ($ file , $ totalBatches , $ numProcessed );
768764 }//end if
769- }//end foreach
765+ }//end if
770766 }//end while
771767
772768 return $ success ;
0 commit comments