Skip to content

Commit 144d0a6

Browse files
authored
Merge pull request #180 from open-runtimes/fix-catch-runtime-exception-tcp-check
fix: catch runtime execption tcp check
2 parents ec12e3d + 7ff48c9 commit 144d0a6

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

src/Executor/Validator/TCP.php

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,31 @@ public function getType(): string
2929
{
3030
return self::TYPE_STRING;
3131
}
32+
3233
public function isValid(mixed $value): bool
3334
{
34-
$value = \strval($value);
35-
[ $ip, $port ] = \explode(':', $value);
36-
$port = \intval($port);
37-
38-
if (empty($port) || empty($ip)) {
39-
return false;
40-
}
41-
42-
// TCP Ping
43-
$errorCode = null;
44-
$errorMessage = "";
45-
$socket = @\fsockopen($ip, $port, $errorCode, $errorMessage, $this->timeout); // @ prevents warnings (Unable to connect)
46-
47-
if (!$socket) {
35+
try {
36+
$value = \strval($value);
37+
[ $ip, $port ] = \explode(':', $value);
38+
$port = \intval($port);
39+
40+
if (empty($port) || empty($ip)) {
41+
return false;
42+
}
43+
44+
// TCP Ping
45+
$errorCode = null;
46+
$errorMessage = "";
47+
$socket = @\fsockopen($ip, $port, $errorCode, $errorMessage, $this->timeout); // @ prevents warnings (Unable to connect)
48+
49+
if (!$socket) {
50+
return false;
51+
} else {
52+
\fclose($socket);
53+
return true;
54+
}
55+
} catch (\RuntimeException) {
4856
return false;
49-
} else {
50-
\fclose($socket);
51-
return true;
5257
}
5358
}
5459
}

0 commit comments

Comments
 (0)