phpseclib in a function (multiple)

Get help with using the PHP Secure Communications Library.

Moderator: Nuxius

Forum rules
The purpose of this forum is to provide support for phpseclib, a pure PHP SSH / SFTP / RSA library.

Posts by new users are held in a moderation queue and are not publicly visible until the post is approved.

phpseclib in a function (multiple)

Postby H.Murdock » Tue Oct 08, 2013 1:28 am


I'm trying to get phpseclib into a function to get multipe informations about multiple machines.

This is my php function:

Code: Select all
function groesse($ip, $user, $pw){


$ssh = new Net_SSH2($ip);
if (!$ssh->login($user, $pw)) {
    echo "Login Failed";

$speicher = $ssh->exec('speicher=`df -h` && set -- $speicher && echo "$9"');

echo $speicher;


And i am able to call my function once with "<?PHP groesse('192.xx.xx.1', 'admin', 'admin'); ?>" but i have multiple machines i want to check with.

so 1st: <?PHP groesse('192.xx.xx.1', 'admin', 'admin'); ?>
and 2nd: <?PHP groesse('192.xx.xx.2', 'admin', 'admin'); ?>
and so on...

How is that possible? It always just gives me the information for the first one and the next does not show up anyting.
Posts: 1
Joined: Tue Oct 08, 2013 1:18 am

Re: phpseclib in a function (multiple)

Postby TerraFrost » Wed Oct 09, 2013 8:14 pm

Sorry for the delay - been busy at work.

Anyway, try taking the include() out of the function and putting it at the beginning of the file. Or do include_once.

Either way it's including Net/SSH2.php multiple times and on the second time you're getting a fatal error because it's trying to create an object that's already been created.
Legendary Guard
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Return to phpseclib support

Who is online

Users browsing this forum: No registered users and 1 guest