I have a PHP CLI daemon which is sending files via SFTP regularily to a flaky server, and before I fix the server I want to implement error handling in my script.
After logging in succesfully, I run this command and it works about 70% of the time:
if ($sftp->put("/home/whatever/$name","$local_path"))
{
print "no problem\n";
} else {
print "is problem\n";
}
I don't care if connection doesn't work, because I can make my daemon try again, BUT the problem is that I get these errors and then my daemon just dies:
PHP Notice: Connection closed by server in /usr/share/pear/Net/SSH2.php on line 1009
Notice: Connection closed by server in /usr/share/pear/Net/SSH2.php on line 1009
the "is problem" message never appears, program just dies.
How can I detect when I get connection close without script dying?