@@ -376,25 +376,29 @@ private function getServerPid(): int {
376376 );
377377 }
378378
379- /**
380- * Parse command
381- *
382- * Have commands that need to be executed as sudo otherwise don't will work,
383- * by example the command runuser or kill. To prevent error when run in a
384- * GitHub Actions, these commands are executed prefixed by sudo when exists
385- * an environment called GITHUB_ACTIONS.
386- */
387- private function parseCommand (string $ command ): string {
388- if (getenv ('GITHUB_ACTIONS ' ) !== false ) {
389- $ command = 'sudo ' . $ command ;
390- }
391- return $ command ;
392- }
393-
394379 private function stopIfRunning (): void {
395- $ pid = $ this ->getServerPid ();
396- if ($ pid > 0 ) {
397- exec ($ this ->parseCommand ('kill -9 ' . $ pid ));
380+ $ uri = $ this ->getCfsslUri ();
381+ $ port = (int )(parse_url ($ uri , PHP_URL_PORT ) ?? 0 );
382+ $ this ->processManager ->setSourceHint (self ::PROCESS_SOURCE , [
383+ 'uri ' => $ uri ,
384+ 'port ' => $ port ,
385+ ]);
386+
387+ $ this ->processManager ->findRunningPid (
388+ self ::PROCESS_SOURCE ,
389+ fn (array $ entry ): bool => ($ entry ['context ' ]['uri ' ] ?? '' ) === $ uri ,
390+ );
391+
392+ foreach ($ this ->processManager ->listRunning (self ::PROCESS_SOURCE ) as $ entry ) {
393+ if (($ entry ['context ' ]['uri ' ] ?? '' ) !== $ uri ) {
394+ continue ;
395+ }
396+
397+ $ pid = (int )($ entry ['pid ' ] ?? 0 );
398+ if ($ pid <= 0 ) {
399+ continue ;
400+ }
401+ $ this ->processManager ->stopPid ($ pid , SIGKILL );
398402 $ this ->processManager ->unregister (self ::PROCESS_SOURCE , $ pid );
399403 }
400404 }
0 commit comments