0

I created a multi-server situation, where I'm copying files over SSH2 from the master server to a few slave servers.

I'm using PHP SSH2 with and although it works well, I don't understand why I don't need to CLOSE the connection. Nowhere in the PHP documentation (PHP NET) there's any mention of that.

Am I somehow going to be hogging resources or connections or something?

The code I'm using now is:

foreach ($hosts as $host) {
  $conn = ssh2_connect($host, 22, array('hostkey'=>'ssh-rsa'));

   ssh2_auth_pubkey_file(
      $conn,
      "transfer",
      '/home/transfer/.ssh/rsa_id.pub',
      '/home/transfer/.ssh/rsa_id'
   );
   foreach ($files as $file) ssh2_scp_send($conn, $file, $file, 0644);
}
user1914292
  • 1,586
  • 13
  • 38
  • PHP garbage collection will close the connection, probably just by closing the socket (this is fine). You would need use the close method if you a) wanted to open subsequent connection(s), or b) had a long running CLI process where you were concerned about memory leaks. – StigM Nov 17 '13 at 07:59
  • 1
    You should use: ssh2_exec($connection, 'exit'); unset($connection); According to: http://stackoverflow.com/questions/5820089/disconnect-from-ssh2-connect – MaD Nov 17 '13 at 08:30
  • awesome - thanks! I thought I had searched well enough, but I guess I didn't – user1914292 Nov 17 '13 at 10:28

0 Answers0