title: PHP Show Real Time Shell Output within HTML
body: <p>I have a shell file shell.sh that echo hi every 1 second. I would like to display the real time output of my shell script on my website in a box.</p>
  
  <p>However, the problem is that, my code doesn't show the output in a box. And when I click on it, everything disappears and I just see a white page.</p>
  
  <p>The following is my php file.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form method="GET" action="splitter.php"&gt;
          &lt;label for="folderPath"&gt;Folder Path:&lt;/label&gt;
          &lt;input type="text" id="folderPath" name="folderPath"&gt;
      &lt;br&gt;&lt;/br&gt;
          &lt;fieldset id="khz"&gt;
              &lt;p&gt;Please Choose Khz: &lt;/p&gt;
            &lt;input type="radio" value="8khz" name="khz"&gt; 8khz &lt;br&gt;
            &lt;input type="radio" value="16khz" name="khz"&gt; 16khz &lt;br&gt;
          &lt;/fieldset&gt;
      &lt;br&gt;&lt;/br&gt;
          &lt;fieldset id="audio-type"&gt;
              &lt;p&gt;Please Choose Type: &lt;/p&gt;
            &lt;input type="radio" value="C12" name="group2"&gt; Channel 1 &amp; 2 &lt;br&gt;
            &lt;input type="radio" value="LR" name="group2"&gt; Left to Right &lt;br&gt;
          &lt;/fieldset&gt;
          &lt;div class="spaceh10"&gt;&lt;/div&gt;
          &lt;input class = "submitButton" type="submit" value="Submit"&gt;
  
      &lt;div class="spaceh10"&gt;&lt;/div&gt;
      &lt;div style="width:500px;height:100px;border:1px solid #000;"&gt;
      &lt;?php
      if (isset($_GET['folderPath']) &amp;&amp; !empty($_GET['folderPath']) &amp;&amp; 
      isset($_GET['khz']) &amp;&amp; isset($_GET['group2'])) {
  
      $folderPath = $_GET['folderPath'];
      $khz = $_GET['khz'];
      $group2 = $_GET['group2'];
      #$folderPath $khz $group2
      $command = './shell.sh';
      while (@ ob_end_flush()); // end all output buffers if any
  
      $proc = popen($command, 'r');
      echo '&lt;pre&gt;';
      while (!feof($proc)){
          echo fread($proc, 4096);
          @ flush();
      }
      echo '&lt;/pre&gt;';
      }
      ?&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and below is my shell script</p>
  
  <pre><code>while true
  do 
      echo "Hi"
      sleep 1
  done
  </code></pre>
  
  <p>How do I make my code run in the box? And make sure the outputs just stay in the box and doesn't overflow. Why doesn't my code show the output?</p>
  
  <p>I am monitoring the server address which my php file is running. And when I click submit it loads forever on a white screen and since I know it's not gonna end I stop within the browser.
  and I get the following error.</p>
  
  <pre><code>./shell.sh: line 6: echo: write error: Broken pipe
  </code></pre>
  
  <p>How can I show my real time shell output in a box? and it doesn't outflow the box border?</p>