mirror of
https://github.com/danog/parallel.git
synced 2024-11-26 12:24:40 +01:00
parent
53aa422eaf
commit
c73c6d0a77
@ -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
|
||||
|
@ -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 () {
|
||||
|
Loading…
Reference in New Issue
Block a user