HTTP::Request for www.thescripts.com

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samthemist
    New Member
    • Jul 2007
    • 34

    HTTP::Request for www.thescripts.com

    [CODE=perl]#/usr/bin/perl -w
    use LWP::UserAgent;
    use Time::HiRes qw(gettimeofday );
    #use Crypt::SSLeay;

    use strict;

    print "Enter URL to Time GET request for... ";
    my $host=<STDIN>;
    chomp $host;

    my $before=gettime ofday;
    my $ua = LWP::UserAgent->new();
    my $request = HTTP::Request->new('GET', "$host");
    my $response = $ua->request($reque st);
    my $elapsed=gettim eofday-$before;
    print "ERROR: Bad URL\n" if($response->is_error);
    my @content=split/\n/,$response->content;
    print "Request took $elapsed seconds.\n";
    my @title=grep /(?:title|TITLE)/, @content;
    print "TITLE LINE: @title \n";
    [/CODE]

    I'm using this script to see how fast it can get different pages.
    I put www.thescripts.com as my page,


    Enter URL to Time GET request for... ERROR: Bad URL
    Request took 0.0080049037933 3496 seconds.

    Why would it be a bad url?
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    www.thescripts. com is not a fully qualified url. You must specify the protocol:

    http://www.thescripts. com

    - Miller

    Comment

    • samthemist
      New Member
      • Jul 2007
      • 34

      #3
      Thanks for helping, but it still didn't work:


      Enter URL to Time GET request for... ERROR: Bad URL
      Request took 0.0084350109100 3418 seconds.
      >Exit code: 0

      Comment

      • miller
        Recognized Expert Top Contributor
        • Oct 2006
        • 1086

        #4
        Read this:

        cpan lwptut

        Namely the second section "The Basics of the LWP Class Model" will show you a better way to formatting you request. And much more importantly, it will show you how to get meaningful error messages.

        - Miller

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          Well, you have told the script to print "Bad URL" regardless of what the real error is. The script works fine for me, but do have to shutdown my firewall first because I never figured out how to get a command line perl program to be allowed internet access while the firewall is turned on.

          Comment

          • samthemist
            New Member
            • Jul 2007
            • 34

            #6
            I don't need to turn my firewall off for it to work.

            However, it turns out it requested pages at roughly 1500-2000ms.

            I'm still finding it hard to believe, that perl requests pages slower than VB6?!?!

            Comment

            • KevinADC
              Recognized Expert Specialist
              • Jan 2007
              • 4092

              #7
              perl is really good at processing text, anything else it is not going to be the fastest solution for doing something. I am not a VB6 coder so I have no way to know why it is faster than perl in this specific situation. Perl does have to be compiled, so that right there will add time to the over all speed of execution.

              Comment

              • samthemist
                New Member
                • Jul 2007
                • 34

                #8
                I've made another thread - i think that's why. Go take a look!

                Comment

                Working...