PHP SSH2 Class with Exception Handling

Mar 6, 2012 System Administration


In a previous role, I was responsible for running diagnostics on remote networking devices and parsing the output to gather important details on their current status and health. To keep all aspects of the code consistent, which was written in PHP, I used the SSH2 PECL module, which I was easily able to dynamically load into the PHP config.

The downside is that, there was not much error handling in this default class. Because the code was being used to support a mission critical network, that a lot of people here used on a daily basis, there was no margin for error.

Below I have included an example and the source class which adds exception handling to SSH2 for PHP.

Here’s an Example

Getting the Code

The code is hosted in a Gist, which we have included below:

comments powered by Disqus