Joe Huss

Generation

class from descriptionThu, 19 Jan 2023

create an ssh class for maintaining a pool of ssh connections and running commands on them in parallel via a queue

class ssh { private $pool = array(); private $queue = array(); public function add($host, $user, $pass) { $ssh = new Net_SSH2($host); if (!$ssh->login($user, $pass)) { exit('Login Failed'); } $this->pool[] = $ssh; } public function exec($cmd) { $this->queue[] = $cmd; } public function run() { $pool = $this->pool; $queue = $this->queue; while (count($pool) && count($queue)) { foreach ($pool as $key => $ssh) { $cmd = array_shift($queue); $ssh->exec($cmd); unset($pool[$key]); } } } } $ssh = new ssh; $ssh->add('1.1.1.1', 'user', 'pass'); $ssh

Questions about programming?Chat with your personal AI assistant