Please help Monks Allmighty. How is this code used in the main site? Is it called by using java within my index.html or what? Here's the public domain code I found. I have it running but what should I see to know it works as advertised?

#!/usr/bin/perl #Load balancing #You've hit the big time, and your site is getting more hits than you +ever dreamed of. #Millions, zillions of hits. What's that? System load just passed 50 a +nd response time is getting kinda' s-l-o-w-w-w? #Perl to the rescue. Set up several replica Web servers with different + hostnames and IP addresses. #Run this script on the ``main'' site and watch it round-robin the req +uests to the replica servers. #It uses IO::Socket to listen for incoming requests on port 80. It the +n changes its privileges to run as #nobody.nogroup, just like a real Web server. Next it preforks itself +a few times (and you always thought #preforking was something fancy, didn't you?), and goes into an accept +() loop. Each time an incoming session comes in, #it forks off another child to handle the request. The child reads the + HTTP request and issues an HTTP redirection to #send the browser to a randomly selected server. #NOTE: Another way to do this is to have multiple ``A'' records define +d for your server's hostname and let DNS caching distribute the load. + #---------------- Script I.4.1: A Load Balancing ``Web Server'' ------ +--- use CGI qw/:standard/; print "Content-type:text/html\n\n"; print "hello", "\n"; # list of hosts to balance between my @HOSTS = qw/www1.mydomain.com www2.mydomain.com www3.mydomain.com w +ww4.mydomain.com/; use IO::Socket; $SIG{CHLD} = sub { wait() }; $ENV{'PATH'}='/bin:/usr/bin'; chomp($hostname = `/bin/hostname`); print $hostname, "\n"; # Listen on port 80 $sock = IO::Socket::INET->new(Listen => 5, LocalPort => 80, LocalAddr => $hostname, Reuse => 1, Proto => 'tcp'); # become "nobody" $nobody = (getpwnam('nobody'))[2] || die "nobody is nobody"; $nogroup = (getgrnam('nogroup'))[2] || die "can't grok nogroup"; ($<,$() = ($>,$)) = ($nobody,$nogroup); # get rid of root privileges! ($\,$/) = ("\r\n","\r\n\r\n"); # CR/LF on output/input # Go into server mode close STDIN; close STDOUT; close STDERR; # prefork -- gee is that all there is to it? fork() && fork() && fork() && fork() && exit 0; # start accepting connections while (my $s = $sock->accept()) { do { $s->close; next; } if fork(); my $request = <$s>; print $request, "\n"; redirect($1,$s) if $request=~/(?:GET|POST|HEAD|PUT)\s+(\S+)/; $s->flush; undef $s; exit 0; } sub redirect { my ($url,$s) = @_; my $host = $HOSTS[rand(@HOSTS)]; print $s, "HTTP/1.0 301 Moved Temporarily", "\n"; print $s, "Server: Lincoln's Redirector/1.0", "\n"; print $s, "Location: http://${host}${url}", "\n"; print $s, "", "\n"; }

In reply to Load balancer by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.