From b94d55a73438ad40c0bcf55cf85f89f7c3fc2b63 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 1 Aug 2024 12:14:33 -0400 Subject: [PATCH] Use the default socket timeout in absence of more specific user-defined value --- phpseclib/Net/SSH2.php | 6 +++--- tests/Unit/Net/SSH2UnitTest.php | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 0c096d76..521d76a8 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -2747,7 +2747,7 @@ class SSH2 * Set Timeout * * $ssh->exec('ping 127.0.0.1'); on a Linux host will never return and will run indefinitely. setTimeout() makes it so it'll timeout. - * Setting $timeout to false or 0 will mean there is no timeout. + * Setting $timeout to false or 0 will revert to the default socket timeout. * * @param mixed $timeout */ @@ -3462,11 +3462,11 @@ class SSH2 } /** - * @return int[] second and microsecond stream timeout options based on user-requested timeout and keep-alive, 0 by default + * @return int[] second and microsecond stream timeout options based on user-requested timeout and keep-alive, or the default socket timeout by default, which mirrors PHP socket streams. */ private function get_stream_timeout() { - $sec = 0; + $sec = ini_get('default_socket_timeout'); $usec = 0; if ($this->curTimeout > 0) { $sec = (int) floor($this->curTimeout); diff --git a/tests/Unit/Net/SSH2UnitTest.php b/tests/Unit/Net/SSH2UnitTest.php index d8d3951d..c4a58c0b 100644 --- a/tests/Unit/Net/SSH2UnitTest.php +++ b/tests/Unit/Net/SSH2UnitTest.php @@ -228,9 +228,10 @@ class SSH2UnitTest extends PhpseclibTestCase */ public function testGetStreamTimeout() { + $default = ini_get('default_socket_timeout'); // no curTimeout, no keepAlive $ssh = $this->createSSHMock(); - $this->assertEquals([0, 0], self::callFunc($ssh, 'get_stream_timeout')); + $this->assertEquals([$default, 0], self::callFunc($ssh, 'get_stream_timeout')); // curTimeout, no keepAlive $ssh = $this->createSSHMock();