Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

printing blank page

by mexnix (Pilgrim)
on Jul 18, 2001 at 20:09 UTC ( [id://97722]=perlquestion: print w/replies, xml ) Need Help??

mexnix has asked for the wisdom of the Perl Monks concerning the following question:

This is a wierd one. My boss wants "speedometer"-like counters on all of our current web pages (Ack!), so I whipped a this script really quick:

#!/usr/bin/perl -w use strict; use CGI qw/:standard/; # "global" variable declaration ############################### my $countfile = './_countfile'; my $q = CGI->new; my $font = {face => 'Arial', size => 2}; open (OCOUNT, "<$countfile") || die "open died: $!"; my $count = <OCOUNT>; close (OCOUNT); open (NCOUNT, ">$countfile") || die "open died: $!"; my $ncount = ++$count; print NCOUNT $ncount; close (NCOUNT); my @nums = split //, $ncount; print $q->header; print $q->table({-border => 0, -cellpadding => 0, -cellspacing => 0}, Tr( map { td( img {-src => "count${_}.jpg"} ) } @nums, ) );
I have Apache 1.3.3 running locally on my Win32 box, and when tested, this worked fine (from command-line, and web via localhost). So I go and upload this to our server (Cobalt RaQ2 with Cobalt-Redhat and Cobalt-Apache) and run it from the web. It prints a blank page!! WTF! So I telnet in, and run it from the the command-line, and it prints the header and table tags perfectly! At this point I'm about to shoot someone. Can somebody tell me what's going on?? Is it uncompatible code? AHHH!!! It's not giving any errors at all.

__________________________________________________
<moviequote name="The Whole Nine Yards">
Jimmy T: Oz, we're friends, friends do not engage in sexual congress with each others wives.
</moviequote>

mexnix.perlmonk.org

Replies are listed 'Best First'.
Re: printing blank page
by merlyn (Sage) on Jul 18, 2001 at 20:42 UTC
    I'd avoid CGI.pm here, especially if it's not needing to parse the parameters or generate any complicated HTML.

    Also, use the CPAN luke! File::CounterFile does all that work for you!

    use constant COUNTERFILE => "_counter"; use File::CounterFile; my $n = File::CounterFile->new(COUNTERFILE, "0"); $n++; print "Content-type: text/html\n\n"; # this is SSI print "<table border=0 cellspacing=0 cellpadding=0><tr>"; print "<td><img src='count$_.jpg'></td>" for split //, "$n"; print "</tr></table>";

    -- Randal L. Schwartz, Perl hacker

Re: printing blank page
by HyperZonk (Friar) on Jul 18, 2001 at 20:17 UTC
    I wouldn't want to swear to this, but is it possible that this is because you don't have a print $q->start_html; and a print $q->end_html;? Also, I trust that you have looked at the returned page source (Ctrl-U in netscape, I have no idea what in IE) - is that blank, too?
      I thought to say this just after I submitted the question. I'm calling this script via SSI, so that's why I didn't have start_html() or end_html(). Yes I have looked at the page source. It's prints the header, and valid HEAD and BODY tags, but now TABLE's or IMG's :( Thanks

      __________________________________________________
      <moviequote name="The Whole Nine Yards">
      Jimmy T: Oz, we're friends, friends do not engage in sexual congress with each others wives.
      </moviequote>

      mexnix.perlmonk.org

Re: printing blank page
by suaveant (Parson) on Jul 18, 2001 at 20:30 UTC
    It's always good to use existing code, etc, I have always used Mohammad Muquit's WWW Counter... it is excellent, runs under windows or unix, is quick, and highly customizable... It might save you some headaches...

                    - Ant

      Yeah, I just might have to do that. I wanted to code my own, sorda to see it I could do it, even though it's not "great" by any means. Oh well. If anyway can tell me why this breaks, it'd much appreciated.

      __________________________________________________
      <moviequote name="The Whole Nine Yards">
      Jimmy T: Oz, we're friends, friends do not engage in sexual congress with each others wives.
      </moviequote>

      mexnix.perlmonk.org

Re: printing blank page
by Maclir (Curate) on Jul 18, 2001 at 20:42 UTC
    Is anything turning up in the error log? That is often a good place to start.
Re: printing blank page
by abstracts (Hermit) on Jul 19, 2001 at 05:47 UTC
    Hello

    It's a simple non-critical script; the whole purpose of it is satisfying the boss. If the purpose of this script was anything else, then you should've definately use flock to lock the file while you're updating it. You are running a race condition where after one process opens the file for writing, thus truncating the file, another might start reading, and getting an empty line (0). After this case, you might end up either losing one count or overwriting the count with 1, leading to a scienario where you hear your boss shouting from acrpss the hall something that ends with "FIRED!!".

    Aziz,,,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://97722]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-23 18:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found