How can I continuously inform the user of progress from a Perl CGI script?

前端 未结 6 702
一整个雨季
一整个雨季 2021-01-13 12:04

I have this Perl script sitting in the cgi-bin folder of my Apache server:

#!/usr/bin/perl 
use strict;
use warnings;

$| = 1;

print \"Content-type: text/ht         


        
6条回答
  •  [愿得一人]
    2021-01-13 12:26

    Randal Schwartz shows a better way in Watching long processes through CGI.

    That said, lying about the content type will not help. The following script does exactly what you seem to want it to do on Windows XP with Apache 2.2 (in that it takes ten seconds for the last line of output to appear):

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    use CGI qw(:cgi);
    
    print header('text/plain');
    
    $| = 1;
    
    print "Job started\n";
    
    for ( 1 .. 10 ) {
        print "$_\n";
        sleep 1;
    }
    

    Now, if you are sending HTML, you cannot avoid the fact that most browsers will wait until they what they believe is enough of the page to begin rendering.

提交回复
热议问题