简体   繁体   中英

phpSeclib real time output using PHP?

I am trying to get the output of a ping command using phpSeclib. I tried the examples on their official website but none of them work, they all just execute the command and display the output once done.

Is it possible to directly show the output everytime the shell changes? So everytime a new ping is done show it to the user.

It works perfectly in CLI mode, but not in the browser.

I am looking for a fully PHP solution. No AJAX or jQuery.

Thanks

From http://phpseclib.sourceforge.net/ssh/examples.html#callback :

<?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;
    flush();
    ob_flush();
}

$ssh->exec('ping 127.0.0.1', 'packet_handler');
?>

You may want to play around with flush() and ob_flush() as well.

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM