Jump to content

Text Data Streaming


Recommended Posts

Here's what I have so far as for implementation:

popuptest.html

<html>
<head>
<title>Popup Window Test: Main Window<title>
<script type="text/javascript" language="JavaScript">
function openwindow()
{
var feats;
feats = "resizeable=1,scrollbars=1,width=689,height=728";
window.open("/test/popupnew.html", "Popup Window", feats);
}
</script>

</head>
<body>
Click button for large data download.
<input type="button" value="Click ME!" onclick="openwindow()">
</body>
</html>

popupnew.html

<html>
<head>
<title>Popup Test: New Window</title>
<script type="text/javascript" language="JavaScript">


var objxml;


// Creates and returns a new communications object, if available.
function get_comm_obj()
{
var serverObject;
serverObject = false;
try
{
serverObject = new XMLHttpRequest();
}
catch(err)
{
try
{
serverObject = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(err)
{
try
{
serverObject = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (err)
{
}
}
}
return(serverObject);
}


// Called when the response state has changed.
function stateChanged()
{
var txtdata;
if (objxml.readyState == 4)
{
txtdata = document.getElementById("xx0923");
txtdata.value = objxml.responseText;
//alert(objxml.responseText);
}
}


// Request data from the server.
function get_data()
{
var url;
url = "/test/genchar.php";
objxml.onreadystatechange = stateChanged;
objxml.open("GET", url, true);
objxml.send(null);
}


// Onload function.
function comm_start()
{
var xs1;
var xs2;
objxml = get_comm_obj()
if (objxml == false)
{
return (false);
}
get_data();
}


</script>
</head>
<body onload="comm_start()">
<textarea id="xx0923" rows="40" cols="80">
</textarea>
</body>
</html>

genchar.php

<?php

$datalist="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefgjihklmnopqestuvwxyz0123456789+=";
$dcount = strlen($datalist) - 1;

while(true)
{
$t = "";
for ($i = 0; $i < 78; $i++)
{
$t = $t . $datalist[mt_rand(0, $dcount)];
}
print $t . "\n";
}


?>

It does work for the most part, except that all the data is buffered before it is displayed. So if you have LOTS of data coming in from the server, nothing shows up until the connection closes, and that can take awhile. What I want to do is have the client display the data as the server streams it, since some of the commands that are being run are external to php in shell scripts. Any ideas?

Link to comment
Share on other sites


  • 5 weeks later...

Web browsers show content as they receive it. If a long period of time is going on before you see anything, then chances are as ReDucTor mentioned, that your content is being buffered on the server.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...