diff --git a/lib/Context/Internal/ProcessHub.php b/lib/Context/Internal/ProcessHub.php index a7bb726..5952d3d 100644 --- a/lib/Context/Internal/ProcessHub.php +++ b/lib/Context/Internal/ProcessHub.php @@ -30,6 +30,9 @@ class ProcessHub /** @var Deferred[] */ private $acceptor = []; + /** @var string|null */ + private $toUnlink; + public function __construct() { $isWindows = \strncasecmp(\PHP_OS, "WIN", 3) === 0; @@ -37,7 +40,10 @@ class ProcessHub if ($isWindows) { $this->uri = "tcp://127.0.0.1:0"; } else { - $this->uri = "unix://" . \tempnam(\sys_get_temp_dir(), "amp-parallel-ipc-") . ".sock"; + $suffix = \bin2hex(\random_bytes(10)); + $path = \sys_get_temp_dir() . "/amp-parallel-ipc-" . $suffix . ".sock"; + $this->uri = "unix://" . $path; + $this->toUnlink = $path; } $this->server = \stream_socket_server($this->uri, $errno, $errstr, \STREAM_SERVER_BIND | \STREAM_SERVER_LISTEN); @@ -88,6 +94,9 @@ class ProcessHub { Loop::cancel($this->watcher); \fclose($this->server); + if ($this->toUnlink !== null) { + @\unlink($this->toUnlink); + } } public function getUri(): string diff --git a/lib/Context/Process.php b/lib/Context/Process.php index cda4f6a..b37fe6b 100644 --- a/lib/Context/Process.php +++ b/lib/Context/Process.php @@ -109,7 +109,8 @@ final class Process implements Context $contents = \file_get_contents(self::SCRIPT_PATH); $contents = \str_replace("__DIR__", \var_export($path, true), $contents); - self::$pharScriptPath = $scriptPath = \tempnam(\sys_get_temp_dir(), "amp-process-runner-"); + $suffix = \bin2hex(\random_bytes(10)); + self::$pharScriptPath = $scriptPath = \sys_get_temp_dir() . "/amp-process-runner-" . $suffix . ".php"; \file_put_contents($scriptPath, $contents); \register_shutdown_function(static function () {