#!/usr/bin/perl

use LWP::Simple;

$stime = time;
for ($i=0; $i<100; $i++) {
timeGetUrl('http://wetterhorn.uccs.edu/~cs522/CS522F2000Photo.html');
unless ($pid = fork) {
   unless ($pid2 = fork) {
      unless ($pid3 = fork) {
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/kmadimul.jpg', 3);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/mkakhtar.jpg', 3);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/busanem.jpg', 3);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/jlbryan.jpg', 3);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/jchadha.jpg', 3);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/ykchoe.jpg', 3);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/dmclapp.jpg', 3);
         exit 0;
       }
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/pferrao.jpg', 2);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/mmgebhar.jpg', 2);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/gkgodava.jpg', 2);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/lmgonsal.jpg', 2);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/jeharvey.jpg', 2);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/lkaplan.jpg', 2);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/srkasire.jpg', 2);
       waitpid($pid3, 0);
       exit 0;
   }
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/prohilla.jpg', 1);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/tshishid.jpg', 1);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/jdsmith.jpg', 1);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/hbsomara.jpg', 1);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/xsun.jpg', 1);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/jdtaylor.jpg', 1);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/trvaddir.jpg', 1);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/jxie.jpg', 1);

   waitpid($pid2, 0);
   exit 0;
}

         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/ajdavis.jpg', 3);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/vpdevabh.jpg', 3);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/rsdevi.jpg', 3);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/lli.jpg', 2);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/awmorris.jpg', 2);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/bkrobert.jpg', 2);
         timeGetUrl('http://wetterhorn.uccs.edu/~cs522/images/chow.jpg', 1);


waitpid($pid,0);
} # end for 
$etime = time;
$dtime = $etime - $stime;
print "It takes $dtime seconds to retrieve CS522F2000Photo.html times.\n";
exit(0);

for ($i=1; $i<3; $i++) {
	timeGetUrl('http://wetterhorn.uccs.edu:8080/cs622/hw/hw1.htm');
	timeGetUrl('http://wetterhorn.uccs.edu:8080/cs622/hw/hw1_ht1.gif');
	
}

use LWP::UserAgent;
$ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(POST => 'http://wetterhorn.uccs.edu:8080/cgi-bin/cs622/purchase.pl');
$req->content_type('text/xml');
$xmldoc = "
<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>
<!--======= purhcase request example =======-->
<purchase>
  <customerName>CCL</customerName>
  <customerID>111222333</customerID>
  <item>
     <productID>309121544</productID>
     <productName>IBM Thinkpad T21</productName>
     <unitPrice>5000</unitPrice>
     <noOfUnits>10</noOfUnits>
     <subTotal>50000</subTotal>
  </item>
  <item>
     <productID>309121538</productID>
     <productName>Intel wireless LAN PC Card</productName>
     <unitPrice>200</unitPrice>
     <noOfUnits>10</noOfUnits>
     <subTotal>2000</subTotal>
  </item>
  <totalAmount>52000</totalAmount>
</purchase>";

print $xmldoc;
$req->content($xmldoc);
$time3=time;
my $res = $ua->request($req);
$time4=time;
$periodxml = $time4 -$time3;
print $res->as_string;
print "get response after submitting purchase.xml in $periodxml seconds\n";


sub timeGetUrl() {
	my ($url, $pid) = @_;
	$time1 = time;
	$doc = get $url;
	$length= length $doc;
        $time2 = time;
        $period = $time2 - $time1;
        #print "process $pid get $url size $length in $period seconds\n";
}


