User:Woozle/two-way http

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Jump to navigation Jump to search

This is mainly a quick tabdump of pages I had open while trying to figure out how to let a server push updates to a web browser, as described here:


This didn't work (in .htaccess): ProxyPass /meteor http://localhost:3000 ProxyPassReverse /meteor http://localhost:3000

This does work, for the front end: <php>

$out = '

Hello Cruel World


$out .= <<<__END__

<script> console.log("GOT TO HERE");

 var ctMain = document.getElementById('main');
 ctMain.innerHTML = "Fetching page...

// req.onload = function (event) {

 function evPageLoaded(event) {
   ctMain.innerHTML = req.responseText + 'L';
 function evPageUpdate(event) {
   ctMain.innerHTML = req.responseText + 'U';
 function evPageFailed(event) {
   ctMain.innerHTML = req.responseText + 'Houston, we have a problem.';
 function evPageKilled(event) {
   ctMain.innerHTML = req.responseText + 'Cancelled';
 var req = new XMLHttpRequest();
 req.addEventListener("progress", evPageUpdate);
 req.addEventListener("load", evPageLoaded);

// req.addEventListener("error", transferFailed); // req.addEventListener("abort", transferCanceled);

//'get', '', true); //'get', '', true);'get', '', true);

</script> __END__; return $out; </php>

This gets dumped all at once when sent via Apache, but displays incrementally via CLI: <php> if (ob_get_level() == 0) ob_start();

//header('Content-Type: Multipart/mixed; boundary="___BOUNDARY___";'); header('Content-Type: multipart/x-mixed-replace; boundary="___BOUNDARY___";');

echo "\n"; echo "___BOUNDARY___\n"; echo "Content-Type: text/html; charset=utf-8\n"; echo "\n";

for ($count = 1; $count <= 10; $count++) {

   echo "\n";
   echo "___BOUNDARY___\n";
   echo "Content-Type: text/html; charset=utf-8\n";
   echo "\n";
   echo "$count
\n"; //echo str_pad(,8192)."\n"; ob_flush(); flush(); usleep(500000);

} echo "___BOUNDARY___\n"; ob_end_flush(); </php>