怎样把服务器上的ping命令运行过程在web页面中动态展示
本帖最后由 plumdavid 于 2013-07-20 12:10 编辑想在PHP中调用服务器(linux系统)上的ping命令,把ping的返回过程在web页面中,有什么办法实现吗?
如:$ ping www.sina.com
PING cernetnews.sina.com.cn (121.194.0.239) 56(84) bytes of data.
64 bytes from 121.194.0.239: icmp_seq=1 ttl=59 time=0.391 ms
64 bytes from 121.194.0.239: icmp_seq=2 ttl=59 time=0.385 ms
64 bytes from 121.194.0.239: icmp_seq=3 ttl=59 time=0.459 ms
64 bytes from 121.194.0.239: icmp_seq=4 ttl=59 time=0.331 ms
64 bytes from 121.194.0.239: icmp_seq=5 ttl=59 time=0.600 ms
64 bytes from 121.194.0.239: icmp_seq=6 ttl=59 time=0.486 ms
64 bytes from 121.194.0.239: icmp_seq=7 ttl=59 time=0.491 msping命令返回记录是不断添加的,在web页面中也要达到这样效果
可以考虑用libevent 本帖最后由 plumdavid 于 2013-07-20 17:37 编辑
回复 2# bikong0411
好高端,我看看先。 本帖最后由 幽烛 于 2013-07-30 17:29 编辑
function do_command($commandName, $args)
{
$buffer = "";
if (false === ($command = find_command($commandName))) return false;
if ($fp = @popen("$command $args", 'r'))
{
while (!@feof($fp))
{
$buffer .= @fgets($fp, 4096);
}
@pclose($fp);
return trim($buffer);
}
return false;
}
function find_command($commandName)
{
$path = array('/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin');
foreach($path as $p)
{
if (@is_executable("$p/$commandName")) return "$p/$commandName";
}
return false;
} 回复 4# 幽烛
大侠,你这是查找文件?
我想把ping命令的终端输出在web页面里展示,你的代码能实现吗? 研究一下Ajax能否实现。普通后台脚本程序,一次执行就结束了。 回复 6# Cyberman.Wu
我用ajax实现了,但比较复杂,具体方法如下:
ping命令写入文件中,使用ajax调用文件数据在web页面中.
实现是实现了,但文本\linux命令\php语言之间的耦合度太高了,代码可维护性不高.
哎~~看来楼主还没看懂代码:dizzy:
回复 7# plumdavid
回复 8# 幽烛
长知识了.
虽然你算法中用到的一些函数我不熟悉,但你的思路我明白了,多谢. 学习了,幽烛的代码有点像网页画图的做法。