perl code to test my C based CGI application

Discussion in 'Perl Misc' started by chris, Jun 26, 2003.

  1. chris

    chris Guest

    Already tried cgi newsgroup to no avail.

    I'm a Perl begginner, and it's starting to look like Perl is the best
    way to do this. I have a C based CGI executable that receives a single
    arguement via HTTP POST method as follows:

    <form method="POST" action="http://mypc-01/scripts/MyCGI.exe"
    name="postToCGI">

    I'd like to load test it by creating a Perl script that simply calls
    it with same argument over and over and over. How can I do this?

    thanks.

    chris
    chris, Jun 26, 2003
    #1
    1. Advertising

  2. chris <> wrote:

    [a CGI program written in C]
    > I'd like to load test it by creating a Perl script that simply
    > calls it with same argument over and over and over. How can I do
    > this?


    See

    perldoc lwpcook

    It has examples that should get you started.
    David K. Wall, Jun 26, 2003
    #2
    1. Advertising

  3. chris

    chris Guest

    Purl Gurl <> wrote in message news:<>...
    > chris wrote:
    >
    > > I'm a Perl begginner, and it's starting to look like Perl is the best
    > > way to do this. I have a C based CGI executable that receives a single
    > > arguement via HTTP POST method as follows:

    >
    > Are you a beg-ginner or a beginner?
    >
    > "argument"
    >
    >
    > > <form method="POST" action="http://mypc-01/scripts/MyCGI.exe" name="postToCGI">

    >
    > > I'd like to load test it by creating a Perl script that simply calls
    > > it with same argument over and over and over. How can I do this?

    >
    > http://stein.cshl.org/~lstein/torture/torture.html
    >
    >
    > Purl Gurl


    Spell correcting in a newsgroup? yikes.

    Thanks everyone. I found a nice example by Jason Mathews and modified a bit:

    #!/bin/perl
    # based on sample script by Jason Mathews 28-March-1996

    for ($count=1; $count < 11; $count++)
    {
    $ENV{'GATEWAY_INTERFACE'} = "CGI/1.1";
    $ENV{'SCRIPT_NAME'} = "C:/Inetpub/Scripts/MyCGIUtility.exe";
    $ENV{'SERVER_PROTOCOL'} = "HTTP/1.0";

    #
    # Set all environment variables that are referenced in your
    # CGI program. For example, only REQUEST_METHOD, QUERY_STRING,
    # and CONTENT_LENGTH are referenced in the dump.cgi program.
    #######################################################################

    $| = 1;

    # CGI form input

    $cgi_input = 'acctid=501020000246';

    #
    # POST method
    #

    print "----------------------------------------------------\n";
    print "simulating a POST method:\n";

    # Setup environment

    $ENV{'REQUEST_METHOD'} = "POST";
    $ENV{'CONTENT_LENGTH'} = length($cgi_input);
    $ENV{'CONTENT_TYPE'} = "application/x-www-form-urlencoded";

    open(PIPE, "| MyCGIUtility.exe");
    print PIPE $cgi_input;
    close(PIPE);

    } # end for

    chris
    chris, Jun 27, 2003
    #3
  4. (chris) writes:
    > Thanks everyone. I found a nice example by Jason Mathews and modified a bit:


    <snip>

    I guess it depends on what you're testing. What you did will test the
    program, but outside its normal execution environment
    (Webserver+CGI). You're essentially simulating a CGI environment, and
    then testing. This isn't a big problem, but you need to also test it
    in a real CGI environment, as you always have the risk that your
    simulation isn't necessarily good enough.

    -=Eric
    --
    Come to think of it, there are already a million monkeys on a million
    typewriters, and Usenet is NOTHING like Shakespeare.
    -- Blair Houghton.
    Eric Schwartz, Jun 27, 2003
    #4
  5. chris

    chris Guest

    Purl Gurl <> wrote in message news:<>...
    > chris wrote:
    >
    > > Purl Gurl wrote:
    > > > chris wrote:

    >
    > > > > I'm a Perl begginner, and it's starting to look like Perl is the best
    > > > > way to do this. I have a C based CGI executable that receives a single
    > > > > arguement via HTTP POST method as follows:

    >
    > > > Are you a beg-ginner or a beginner?

    >
    > > > "argument"

    >
    > > Spell correcting in a newsgroup? yikes.

    >
    > My presumption is you do not care to improve your spelling skills,
    > which is often a reason for poor spelling skills.
    >
    >
    > > > > I'd like to load test it by creating a Perl script that simply calls
    > > > > it with same argument over and over and over. How can I do this?

    >
    > > > http://stein.cshl.org/~lstein/torture/torture.html

    >
    >
    > > I found a nice example by Jason Mathews and modified a bit:

    >
    > Yours is a nice example, although inefficient. It does not load
    > test your software, however.
    >
    > A single iteration of your example code is no different than eleven
    > iterations. Either your program works right or it doesn't. Your
    > efficiency would be greatly improved by moving your environment
    > variables outside your looping mechanism; no need to set those
    > variables eleven times. Same is true for your $| flushing. This
    > only needs to be set once. A simple system() call would be quicker
    > than opening a filehandle.
    >
    > Nice example which could be improved significantly, keeping in
    > mind your example does not load test.
    >
    >
    > Purl Gurl


    Thanks. I moved all my env vars and flushing outside the loop now.

    I plan to run this script from 10 different client boxes at the same
    time, that will all be hitting the CGI server, so I think it will give
    me somehwhat of a load test. I suppose it's more of a performance
    test.

    chris
    chris, Jun 30, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jürgen Exner

    Re: CGI Perl "use CGI" statement fail

    Jürgen Exner, Jul 31, 2003, in forum: Perl
    Replies:
    0
    Views:
    1,229
    Jürgen Exner
    Jul 31, 2003
  2. praba kar

    Python-cgi or Perl-cgi script doubt

    praba kar, Jul 30, 2005, in forum: Python
    Replies:
    1
    Views:
    513
    Michael Sparks
    Jul 30, 2005
  3. epsilon
    Replies:
    4
    Views:
    308
    Gabriel Genellina
    Aug 22, 2007
  4. Skybuck Flying

    Call oddities: &Test() vs &Test vs Test

    Skybuck Flying, Oct 4, 2009, in forum: C Programming
    Replies:
    1
    Views:
    683
    Skybuck Flying
    Oct 4, 2009
  5. kath
    Replies:
    4
    Views:
    539
    J. Gleixner
    Apr 9, 2007
Loading...

Share This Page