简体   繁体   English

从ssh实时输出使用php运行

[英]Having real time output from ssh run with php

I'm trying to write what is essentially an interactive ssh system with php, I need to have php execute commands on a remote server with ssh_exec or shell and gather the output from the command in real time. 我试图用php编写本质上是一个交互式ssh系统,我需要让php在带有ssh_exec或shell的远程服务器上执行命令,并实时收集命令的输出。

I've messed about with output buffering and flush() until I'm blue in the face and am about to have the command redirect its output to file and have a separate script that polls the contents of this file with sftp and uses jquery to update an output div on page. 我一直在困扰着输出缓冲和flush(),直到脸色发青,即将使命令将其输出重定向到文件,并有一个单独的脚本用sftp轮询该文件的内容并使用jquery更新页面上的输出div。

Just before I go down this long winded route, does anyone have a solution that works using a single script? 就在我走这条漫长的路线之前,没有人有使用单个脚本工作的解决方案吗?

Thanks! 谢谢!

There is no such thing as this working reliably with a single script: You have little control over buffering on the server side - flush() might or might not work as expected, depending on wether you use mod_php , CGI , FCGI or whatever, and you have absolutely no control over buffering at the client (IE is notorious here). 没有哪个事情可以通过单个脚本可靠地工作:您对服务器端的缓冲几乎没有控制权-flush flush()可能会或可能无法按预期工作,这取决于您是否使用mod_phpCGIFCGI或其他任何方式,并且您绝对无法控制客户端的缓冲(IE在这里臭名昭著)。

Been there, done that, did it with AJAX. 到那里,用AJAX完成它。

Will something like the following not work? 像下面这样的东西行不通吗?

$output = shell_exec($theScript);
file_put_contents($someFile, $output, FILE_APPEND);

Or have I got the wrong end of the stick? 还是我错了根?

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

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