我有一个连接到 unix 服务器的 php 脚本,并运行一个 shell 脚本,其中包含该脚本从 html 表单获取的参数。当我在 cli 中运行它时,输出还可以,但是当通过 web 表单运行时,输出在一条累积线中
剧本:
<?php
$alarm = $_POST["fname"];
require_once "PHPTelnet.php";
$telnet = new PHPTelnet();
// if the first argument to Connect is blank,
// PHPTelnet will connect to the local host via 127.0.0.1
$result = $telnet->Connect('host','user','pass');
if ($result == 0) {
$telnet->DoCommand('/home/scripts/find_alarm.sh', $result);
// NOTE: $result may contain newlines
echo "<pre>";
echo $result;
//ob_flush();
echo "</pre>";
$telnet->DoCommand("$alarm", $result);
echo "<pre>";
echo $result;
echo "</pre>";
sleep(10);
$telnet->DoCommand('exit', $result);
echo $result;
// say Disconnect(0); to break the connection without explicitly logging out
//$telnet->Disconnect();
}
?>