I'm using PHP's ssh2 PECL extension to issue shell commands to a number of different servers in an automated fashion.
On each iteration of a loop, I create a new instance of my SSH2 class, open a new SSH connection using ssh2_connect(), and issue a command to one of any number of servers. Once the response is received, I disconnect (by issuing the "exit;" command via ssh2_exec()) and unset the variable that points to the SSH2 class instance. This has worked quite well in the past, and I was able to issue several thousand commands without issue.
But, as of late, I've introduced an issue that is causing PHP to report:
Warning: ssh2_auth_pubkey_file(): Authentication failed for my-user-name using public key in file.php on line XXX
This begins to happen after some 600 iterations of the loop have already completed.
After this warning is issued, I receive another: "Too many open files". Once these two warnings occur the first time, they both occur on every attempt thereafter until the loop has run its course.
As far as I'm aware, I'm not opening any file handles (e.g., via fopen() and family), so I'm not sure what the second warning is about.
I'm almost thinking that the limit, whatever it may be, is being reached on the remote side, e.g., I have too many SSH connections open to the remote host, and the remote host refuses additional connections.
Within each iteration of the loop, I'm checking if some files exist, e.g.:
if (file_exists('ssh2.sftp://' . $ssh->getSftp() . $fileName)) {
}
//where $ssh->getSftp() = ssh2_sftp($this->con) and $this->con = ssh2_connect($this->host, $this->port, array('hostkey', 'ssh-rsa'));
Does anything jump-out at anyone?
Thanks in advance for any insights!