diff --git a/src/Context/Internal/process-runner.php b/src/Context/Internal/process-runner.php index 595d929..d10a60f 100644 --- a/src/Context/Internal/process-runner.php +++ b/src/Context/Internal/process-runner.php @@ -13,7 +13,12 @@ // Doesn't exist in phpdbg... if (\function_exists("cli_set_process_title")) { - @\cli_set_process_title("amp-process"); + \set_error_handler(static fn () => true); + try { + \cli_set_process_title("amp-process"); + } finally { + \restore_error_handler(); + } } (function (): void { diff --git a/src/Context/ProcessContext.php b/src/Context/ProcessContext.php index 011b4ae..2b62ac8 100644 --- a/src/Context/ProcessContext.php +++ b/src/Context/ProcessContext.php @@ -106,11 +106,7 @@ public static function start( self::$pharCopy = \sys_get_temp_dir() . "/phar-" . \bin2hex(\random_bytes(10)) . ".phar"; \copy(\Phar::running(false), self::$pharCopy); - \register_shutdown_function(static function (): void { - if (self::$pharCopy !== null) { - @\unlink(self::$pharCopy); - } - }); + \register_shutdown_function(static fn () => self::unlinkExternalCopy(self::$pharCopy)); $path = "phar://" . self::$pharCopy . "/" . \substr($path, \strlen(\Phar::running(true))); } @@ -121,11 +117,7 @@ public static function start( self::$pharScriptPath = $scriptPath = \sys_get_temp_dir() . "/amp-process-runner-" . $suffix . ".php"; \file_put_contents($scriptPath, $contents); - \register_shutdown_function(static function (): void { - if (self::$pharScriptPath !== null) { - @\unlink(self::$pharScriptPath); - } - }); + \register_shutdown_function(static fn () => self::unlinkExternalCopy(self::$pharScriptPath)); } // Monkey-patch the script path in the same way, only supported if the command is given as array. @@ -176,6 +168,20 @@ public static function start( return new self($process, $ipcChannel, $resultChannel); } + private static function unlinkExternalCopy(?string $filepath): void + { + if ($filepath === null) { + return; + } + + \set_error_handler(static fn () => true); + try { + \unlink($filepath); + } finally { + \restore_error_handler(); + } + } + /** * @return non-empty-list */