Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP读控制台输出_Php_Linux_Console - Fatal编程技术网

PHP读控制台输出

PHP读控制台输出,php,linux,console,Php,Linux,Console,好吧,事情是这样的。我需要读取输出(您通常在linux控制台中看到的输出)。我最大的问题是我不需要读取线性执行的输出,而是类似于wget的东西http://ubuntu.com/jaunty.iso并显示其预计到达时间 此外,工作流程如下所示: S-webserver C1-S内部网中的计算机1 C2-S内部网中的计算机2 等等 用户连接到S,后者连接到Cx,然后启动wget、top或其他控制台日志记录命令(应用户请求)。当wget下载指定目标时,用户可以从Cx查看“控制台日志” 这可能吗?不使

好吧,事情是这样的。我需要读取输出(您通常在linux控制台中看到的输出)。我最大的问题是我不需要读取线性执行的输出,而是类似于
wget的东西http://ubuntu.com/jaunty.iso
并显示其预计到达时间

此外,工作流程如下所示:

S
-webserver

C
1-S内部网中的计算机1

C
2-S内部网中的计算机2

等等

用户连接到
S
,后者连接到
C
x,然后启动
wget
top
或其他控制台日志记录命令(应用户请求)。当
wget
下载指定目标时,用户可以从
C
x查看“控制台日志”

这可能吗?不使用服务器/客户机软件可以完成吗


谢谢

您是否有正在处理的一些现有PHP代码

您需要为此使用php函数——您可以指定一个管道数组(stdin,如果您在控制台上,它通常会连接到键盘,std out和stderr,它们通常都会打印到显示器上)。然后,您可以控制给定程序的输入/输出流程

例如:

$pipes = array();
$pipe_descriptions = array(
   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
   2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file to write to
);

$cmd = "wget $url";

$proc_handle = proc_open($cmd, $pipe_descriptions, $pipes);

if(is_resource($proc_handle))
{
   // Your process is running. You may now read it's output with fread($pipes[1]) and fread($pipes[2])
   // Send input to your program with fwrite($pipes[0])
   // remember to fclose() all pipes and fclose() the process when you're done!

用户如何连接到服务器?SSH还是什么?用户不通过SSH连接。用户只需访问S上的一个网页。服务器通过SSH或专有服务器软件连接到其内部网中的计算机,但我对SSH选项的解决方案感兴趣。目前不,这只是开始,但如果我无法读取控制台输出,恐怕我必须切换到其他内容。哦,对于远程访问,其中S将连接到C(x),设置SSH密钥并设置“$cmd to:SSH hostname.of.C wget$url”