Skip to content

Commit 2c6fbda

Browse files
authored
make timeout configurable
Long running commands (>10s) won't work with this library. This allows to set a timeout on a connection.
1 parent 4be110a commit 2c6fbda

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/SSHConnection.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class SSHConnection
1818
private $username;
1919
private $password;
2020
private $privateKeyPath;
21+
private $timeout;
2122
private $connected = false;
2223
private $ssh;
2324

@@ -51,6 +52,12 @@ public function withPrivateKey(string $privateKeyPath): self
5152
return $this;
5253
}
5354

55+
public function timeout(int $timeout): self
56+
{
57+
$this->timeout = $timeout;
58+
return $this;
59+
}
60+
5461
private function sanityCheck()
5562
{
5663
if (!$this->hostname) {
@@ -92,6 +99,10 @@ public function connect(): self
9299
}
93100
}
94101

102+
if ($this->timeout) {
103+
$this->ssh->setTimeout($this->timeout);
104+
}
105+
95106
$this->connected = true;
96107

97108
return $this;

0 commit comments

Comments
 (0)