Take the 2-minute tour ×

I'm trying to create a simple cgi perl script that counts down from 10 to 0; however I can't seem to get it to work. It keeps telling me malformed header from script. Bad header=HTTP/1.1 200 OK. I'm new to Perl and CGI scripting so I'm sure it's something really simple.

use warnings;
use strict;

use CGI::Push qw(:standard);

my $startingCountDown = 10;

do_push(-next_page => \&refresh, -last_page=> \&lastPage, -delay => 1 );

sub refresh
        my ($cgi, $count) = @_;

        return undef if ($startingCountDown - $count < 0);

        my $num = $startingCountDown - $count;
        my $page = $cgi->start_html();
        $page .= $cgi->p("The count is $num").end_html();
        return $page;

sub lastPage
     my ($cgi, $count) = @_;
    return start_html()."Blast Off".end_html();

If I run this from terminal (on my Macbook) I get the following error: WARNING: YOUR BROWSER DOESN'T SUPPORT THIS SERVER-PUSH TECHNOLOGY.. I've tried running this script in both Safari and Chrome but neither seems to work. In that case, how would I write a functioning script that counts down from 10 to 1, changing numbers every second? Thanks.

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

The "server push" mechanism that CGI::Push is using (specifically, multipart/x-mixed-replace) is not widely supported. You will need to pick a different way of implementing this; probably the best way would be to have the countdown happen in Javascript, rather than on the server side.

share|improve this answer
add comment

Your Answer


