@@ -106,11 +106,7 @@ public static function start(
106106 self ::$ pharCopy = \sys_get_temp_dir () . "/phar- " . \bin2hex (\random_bytes (10 )) . ".phar " ;
107107 \copy (\Phar::running (false ), self ::$ pharCopy );
108108
109- \register_shutdown_function (static function (): void {
110- if (self ::$ pharCopy !== null ) {
111- @\unlink (self ::$ pharCopy );
112- }
113- });
109+ \register_shutdown_function (static fn () => self ::unlinkExternalCopy (self ::$ pharCopy ));
114110
115111 $ path = "phar:// " . self ::$ pharCopy . "/ " . \substr ($ path , \strlen (\Phar::running (true )));
116112 }
@@ -121,11 +117,7 @@ public static function start(
121117 self ::$ pharScriptPath = $ scriptPath = \sys_get_temp_dir () . "/amp-process-runner- " . $ suffix . ".php " ;
122118 \file_put_contents ($ scriptPath , $ contents );
123119
124- \register_shutdown_function (static function (): void {
125- if (self ::$ pharScriptPath !== null ) {
126- @\unlink (self ::$ pharScriptPath );
127- }
128- });
120+ \register_shutdown_function (static fn () => self ::unlinkExternalCopy (self ::$ pharScriptPath ));
129121 }
130122
131123 // 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(
176168 return new self ($ process , $ ipcChannel , $ resultChannel );
177169 }
178170
171+ private static function unlinkExternalCopy (?string $ filepath ): void
172+ {
173+ if ($ filepath === null ) {
174+ return ;
175+ }
176+
177+ \set_error_handler (static fn () => true );
178+ try {
179+ \unlink ($ filepath );
180+ } finally {
181+ \restore_error_handler ();
182+ }
183+ }
184+
179185 /**
180186 * @return non-empty-list<string>
181187 */
0 commit comments