I use server side include cgi files to deliver dynamic content to my shtml pages, however I beleive they may slow the load time of my pages. I believe there are much faster ways to do what these ssi files do using more upto date scripting, something to do with the way it collects information to be displayed. Im hoping to get some feedback on this, and to overall speed up my ssi. Im posting the code for one of several of these types of files, with the thinking that if I can see one I will be able to figure out the changes for other similar files. The main differences of these files is the area of information that is collected and the size and way its displayed, I can figure out the display parts with some trial and error, however some notes on the areas of how its collecting the information would be helpful to help me understand how & where its looking for the information.
<code>
#!/usr/bin/perl
use Carp;
use vars qw(%config %category %form %supercat);
require "/var/require "/var/local %config;
$config{'basepath'} = '/var/$config{'htmlpages'} = '$config{'colortablehead'} = '#E6E6E6';
$config{'colortablehead0'} = '#E6E6E6';
$config{'colortablehead1'} = '#E6E6E6';
$config{'colortablehead2'} = '#E6E6E6';
$config{'colortablehead3'} = '#E6E6E6';
$config{'colortablehead4'} = '#E6E6E6';
$config{'colortablehead5'} = '#E6E6E6';
$config{'colortablehead6'} = '#E6E6E6';
$config{'colortablehead7'} = '#E6E6E6';
$config{'colortablehead8'} = '#E6E6E6';
$config{'colortablehead9'} = '#E6E6E6';
$config{'colortablehead10'} = '#EEEEEE';
$config{'colortablehead10T'} = '#E6E6E6';
$config{'colortablehead10B'} = '#EEEEEE';
$config{'colortablehead11'} = '#E6E6E6';
$config{'colortablehead12'} = '#E6E6E6';
$config{'colortablehead13A'} = '#FFFFBF';
$config{'colortablehead13B'} = '#FFFFBF';
$config{'colortablehead13C'} = '#FFFF8C';
$config{'colortablehead13D'} = '#FFFF8C';
$config{'colortablehead13E'} = '#FFFF00';
$config{'colortablehead13F'} = '#FFFF00';
$config{'specialtext0'} = '#FF0000';
$config{'specialtext1'} = '#FF0000';
$config{'specialtext2'} = '#FF0000';
$config{'text'} = '#000000';
$config{'text0'} = '#000000';
$config{'text1'} = '#000000';
$config{'text2'} = '#000000';
$config{'text3'} = '#000000';
$config{'text4'} = '#000000';
$config{'text5'} = '#000000';
$config{'text6'} = '#000000';
$config{'text7'} = '#000000';
$config{'text8'} = '#000000';
$config{'text9'} = '#000000';
$config{'text10'} = '#FF0000';
$config{'text10T'} = '#000000';
$config{'text10B'} = '#000000';
$config{'text12'} = '#000000';
$config{'text13A'} = '#000000';
$config{'text13C'} = '#000000';
$config{'text13E'} = '#000000';
$config{'colortablebody'} = '#E6E6E6';
$config{'colortablebody1'} = '#EFEFEF';
$config{'bordercolor'} = '#0000FF';
$config{'bordercolor1'} = '#000000';
$config{'odd_row_color'} = '#FFFFFF';
$config{'even_row_color'} = '#EEEEEE';
$config{'currency'} = '$';
$config{'currency2'} = 'U.S.';
$config{'currency3'} = 'dollar';
$config{'disp_max'} = 20;
##################################
# SSI Gallery on front page
# Randomly gathers current items posted to gallery
print "Content-type: text/html\n\n";
print "<div align=center><center><table border=0 cellpadding=0 cellspacing=0 width=100%>\n";
my $key;
my $s = 1;
my $pagebreak = int $form{pb} || 17;
my ($icount, $pcount) = (0,0);
foreach $key (sort keys %category) {
opendir THEDIR, "$config{'basepath'}$key" || die "Unable to open directory: $!";
my @allfiles = readdir THEDIR;
closedir THEDIR;
my $file;
@allfiles = get_random( \@allfiles, $config{'disp_max'}) if $#allfiles >= $config{'disp_max'};
foreach $file (sort { int($a) <=> int($b) } @allfiles) {
if (-T "$config{'basepath'}$key/$file") {
open THEFILE, "$config{'basepath'}$key/$file";
my ($title, $reserve, $inc, $desc, $image1, $image2, $image3, $image4, $thumb1, $thumb2, $thumb3, $thumb4, $dutch, $qty, $bold, $highlight, $feat, $catfeat, $grabber, $relist, $buyit, $gallery, $counter, $ship1, $ship2, $ship3, $ship4, $ship5, $shipcost, $location, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $pay9, $paypal, $idata1, $idata2, $idata3, $idata4, $idata5, $idata6, $idata7, $idata8, $idata9, @bids) = <THEFILE>;
my ($alias, $email, $bid, $time, $add1, $add2, $add3, $oqty, $qtysold) = &read_bid($bids[$#bids]);
my ($selleralias, $selleremail, $sellerbid, $sellertime, $selleradd1, $selleradd2, $selleradd3) = &read_bid($bids[0]);
close THEFILE;
chomp($title, $reserve, $inc, $desc, $image1, $image2, $image3, $image4, $thumb1, $thumb2, $thumb3, $thumb4, $dutch, $qty, $bold, $highlight, $feat, $catfeat, $grabber, $relist, $buyit, $gallery, $counter, $ship1, $ship2, $ship3, $ship4, $ship5, $shipcost, $location, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $pay9, $paypal, $idata1, $idata2, $idata3, $idata4, $idata5, $idata6, $idata7, $idata8, $idata9, @bids);
my @lastbid = split(/\[\]/,$bids[$#bids]);
$file =~ s/\.dat//;
my @closetime = localtime int($file);
my $timeleft = &timeleft($file);
$closetime[4]++;
my $imagedisp = "<IMG SRC=$thumb1 BORDER=0 width=95>";
if ($gallery eq "Yes") {
if(++$icount > $pagebreak){$icount=1; $pcount++} next if $pcount != $form{page};
print "\n<td width=20\% height=150 align=center valign=bottom><font face=arial size=2><table width=80 height=80 bgcolor=000000><tr><br><br><td align=center><A HREF=$config{'htmlpages'}/cgi-bin/auction/auction.cgi\?category=$key\&item=$file>$imagedisp</a></td></tr></table><FONT SIZE=1 FACE=ARIAL>Current Bid: $config{'currency'}$bid</font><br><FONT SIZE=1 FACE=ARIAL>Closes: $timeleft</font></td>\n" if ($thumb1);
if ($s==1) {
print "\n </tr>";
$s = 1;
}
else {
$s++;
}
}
}
}
}
if ($s > 1 && $s < 1) {
print "\n </TR>\n";
}
if ($icount <= 0){
print "<tr><td align=center valign=top height=225><font face=arial size=2><B><br>No items in category.</B></center></font></td></tr>";
}
print "</table>";
print "<div align=center><center><table border=0 cellpadding=0 cellspacing=0 width=100%></td></tr></table></center></div>\n";
print "<br><font face=arial size=2><div align=center><center><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td align=right width=90%><font size=2><a href=$config{'htmlpages'}/cgi-bin/auction/auction.cgi\?action=gallery>More Gallery!</a> </font></td></tr></table></center></div>\n";
# print "<font face=arial size=2><div align=center><center><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td width=100% bgcolor=E8E8E8 height=3></td></tr></table></center></div><br>\n";
#-#############################################
# Sub: Read Bid Information (bid_string)
# Reads an item file
sub read_bid {
my $bid_string = shift;
my ($alias, $email, $bid, $time, $add1, $add2, $add3, $oqty, $qtysold) = split(/\[\]/,$bid_string);
return ($alias, $email, $bid, $time, $add1, $add2, $add3, $oqty, $qtysold);
}
#-#############################################
# Sub: Get Random Item Data
# Written by: Dieter Werner
# Copyright by: Dieter Werner
#-#############################################
sub get_random {
my ($array, $cnt) = @_;
my ($val, $i, $j);
my @random;
my $noe = @$array;
$cnt = $noe if $cnt > $noe;
for ($i = @$array; --$i {
$j = int rand ($i + 1);
next if $i == $j;
@$array[$i, $j] = @$array[$j, $i];
}
while ($val = pop @$array) {
if ($cnt > 0) {
push @random, $val;
--$cnt;
}
}
return @random;
}
1;
</code>
<code>
#!/usr/bin/perl
use Carp;
use vars qw(%config %category %form %supercat);
require "/var/require "/var/local %config;
$config{'basepath'} = '/var/$config{'htmlpages'} = '$config{'colortablehead'} = '#E6E6E6';
$config{'colortablehead0'} = '#E6E6E6';
$config{'colortablehead1'} = '#E6E6E6';
$config{'colortablehead2'} = '#E6E6E6';
$config{'colortablehead3'} = '#E6E6E6';
$config{'colortablehead4'} = '#E6E6E6';
$config{'colortablehead5'} = '#E6E6E6';
$config{'colortablehead6'} = '#E6E6E6';
$config{'colortablehead7'} = '#E6E6E6';
$config{'colortablehead8'} = '#E6E6E6';
$config{'colortablehead9'} = '#E6E6E6';
$config{'colortablehead10'} = '#EEEEEE';
$config{'colortablehead10T'} = '#E6E6E6';
$config{'colortablehead10B'} = '#EEEEEE';
$config{'colortablehead11'} = '#E6E6E6';
$config{'colortablehead12'} = '#E6E6E6';
$config{'colortablehead13A'} = '#FFFFBF';
$config{'colortablehead13B'} = '#FFFFBF';
$config{'colortablehead13C'} = '#FFFF8C';
$config{'colortablehead13D'} = '#FFFF8C';
$config{'colortablehead13E'} = '#FFFF00';
$config{'colortablehead13F'} = '#FFFF00';
$config{'specialtext0'} = '#FF0000';
$config{'specialtext1'} = '#FF0000';
$config{'specialtext2'} = '#FF0000';
$config{'text'} = '#000000';
$config{'text0'} = '#000000';
$config{'text1'} = '#000000';
$config{'text2'} = '#000000';
$config{'text3'} = '#000000';
$config{'text4'} = '#000000';
$config{'text5'} = '#000000';
$config{'text6'} = '#000000';
$config{'text7'} = '#000000';
$config{'text8'} = '#000000';
$config{'text9'} = '#000000';
$config{'text10'} = '#FF0000';
$config{'text10T'} = '#000000';
$config{'text10B'} = '#000000';
$config{'text12'} = '#000000';
$config{'text13A'} = '#000000';
$config{'text13C'} = '#000000';
$config{'text13E'} = '#000000';
$config{'colortablebody'} = '#E6E6E6';
$config{'colortablebody1'} = '#EFEFEF';
$config{'bordercolor'} = '#0000FF';
$config{'bordercolor1'} = '#000000';
$config{'odd_row_color'} = '#FFFFFF';
$config{'even_row_color'} = '#EEEEEE';
$config{'currency'} = '$';
$config{'currency2'} = 'U.S.';
$config{'currency3'} = 'dollar';
$config{'disp_max'} = 20;
##################################
# SSI Gallery on front page
# Randomly gathers current items posted to gallery
print "Content-type: text/html\n\n";
print "<div align=center><center><table border=0 cellpadding=0 cellspacing=0 width=100%>\n";
my $key;
my $s = 1;
my $pagebreak = int $form{pb} || 17;
my ($icount, $pcount) = (0,0);
foreach $key (sort keys %category) {
opendir THEDIR, "$config{'basepath'}$key" || die "Unable to open directory: $!";
my @allfiles = readdir THEDIR;
closedir THEDIR;
my $file;
@allfiles = get_random( \@allfiles, $config{'disp_max'}) if $#allfiles >= $config{'disp_max'};
foreach $file (sort { int($a) <=> int($b) } @allfiles) {
if (-T "$config{'basepath'}$key/$file") {
open THEFILE, "$config{'basepath'}$key/$file";
my ($title, $reserve, $inc, $desc, $image1, $image2, $image3, $image4, $thumb1, $thumb2, $thumb3, $thumb4, $dutch, $qty, $bold, $highlight, $feat, $catfeat, $grabber, $relist, $buyit, $gallery, $counter, $ship1, $ship2, $ship3, $ship4, $ship5, $shipcost, $location, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $pay9, $paypal, $idata1, $idata2, $idata3, $idata4, $idata5, $idata6, $idata7, $idata8, $idata9, @bids) = <THEFILE>;
my ($alias, $email, $bid, $time, $add1, $add2, $add3, $oqty, $qtysold) = &read_bid($bids[$#bids]);
my ($selleralias, $selleremail, $sellerbid, $sellertime, $selleradd1, $selleradd2, $selleradd3) = &read_bid($bids[0]);
close THEFILE;
chomp($title, $reserve, $inc, $desc, $image1, $image2, $image3, $image4, $thumb1, $thumb2, $thumb3, $thumb4, $dutch, $qty, $bold, $highlight, $feat, $catfeat, $grabber, $relist, $buyit, $gallery, $counter, $ship1, $ship2, $ship3, $ship4, $ship5, $shipcost, $location, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $pay9, $paypal, $idata1, $idata2, $idata3, $idata4, $idata5, $idata6, $idata7, $idata8, $idata9, @bids);
my @lastbid = split(/\[\]/,$bids[$#bids]);
$file =~ s/\.dat//;
my @closetime = localtime int($file);
my $timeleft = &timeleft($file);
$closetime[4]++;
my $imagedisp = "<IMG SRC=$thumb1 BORDER=0 width=95>";
if ($gallery eq "Yes") {
if(++$icount > $pagebreak){$icount=1; $pcount++} next if $pcount != $form{page};
print "\n<td width=20\% height=150 align=center valign=bottom><font face=arial size=2><table width=80 height=80 bgcolor=000000><tr><br><br><td align=center><A HREF=$config{'htmlpages'}/cgi-bin/auction/auction.cgi\?category=$key\&item=$file>$imagedisp</a></td></tr></table><FONT SIZE=1 FACE=ARIAL>Current Bid: $config{'currency'}$bid</font><br><FONT SIZE=1 FACE=ARIAL>Closes: $timeleft</font></td>\n" if ($thumb1);
if ($s==1) {
print "\n </tr>";
$s = 1;
}
else {
$s++;
}
}
}
}
}
if ($s > 1 && $s < 1) {
print "\n </TR>\n";
}
if ($icount <= 0){
print "<tr><td align=center valign=top height=225><font face=arial size=2><B><br>No items in category.</B></center></font></td></tr>";
}
print "</table>";
print "<div align=center><center><table border=0 cellpadding=0 cellspacing=0 width=100%></td></tr></table></center></div>\n";
print "<br><font face=arial size=2><div align=center><center><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td align=right width=90%><font size=2><a href=$config{'htmlpages'}/cgi-bin/auction/auction.cgi\?action=gallery>More Gallery!</a> </font></td></tr></table></center></div>\n";
# print "<font face=arial size=2><div align=center><center><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td width=100% bgcolor=E8E8E8 height=3></td></tr></table></center></div><br>\n";
#-#############################################
# Sub: Read Bid Information (bid_string)
# Reads an item file
sub read_bid {
my $bid_string = shift;
my ($alias, $email, $bid, $time, $add1, $add2, $add3, $oqty, $qtysold) = split(/\[\]/,$bid_string);
return ($alias, $email, $bid, $time, $add1, $add2, $add3, $oqty, $qtysold);
}
#-#############################################
# Sub: Get Random Item Data
# Written by: Dieter Werner
# Copyright by: Dieter Werner
#-#############################################
sub get_random {
my ($array, $cnt) = @_;
my ($val, $i, $j);
my @random;
my $noe = @$array;
$cnt = $noe if $cnt > $noe;
for ($i = @$array; --$i {
$j = int rand ($i + 1);
next if $i == $j;
@$array[$i, $j] = @$array[$j, $i];
}
while ($val = pop @$array) {
if ($cnt > 0) {
push @random, $val;
--$cnt;
}
}
return @random;
}
1;
</code>