[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] MacPerl Counter (fwd)



According to Richard Rathe:
> 
> >*whew*  Ok - back to the subject:  I was going to say - why
> >do this as a graphical image?  If for glitz ok, but you can
> >also do this with just plain text and it would be faster.
> 
> Won't this require some sort of pre/post processing of the page? The
> advantage of using a GIF is that it only requires an <IMG> tag to place the
> counter in the page. RR

It shouldn't take any more processing than to create the
GIF image.  For instance:

Pseudo code here:

GIF:
	open( COUNTER, "pagecount.dat" );
	$theCount = <COUNTER>;
	close( COUNTER );

	$theCount++;
	<Make GIF>
	<store GIF to disk for access>

	open( COUNTER, ">pagecount.dat" );
	print COUNTER "$theCount\n";
	close( COUNTER );

	<example page>
	$theReply =<<HTML_CODE;
Content-type:	text/html

<html>
<head>
<title>Page Counter</title>
</head>

<body>
You are person #<img src="counter.gif">!
</body>
</html>
HTML_CODE

	$theReply =~ s/\015/\015\012/g;
	MacPerl::Reply( $theReply );
	exit( 0 );

Text output:
	open( COUNTER, "pagecount.dat" );
	$theCount = <COUNTER>;
	close( COUNTER );

	$theCount++;
	$myCount = sprintf( "%.10d", $theCount );

	open( COUNTER, ">pagecount.dat" );
	print COUNTER "$theCount\n";
	close( COUNTER );

	<example page>
	$theReply =<<HTML_CODE;
Content-type:	text/html

<html>
<head>
<title>Page Counter</title>
</head>

<body>
You are person #$myCount!
</body>
</html>
HTML_CODE

	$theReply =~ s/\015/\015\012/g;
	MacPerl::Reply( $theReply );
	exit( 0 );

Notes:

Granted that some web servers maintain an internal count of
how many times a web page has been accessed and some even
create the GIF image for you.  But if you were going to
have to create a GIF image it takes a lot more cpu usage to
generate a GIF image, store it, and then reference it than
it does to just print a number out.  This is not in
addition to the fact that a graphical image token must be
processed and the image brought across the line to the
other person.  Which is slower than if you just sent the
text line.  Finally, you have to create a unique file name
for each GIF image.  Otherwise the file might get
overwritten before it is even sent.  :-/

However, again, if the server itself maintains a special
image for your usage, then all you'd have to do is to
reference it.  But you are still having to send the image
over the net and/or possibly a modem.  And ten bytes is a
lot less than a 5K GIF image.