php - phpseclib - exit callback? -
i'm using code ssh2 examples:
<?php include('net/ssh2.php'); $ssh = new net_ssh2('www.domain.tld'); if (!$ssh->login('username', 'password')) { exit('login failed'); } function packet_handler($str) { echo $str; } $ssh->exec('ping 127.0.0.1', 'packet_handler'); ?>
this working well, want quit stream after xx seconds.
so i've amended follows :
<?php include('net/ssh2.php'); $st = time(); $dur = 10; $ssh = new net_ssh2('www.domain.tld'); if (!$ssh->login('username', 'password')) { exit('login failed'); } function packet_handler($str) { global $st, $dur, $ssh; echo $str; $now = ceil(time() - $st); if ($now >= $dur) { $ssh->disconnect(); unset($ssh); } } $ssh->exec('ping 127.0.0.1', 'packet_handler'); ?>
this works , exits packet handler, folllowing notices being shown:
notice: connection closed prematurely in ssh2.php on line 2676
notice: connection closed server in ssh2.php on line 2959
can advise how can close connection without notice messages?
you can either ignore notices, prevent them displaying php.ini or go without callback, using php sleep(x)
seconds , that's it.
$ssh->enablepty(); $ssh->exec("ping 127.0.0.1"); //run ping sleep(3); // sleep 3 seconds $ssh->write("\x03"); //send ctrl+c terminate ping command print $ssh->read(); // dump output $ssh->disconnect(); unset($ssh); //disconnect
Comments
Post a Comment