Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

threads blowfish error #442

Closed
ghost opened this issue Apr 27, 2015 · 3 comments
Closed

threads blowfish error #442

ghost opened this issue Apr 27, 2015 · 3 comments

Comments

@ghost
Copy link

ghost commented Apr 27, 2015

when i try to use this code...

<?php
include_once('Net\SSH2.php');

class AsyncOperation extends Thread {

    public function __construct($sshSession) {
        $this->u = 'user';
        $this->p = 'pass';
        $this->sshSession = $sshSession;

    }
   public function run() {
        $ssh = $this->sshSession;
    if (!$ssh->login($this->u, $this->p)) {
        exit('Login Failed');
    }
    echo "<pre>";
    echo $ssh->read('# ');
    $ssh->write('show version'."\n");
    echo "</pre>";
    $ssh->disconnect();
    }
}

$devices = '82.2.1.4';
$stack = array();
$dev_explode = explode(' ', $devices);

// Create threads
foreach ($dev_explode as $ip) {
    $sshSess = new Net_SSH2($ip);
    $stack[] = new AsyncOperation($sshSess);
}

// Start The Threads
foreach ( $stack as $t ) {
    $t->start();
}

// Wait for them
foreach ( $stack as $t1 ) {
    $t1->join();
}

echo "All done.<br>";

i receive:
Warning: Missing argument 1 for Crypt_Blowfish::Crypt_Blowfish(), called in D:\xampp-5-5\htdocs\user\Net\SSH2.php on line 1529 and defined in D:\xampp-5-5\php\pear\Crypt\Blowfish.php on line 94

Strict Standards: Non-static method PEAR::raiseError() should not be called statically, assuming $this from incompatible context in D:\xampp-5-5\php\pear\Crypt\Blowfish.php on line 255
Key must be a string All done.

I think thread does not know where is the key or smth. I tried also to create Net_SSH2 object inside run() but then i reached some other interesting error. So the question is - Is this approach of passing object to the thead constructor the best i can use or no and any advice should be appreciated. The other question is - Is there any good chanse to make phpseclib and pthreads work together?

@nogrp
Copy link

nogrp commented Apr 27, 2015

You should pass only the data to thread's constructor and any action related to autoloading or constructing objects that cannot be serialized must be done in thread's run method. What was the other error you got?

Basically, both file include and creating the Net_SSH2($ip) should be done in thread's run. You can make phpseclib work the same way. If you use composer to load phpseclib, include Composer's autoload.php in run and construct objects there.

@hrantly
Copy link

hrantly commented Apr 27, 2015

@BNikola You are absolutely correct. Thank you very much! 👍
Working now. Issue can be closed.

@nogrp
Copy link

nogrp commented Apr 28, 2015

I'm glad it works, good luck! :)

@krakjoe krakjoe closed this as completed Apr 29, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants