php8.5
Home/ Manual/ ssh2 / functions/ ssh2_keepalive_send

ssh2_keepalive_send

PHP function Edit on GitHub ✎

(PECL ssh2 >= 1.5.0)

Send a keepalive message

Description

ssh2_keepalive_send(resource $session): int|false

Sends a keepalive message on the given session, according to the configuration set with ssh2_keepalive_config().

Note

This function is only available when the extension is built against a libssh2 version providing keepalive support.

Parameters

session

An SSH connection link identifier, obtained from a call to ssh2_connect().

Return Values

Returns the number of seconds that may pass before another keepalive message must be sent, or false on failure. 0 is returned when keepalive messages are disabled.

Since 0 and false are both falsy, the === operator has to be used to tell them apart.

Examples

Sending a keepalive message

php
<?php
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');
ssh2_keepalive_config($connection, true, 30);

$seconds = ssh2_keepalive_send($connection);

if ($seconds === false) {
    echo "The keepalive message could not be sent", PHP_EOL;
} elseif ($seconds === 0) {
    echo "Keepalive messages are disabled", PHP_EOL;
} else {
    echo "Next keepalive message due in $seconds seconds", PHP_EOL;
}
?>

See Also

Source: reference/ssh2/functions/ssh2-keepalive-send.xml · from the official PHP manual (php/doc-en)