• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 162
  • Last Modified:

reload page only when file is updated

I am using a perl script to read a text file and show that on a page using an iframe.
It is a sort of chat box.

Now I use a meta tag to reload/ refresh the page every 300 seconds.
To reload a pae that isn't updated is no use. It is better to only reload the page when it is updated. So I added an extra value to the reload command that will add the last changed time of the file.

<meta http-equiv="refresh" content="300; URL=http://www.test.nl/cgi-bin/calendar/calendar.cgi?chat_data=1&number=8&next=8&last_update=1148023591&refresh=1">

How to only update/ refresh the page when the file last update time is changed.
And if it is not changed do not reload the page to save uptime.

Michel
                              
0
mmcw
Asked:
mmcw
  • 4
1 Solution
 
ps15Commented:
Well, since the <meta> tag is transferred to the browser before the update is done, you can't have it check that, because it will always be the same.
What you could do is use Ajax to check if the page is updated.

using the Prototype library from http://prototype.conio.net/dist/prototype-1.4.0.js (just put it somewhere on your server)
let's say you have a calendar.cgi and a last_changes.cgi where last_changes.cgi only outputs the last changed time()


then you can add to your calender.cgi:

<script type="text/javascript" src="http://test.nl/wherever/protype/is.js"></script>
<script type="text/javascript">
var last_change = "1148023591"; // this should be supplied by your calendar.cgi

setTimeout("UpdateTest()", 300000); /
function UpdateTest() {
var opt = {
                  onSuccess: function(t) {
                        if(t.responseText > last_change) {
                                  location.reload; // reloads page
                                }
                  },
                  on404: function(t) {
                        alert('Error 404: location "' + t.statusText + '" was not found.');
                  },
                  onFailure: function(t) {
                        alert('Error ' + t.status + ' -- ' + t.statusText);
                  },
                  asynchonous: true
            }
            new Ajax.Request("http://test.nl/cgi-bin/last_changes.cgi", opt);
                 setTimeout("UpdateTest()", 300000); // 300 seconds then try again
}

</script>

now make sure last_changes.cgi only outputs the time, and it should only update when a change was made.
0
 
mmcwAuthor Commented:
I am using the following code for the last_changes.cgi:

#!/usr/bin/perl

use CGI qw(:standard -unique_headers escapeHTML unescapeHTML);

my $file_chat = "/path/to/the file/chat/file";
my $last_update = (stat($file_chat))[9];

print header();
print $last_update;

exit(0);

Is that what you mean?
0
 
mmcwAuthor Commented:
I am using this code WITHOUT SUCCESS!!

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
      <title>Medicos Online Calendar - Chat</title>
      <meta http-equiv="Description" content="Medicos Online Calendar - Chat" />
      <meta http-equiv="Keywords" content="medicos" />
      <meta http-equiv="expires" content="0">
      <meta name="robots" content="noindex, nofollow">

      <link href="http://www.medicosonline.nl/css/medicos.css" type="text/css" rel="stylesheet">

      <script type="text/javascript" src="http://www.medicosonline.nl/js/prototype-1.4.0.js"></script>
      <script type="text/javascript">
      var last_change = "1148144002";

      setTimeout("UpdateTest()", 3000);
      function UpdateTest() {
      var opt = {
            onSuccess: function(t) {
                  if(t.responseText > last_change) {
                        location.reload; // reloads page
                  }
            },
            on404: function(t) {
                  alert('Error 404: location "' + t.statusText + '" was not found.');
            },
            onFailure: function(t) {
                  alert('Error ' + t.status + ' -- ' + t.statusText);
            },
            asynchonous: true
      }
      new Ajax.Request("http://www.medicosonline.nl/cgi-bin/calendar/calendar_chat_time.cgi", opt);
      setTimeout("UpdateTest()", 3000); // 300 seconds then try again
}
</script>


</head>

<body class="chat">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
            
            <tr class="chat" valign="top">
                  <td colspan="3" align="right">
                        Bericht&nbsp;&nbsp;<b>9</b> - <b>1</b> van <b>9</b>
                  </td>                        
            </tr>
            <tr class="chat" valign="top">
                  <td width="122">
                        2006/05/20 18:54:34:<br />
                  </td>
                  <td>
                        test (michel)<br />
                  </td>
            </tr>
            <tr class="chat" valign="top">
                  <td width="122">
                        2006/05/19 09:26:31:<br />
                  </td>
                  <td>
                        hallo hallo (carola)<br />
                  </td>
            </tr>
            <tr class="chat" valign="top">
                  <td width="122">
                        2006/04/28 11:36:04:<br />
                  </td>
                  <td>
                        Marja, zou jij vrijdag 12 mei even willen nakijken, er staan twee behandelingen s&#39;avonds voor mij, maar vrijdagavond kan ik helemaal niet. Tot 18.00! B.V.D (sharon)<br />
                  </td>
            </tr>
      </table>
       Saturday, May 20, 2006
</body>
</html>

What am I doing wrong????
0
 
mmcwAuthor Commented:
I have uploaded the not working example to: http://www.medicosonline.nl/chat.shtml
0
 
mmcwAuthor Commented:
It did work to day
Problem was the reload fuction did not work
Changed it to load the page again and it worked!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now