There's some other choice(s) here as well.
You could have javascript set to check at regular intervals (like once a second or something), using SetInterval(), for an updated "message" from the server, and if it gets the "refresh" message, it does a window.reload() refresh command.
... you say, how does javascript do that... well i'm glad you asked...
1. (probably best method) a hidden iframe/layer, where you can send URL requests through to a PHP script, and then "parse" the response output that is returned to inside that iframe/layer.
2. have javascript on it's timeout instantiate a new Image object, and set it's source to the location of a PHP script, and then the response is like yes or no depending on if an event like a refresh should be initiated. The way javascript knows the "yes" or "no" is to check to see if the image loaded successfully (and then in your PHP simply fail to send back an image stream correctly if you want to indicate a "yes", by throwing a "404 not found" header back)... this might look something like:
Code:
var img = new Image();
img.onerror=fnRefresh;
img.src = "[URL unfurl="true"]http://www.myurl.com/myscript.php?gmsg=123";[/URL]
function fnRefresh() {
window.reload();
}
FYI:
a. this method is asynchronus, meaning you can't expect for an immediate yes/no answer from the setting of .src, to decide what to do next... (in other words, the img.src= command does NOT wait to see a response from the server before going on to the next command). you have to have a call-back method as above, to handle the "error" a split second later.
b. it looks like IE might sorta "cache" a call to an image that returns a "valid" response (in other words, no error). Subsequent calls to the image with the exact same URL will not fire the error, even if the image is gone, or your php script returns an invalid image stream (404 error, etc). To get around this, just make sure the URL that you use to load the image src has a random number on the end of it, like:
img.src = "
that r= parameter can be ignored by your PHP script, you are simply trying to make sure the "URL" of your image request is ALWAYS different to defeat the cache'ing done by the browser.
3. This option is IE only, but is very reliable, and is synchronous. it uses the built in HTTPClient (activeX) plugin that IE has by default, which allows your code to execute a sub-request to a URL, and you can then parse it's results, much like if there had been a hidden iframe/layer making the request.