Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks

I was wondering if there is any way of getting perl to refresh a web page automatically? Sometimes, when I click on a recently used page with my perlscript in it, it loads up an out of date page from cache.

Cheers

C J

Replies are listed 'Best First'.
Re: Automatic page refresh
by jdhedden (Deacon) on Jul 28, 2005 at 12:09 UTC
    Since you're using CGI, when you print out the CGI headers from your script add:
    -expires => 'now'
    For example:
    print(header(-expires => 'now'));
    This directive is supposed to cause the browser to expire the page in its cache and get a fresh copy the next time the page is displayed.

    Remember: There's always one more bug.

      You shouldn't set the expires header to be "now" (update (thanks frodo72): but that code doesn't set the header to be "now", it is converted to an actual date. That's teach me to not test - you only ever get something wrong if you don't test, 99% of the time, if you do test, your test will give the expected result). The spec says that it must be in HTTP-Date format. It does also say that if a client recieves anything that isn't HTTP-Date, then it should treat it as "already expired" - but intentionally triggering error recovery isn't a fantastic idea.

      Other caching headers might also come in useful. Caching Tutorial for Web Authors and Webmasters is a worthwhile read.

        But the respondent is suggesting to set the -expire parameter of the header function to now, which is pretty different. From CGI docs:
        Most browsers will not cache the output from CGI scripts. Every time the browser reloads the page, the script is invoked anew. You can change this behavior with the -expires parameter. When you specify an absolute or relative expiration interval with this parameter, some browsers and proxy servers will cache the script's output until the indicated expiration date. The following forms are all valid for the -expires field:
        +30s 30 seconds from now +10m ten minutes from now +1h one hour from now -1d yesterday (i.e. "ASAP!") now immediately +3M in three months +10y in ten years time Thursday, 25-Apr-1999 00:40:33 GMT at the indicated time & da +te

        Flavio
        perl -ple'$_=reverse' <<<ti.xittelop@oivalf

        Don't fool yourself.
      Thanks, folks

      This works a treat!

      C J

Re: Automatic page refresh
by anonymized user 468275 (Curate) on Jul 28, 2005 at 11:30 UTC
    Before assuming this can or should be solved with perl, I would try to eliminate more possibilities, e.g. it could be caused by your hosting provider not giving you access to the real www directory and having a script refreshing the real one.

    You might also want to provide details such as version of Apache or Netscape server, running on what platform/version etc. etc. to get a reasonable response.

    One world, one people

Re: Automatic page refresh
by blazar (Canon) on Jul 28, 2005 at 11:35 UTC
    Hint: 'web' !~ /^[Pp]erl$/. That is you should specify which is the environment in which you're actually working... most probably CGI, isn't it? In particular there's something called "perlscript" which is a tool for client side perl scripting, but that is not much used AFAIK and my guess is that it is not what you're having to do with, so I think that your description of the problem may be misleading.

    To obtain better help you should show what you have tried so far...

      Ok sorry folks, looks like I wasn't specific enough.

      If there's one thing I dislike, it's vagueness...

      I am running perl version 5.6.0 on an i386 linux server.
      My client is running Internet Explorer version 6 on Windows XP.
      My perl script (sorry for missing out the space last time) does use CGI.

      Apologies if this sort of thing isn't possibe with Perl, I just thought someone might have known a quick trick.

Re: Automatic page refresh
by kprasanna_79 (Hermit) on Jul 28, 2005 at 12:34 UTC
    Hai,
    Just try this piece of code in HTMl part..rather than in perl..which save time and code reduction
    in header section put this tag <meta http-equiv= refresh content= 3600 >
    -Prasanna.K