http://www.perlmonks.org?node_id=968987


in reply to Re^4: CGI::Session keeps re-using same session ID
in thread CGI::Session keeps re-using same session ID

CGI::Application::Plugin::Streaming does not really provide what I need. I am not trying to stream a static file from disk. Instead, I am trying to write a run mode that dynamically generates HTML content and display each line of this dynamically generated content as soon as it becomes available.

Yes, I understood that, I suppose I wasn't clear that you should UTSL ie read the source code to see how its done (even though I described the steps)

Notice how the file does not contain the HTML code generated by stream_dynamic_html(). It only contains the single digit 1.

For me, the html contains the generated html

  • Comment on Re^5: CGI::Session keeps re-using same session ID

Replies are listed 'Best First'.
Re^6: CGI::Session keeps re-using same session ID
by alain_desilets (Beadle) on May 06, 2012 at 03:13 UTC
    For me, the html contains the generated html

    Strange. Maybe Windows deals differently than Unix with reading files that are still open for writing? I'm on Windows.

      Strange. Maybe Windows deals differently than Unix with reading files that are still open for writing? I'm on Windows.

      I'm also on Windows. The code you presented finishes writing to a file, then it streams it.

        I'm also on Windows. The code you presented finishes writing to a file, then it streams it.

        Oops. Posted an older version of the code. In that older version, I was opening the HTML temp file, writing to it, then streaming the temp file. It does stream the full content, but it defeats the whole purpose, because you don't start streaming the file until the complete HTML has been printed to it.

        I tried to address this issue by starting to stream the temp file right after it was opened, in the hopes that streaming from a file that is open for writing would work. In other words, I used this version of stream_dynamic_html:

        sub stream_dynamic_html { my ($self) = @_; $| = 1; open TEMP_HTML_FILE, ">$temp_dynamic_html_fpath"; $self->stream_file($temp_dynamic_html_fpath, 10); my $q = $self->query(); print TEMP_HTML_FILE $q->start_html(-title => 'HTML page dynamical +ly streamed to scean'); print TEMP_HTML_FILE $q->h3('HTML page dynamically streamed to sce +an'); print TEMP_HTML_FILE $q->p("The following lines will be printed at + 1 sec interval."); for (my $ii=0; $ii<3; $ii++) { print TEMP_HTML_FILE $q->p("This is line $ii.\n"); sleep(1); } print TEMP_HTML_FILE $q->p()."\n"; print TEMP_HTML_FILE "<a href=\"$script_name?dlg=stream_dynamic_ht +ml\">Stream dynamic HTML page</a><br/>\n"; print TEMP_HTML_FILE "<a href=\"$script_name?dlg=stream_static_fil +e\">Stream static file</a><br/>\n"; print TEMP_HTML_FILE $q->end_html(); close TEMP_HTML_FILE; }

        Unfortunately, this does not work, and ends up only showing a file that has the single digit 1 in it.