Print ubuntu server prints into a div real-time

Viewed 58

What I'm trying to achieve have the information printing in the terminal window to print into a html div in real time as its occurring. Currently I have a php execute setup with ajax to post/get. When you click the button, the action will send a script call to the server and bring the information back as a whole request. Some scripts run for a while so the response back takes forever. I wanted to find a way to print server prints real-time to that div instead of returning when completed.

This is the index.php

function tests() {
    send_data = "script";
    $.ajax({
        type: "POST",
        url: "html/results.php",
        data: {
            send_data: send_data
        },
        success: function (data) {
            alert("Success Finish!");
            $("#results").html(data);
        },
        error: function (data) {
            alert("Data sending failed");
        }
    });
}
$('.dropdown-menu li span').on({
    "click": function (e) {
        e.stopPropagation();
    }
});

This is the results page

<?php
    $temp = $_POST["send_data"];

    $handle = popen($temp, 'r');
    while (!feof($handle)) {
        echo fgets($handle);
        flush();
        ob_flush();
    }
    pclose($handle);
?>    
0 Answers
Related