Skip to content

Commit 7889f8f

Browse files
authored
Merge pull request #82 from tal7aouy/tal7aouy
set timeout
2 parents 05ac5a2 + 740d804 commit 7889f8f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ Alternatively you can use the `usePort` function:
8686
```php
8787
Ssh::create('user', 'host')->usePort($port);
8888
```
89+
### Setting a timeout
90+
91+
You can set a timeout for the command.
92+
93+
94+
```php
95+
Ssh::create('user', 'host')->setTimeout(100);
96+
```
8997

9098
### Specifying a jump host
9199

src/Ssh.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ public function enableStrictHostKeyChecking(): self
9393

9494
return $this;
9595
}
96+
97+
public function setTimeout(int $timeout): self
98+
{
99+
$this->extraOptions['timeout'] = $timeout;
100+
101+
return $this;
102+
}
96103

97104
public function disableStrictHostKeyChecking(): self
98105
{
@@ -246,7 +253,7 @@ protected function run(string $command, string $method = 'run'): Process
246253
{
247254
$process = Process::fromShellCommandline($command);
248255

249-
$process->setTimeout(0);
256+
$process->setTimeout($this->extraOptions['timeout'] ?? 0);
250257

251258
($this->processConfigurationClosure)($process);
252259

@@ -266,4 +273,7 @@ protected function getTargetForSsh(): string
266273
{
267274
return "{$this->user}@{$this->host}";
268275
}
276+
277+
278+
269279
}

0 commit comments

Comments
 (0)