简体   繁体   English

phpSeclib使用PHP实时输出?

[英]phpSeclib real time output using PHP?

I am trying to get the output of a ping command using phpSeclib. 我正在尝试使用phpSeclib获取ping命令的输出。 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? 每次shell更改时是否可以直接显示输出? So everytime a new ping is done show it to the user. 因此,每次完成新的ping操作后,就会向用户显示。

It works perfectly in CLI mode, but not in the browser. 它可以在CLI模式下完美运行,但不能在浏览器中运行。

I am looking for a fully PHP solution. 我正在寻找一个完整的PHP解决方案。 No AJAX or jQuery. 没有AJAX或jQuery。

Thanks 谢谢

From http://phpseclib.sourceforge.net/ssh/examples.html#callback : 来自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. 您可能还希望同时使用flush()ob_flush()

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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