Another solution is to set up background refreshing of your cache files. This is done by setting up a "cron job" to periodically load a web page containing the newsfeeds. When setting up such a system, note the following points:
update_news.php
This file is loaded by "update_news.pl", show below, to cache a copy of the newsfeed on your server for quick access:
your_webpage.php
Now that you have the newsfeed cached on your server, you can access it on the page where you want it displayed like this:
update_news.pl
Depending on your PHP setup, cron jobs may not be able to load and execute PHP files directly.
Even if they can, it is usually preferable to have the cron job execute a script which loads the PHP file to ensure that there are no problems with file access and that you don't get an unnecessary email every time the cron job runs.
This is a script written in Perl which is executed by cron to connect to the web server and load update_news.php. Refer to the documentation for cron for instructions on how to set up the cron job on your server:
Note that you'll need to change "www.yourwebsite.com" (near the top) and "/path/to/update_news.php" (near the bottom) to the appropriate values for your setup. IMPORTANT: The path to update_news.php should NOT be the full path on the server, but the path that a web browser would specify. For example, if a web browser would load the page as http://www.geckotribe.com/rss/update_news.php", the appropriate path would be /rss/update_news.php.
The cron job can run on a different computer from the webserver. When doing that, enter the hostname of the computer where the cron job is running in the "$hostname=" line.
use Socket;
$hostname='www.yourwebsite.com';
$remote_host='www.yourwebsite.com';
$sockaddr = 'S n a4 x8';
$proto=getprotobyname('tcp');
($name, $aliases, $type, $len, $thisaddr) = gethostbyname($hostname);
($name, $aliases, $type, $len, $thataddr) = gethostbyname($remote_host);
$this = pack($sockaddr, &AF_INET, 0, $thisaddr);
$that = pack($sockaddr, &AF_INET, 80, $thataddr);
socket(S, &AF_INET, &SOCK_STREAM, $proto)||die "socket: $!";
bind(S,$this)||die "bind: $!";
connect(S,$that)||die "connect: $!";
select(S); $|=1; select(STDOUT);
print S "GET /path/to/update_news.php HTTP/1.0\nHost: $remote_host\n\n";
while ($line=<S>) { }
close(S);
exit 0;