Skip to content

Commit 6d5dcae

Browse files
authored
Merge pull request #8 from sboesch/configurable-timeout
Configurable timeout
2 parents 4be110a + b5edf99 commit 6d5dcae

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ $connection = (new SSHConnection())
2424
->as('demo')
2525
->withPassword('password')
2626
// ->withPrivateKey($privateKeyPath)
27+
// ->timeout(0)
2728
->connect();
2829

2930
$command = $connection->run('echo "Hello world!"');

src/SSHConnection.php

+11
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)