If you're using PHP to add a newsfeed to your site, please be kind to the news feed supplier and cache the feed if your page is a popular one. I posted a couple of weeks ago ... a link to a piece of code that grabs a news feed .... and I've enhanced it now to do the caching. Here's the modified code:
$feed = "http://thescotsman.scotsman.com/uk.cfm?format=rss";
$copy = 1;
if (time() - @filemtime("haggis.xml") < 120) {
$feed = "haggis.xml";
$copy = 0;
}
$fh = fopen($feed,"r");
if ($copy) $saver = fopen("haggis.xml","w");
while ($xmlcontent = fread($fh,1024)) {
if ($copy) fputs($saver,$xmlcontent);
xml_parse($parser,$xmlcontent,feof($fh));
}
Links ...
Previous posting
Original full source code listing
Running Script
(written 2005-08-26, updated 2008-05-17)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
H112 - PHP - Further Web Page and Network Handling [220] When to use Frames - (2005-02-19)
[314] What language is this written in? - (2005-05-17)
[345] Spotting a denial of service attack - (2005-06-12)
[356] Sudoku helper or sudoku cheat - (2005-06-23)
[372] Time calculation in PHP - (2005-07-08)
[376] What brings people to my web site? - (2005-07-13)
[410] Reading a news or blog feed (RSS) in your PHP page - (2005-08-12)
[443] Server side scripting of styles to suit the browser - (2005-09-12)
[451] Accessing a page via POST from within a PHP script - (2005-09-26)
[484] Setting the file name for a downloaded document - (2005-11-03)
[537] Daily Image Santafied - (2005-12-22)
[542] Morning image, afternoon image - (2005-12-26)
[565] Using PHP to output images, XML, Style sheets, etc - (2006-01-15)
[603] PHP - setting sort order with an associative array - (2006-02-13)
[675] Adding PHP tags to an old cgi program - (2006-04-08)
[767] Finding the language preference of a web site visitor - (2006-06-18)
[789] Hot answers in PHP - (2006-07-02)
[847] Image maps for navigation - a straightforward example - (2006-08-28)
[904] Of course I'll tell you by email - (2006-10-25)
[936] Global, Superglobal, Session variables - scope and persistance in PHP - (2006-11-21)
[1009] Passing GET parameters through Apache mod_rewrite - (2006-12-27)
[1114] PHP Image upload script - (2007-03-21)
[1183] Improving searches - from OR to AND? - (2007-05-11)
[1187] Updating a page strictly every minute (PHP, Perl) - (2007-05-14)
[1210] PHP header() function - uses and new restrictions - (2007-05-30)
[1355] .php or .html extension? Morally Static Pages - (2007-09-17)
[1379] Simple page password protection - PHP - (2007-10-04)
[1485] Copyright and theft of images, bandwidth and members. - (2007-12-26)
[1495] Single login and single threaded models - Java and PHP - (2008-01-04)
[1496] PHP / Web 2 logging - (2008-01-06)
[1505] Script to present commonly used images - PHP - (2008-01-13)
[1515] Keeping staff up to date on hotel room status - (2008-01-22)
[1518] Downloading data for use in Excel (from PHP / MySQL) - (2008-01-25)
[1549] http, https and ajp - comparison and choice - (2008-02-22)
[2632] Shipping a test harness with your class in PHP - (2010-02-12)
[2679] How to build a test harness into your PHP - (2010-03-16)
[2729] Uploading a document or image to its own URL via a browser - (2010-04-18)
[2918] Downloading a report from the web for further local analysis - (2010-08-13)
[3036] Sending out an email containing HTML from within a PHP page - (2010-11-07)
[3432] 3 digit HTTP status codes - what are they, which are most common, which should be a concern? - (2011-09-11)
[3540] Easy session example in PHP - keeping each customers data apart - (2011-12-06)
[3568] Telling which ServerAlias your visitor used - useful during merging domains - (2012-01-04)
[3918] Multiple page web applications - maintaining state - PHP - (2012-11-10)
[4070] Passing variable between PHP pages - hidden fields, cookies and sessions - (2013-04-26)
[4483] Moving from mysql to mysqli - simple worked example - (2015-05-03)
G905 - Well House Consultants - Blogging and Blog Administration [1] First Jottings - (2004-08-05)
[6] Blog v Forum - (2004-08-07)
[18] Wanted: More hours in the day - (2004-08-18)
[141] Too technical? - (2004-12-05)
[145] A comment on comments - (2004-12-09)
[177] Blogs come of age - (2005-01-14)
[185] Who am I? - (2005-01-21)
[204] The confidence to allow public comments - (2005-02-06)
[231] Feedback as lifeblood - (2005-02-28)
[245] I'm not blogging it - (2005-03-14)
[359] Chicken soup without the religion - (2005-06-26)
[390] Moderating wiki, blog, and forum contributions - (2005-07-26)
[405] Horse's Mouth is a year old - (2005-08-07)
[508] Comment, please! - (2005-11-28)
[671] Both ends of the animal - (2006-04-05)
[876] Making pages clearer - easy Disability Discrimination Act Compliance - (2006-09-23)
[1000] One Thousand Posts and still going strong - (2006-12-18)
[1077] In answer to 'am I glad I started a blog' ... - (2007-02-12)
[1203] A Fresh horse - (2007-05-24)
[1978] From spam to mod_alias - finding resources - (2009-01-05)
[2000] 2000th article - Remember the background and basics - (2009-01-18)
[2192] Copy writing - allowing for the cut - (2009-05-21)
[2449] Four aspects - Chamber, Transport, Courses and Hotel - (2009-10-11)
[2517] Blogging accuracy - open invitation for any corrections - (2009-11-29)
[2564] Microblogging services - Plurk, Twitter, Jaiku and more - (2010-01-05)
[2751] Going off at a tangent, for a ramble - (2010-05-04)
[2823] Where have all the bloggers gone? - (2010-06-24)
[3016] The legal considerations of your web presence - revisited - (2010-10-26)
[3163] Twitter - the special use of @ # and http: in tweets - (2011-02-09)
[3186] How to add a customised twitter feed to your site - (2011-02-27)
[3208] Links for social media, microblogs and business networking - (2011-03-20)
[3514] Microblogging - what I should have tweeted in the last 48 hours - (2011-11-10)
[3759] The five oldest blogs and the horses mouth - (2012-06-09)
[4000] 9 years, and 4000 articles on - (2013-02-09)
[4121] Has your Twitter feed stopped working? Switching to their new API - (2013-06-23)
[4292] The Horse is back! - (2014-09-15)
[4568] Moderation - and the tendency to over-moderate - (2015-11-02)
[4714] The technical article feed continues - personal updates more proactive on Facebook now! - (2016-10-30)
Some other Articles
Charlie on MondaySwindon - Chippenham - Melksham - Trowbridge - Westbury train serviceThe Melksham train - a button is pushedRobust checking of data entered by usersCaching an XML feedHow not to run a forumA Victorian LadyPHP Magic QuotesDon't repeat code - use loops or functionsTowards Tebay