Reputation: 1853
I am trying to handle this connection error in a more graceful way than the default API. The default API will print an error message, but I would like to suppress it and replace it with my own somehow, recognize the error and handle it, but I am not sure how to do so.
public function __construct($host)
{
// trying to test by opening a failed connection -- try catch
// block doesn't work because no exception thrown
$this->connection = new Net_SFTP("nonexistent.domain.com");
// this will not work either ....
if ( !$this->connection->status_codes )
{
throw new Exception("Could not create SFTP connection.\n");
}
else
{
echo "Connected via SFTP to " . $host . " on port 22.\n";
}
}
Executing it will show that, even though there is an error, it hits the else block:
PHP Notice: Cannot connect to nonexistent.domain.com. Error 0. php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/dylan/Documents/php/Net/SSH2.php on line 788
Connected via SFTP to gluon.exavault.com on port 22.
I have been looking around at the class in the Net/SFTP.php
file, but I can't seem to find a way to process the error code and ignore the error message. Does anyone have any ideas on another possible solution?
Upvotes: 1
Views: 1367