Getting status/response codes in Perl

Discussion in 'Perl Misc' started by Ali, Feb 29, 2004.

  1. Ali

    Ali Guest

    Hi,

    I've created a site and on one page I need to print certain
    information out to a log file. I've managed to get all the data that
    is required except a 'HTTP response code'. I've searched through
    several books and websites and all I've come up with is that they are
    also called status codes and I've found how to create a page that is
    displayed when a certain status code is found but I can't find out how
    to log the status of the page that was loaded.

    Does anyone know how to do this and am I right in saying that for the
    page to have loaded correctly the code must be 200?

    I thought it might be stored as an environment variable like when
    setting and retrieving cookies but I can't find any environment
    variables associated with status codes.

    Can anyone help?

    Thanks very much,
    Ali :eek:)
     
    Ali, Feb 29, 2004
    #1
    1. Advertising

  2. Ali

    gnari Guest

    "Ali" <> wrote in message
    news:...


    > I've created a site and on one page I need to print certain
    > information out to a log file. I've managed to get all the data that
    > is required except a 'HTTP response code'. I've searched through
    > several books and websites and all I've come up with is that they are
    > also called status codes and I've found how to create a page that is
    > displayed when a certain status code is found but I can't find out how
    > to log the status of the page that was loaded.
    >
    > Does anyone know how to do this and am I right in saying that for the
    > page to have loaded correctly the code must be 200?
    >
    > I thought it might be stored as an environment variable like when
    > setting and retrieving cookies but I can't find any environment
    > variables associated with status codes.


    not really a perl question, but in general the web server does decide
    what the status code is until the cgi script has finished, because if
    the said script should terminate with error, a status 500 is returned.

    you must either
    a) assume there will be no error,and log code 200, preferably as the very
    last action your script does
    or
    b) retrieve the status code from the webservers log file and join that
    somehow with your logfile
    or
    c) your webserver may allow for your application to add information
    to the webserver logfile. (Apache+mod_perl, for example allows this)

    gnari
     
    gnari, Feb 29, 2004
    #2
    1. Advertising

  3. Ali

    Ali Guest

    Thanks very much, that was extremely helpful. I think I know what I have to do now!

    Ali :eek:)

    "gnari" <> wrote in message news:<c1tfq0$4qh$>...
    > "Ali" <> wrote in message
    > news:...
    >
    >
    > > I've created a site and on one page I need to print certain
    > > information out to a log file. I've managed to get all the data that
    > > is required except a 'HTTP response code'. I've searched through
    > > several books and websites and all I've come up with is that they are
    > > also called status codes and I've found how to create a page that is
    > > displayed when a certain status code is found but I can't find out how
    > > to log the status of the page that was loaded.
    > >
    > > Does anyone know how to do this and am I right in saying that for the
    > > page to have loaded correctly the code must be 200?
    > >
    > > I thought it might be stored as an environment variable like when
    > > setting and retrieving cookies but I can't find any environment
    > > variables associated with status codes.

    >
    > not really a perl question, but in general the web server does decide
    > what the status code is until the cgi script has finished, because if
    > the said script should terminate with error, a status 500 is returned.
    >
    > you must either
    > a) assume there will be no error,and log code 200, preferably as the very
    > last action your script does
    > or
    > b) retrieve the status code from the webservers log file and join that
    > somehow with your logfile
    > or
    > c) your webserver may allow for your application to add information
    > to the webserver logfile. (Apache+mod_perl, for example allows this)
    >
    > gnari
     
    Ali, Mar 1, 2004
    #3
  4. Ali

    gnari Guest

    "Ali" <> wrote in message
    news:...
    > Thanks very much, that was extremely helpful. I think I know what I have

    to do now!
    >

    that's good, but there is no need to quote the whole article you are
    following up on. rather quote the relevant bits, and add your response
    after it. That makes it so much more readable, specially if it develops
    into a real thread.

    >
    > "gnari" <> wrote in message

    news:<c1tfq0$4qh$>...
    [snipped whole quoted article]

    gnari
     
    gnari, Mar 1, 2004
    #4
  5. Ali

    pkent Guest

    In article <>,
    (Ali) wrote:

    > also called status codes and I've found how to create a page that is
    > displayed when a certain status code is found but I can't find out how
    > to log the status of the page that was loaded.


    If you're using Apache then the default access log format includes the
    status code - so it's already being logged, albeit in a separate file.


    > am I right in saying that for the
    > page to have loaded correctly the code must be 200?


    No, the web server can return a valid response with some content with a
    number of response codes.


    > I thought it might be stored as an environment variable like when
    > setting and retrieving cookies but I can't find any environment
    > variables associated with status codes.


    The response code is, AFAICT, decided on by the web server, not the CGI
    application (except in NPH mode). But if you want to explain in a bit
    more detail what you're trying to achieve then maybe I can be of a bit
    more help

    P

    --
    pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
    Remove the tea to reply
     
    pkent, Mar 1, 2004
    #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. Greg  --
    Replies:
    4
    Views:
    2,272
  2. Mike C
    Replies:
    1
    Views:
    518
    pythonhda
    Feb 16, 2004
  3. Alvin A. Delagon
    Replies:
    0
    Views:
    251
    Alvin A. Delagon
    Dec 28, 2005
  4. Replies:
    2
    Views:
    2,981
    Malcolm
    Aug 20, 2005
  5. Allen
    Replies:
    1
    Views:
    682
    Mark Rae [MVP]
    Dec 3, 2007
Loading...

Share This Page