KBD

Keith Devens .com

Friday, August 29, 2008 Flag waving
... be conservative in what you do, be liberal in what you accept from others. – Jon Postel (RFC 793)
← Kerry unfit to be Commander in ChiefConditional get →

Daily link icon Monday, May 3, 2004

del.icio.us links now cron'd

I finally got the impetus to cron my del.icio.us links over on the right. The format can be improved, but I'm in a hurry, so I'll do that later.

Hmm... might as well share the source. First, the cron:

<?php
$location 
'http://del.icio.us/html/keith?extended=body';
if(!
$file = @file_get_contents($location)){
    if(!
$file = @file_get_contents($location)){ #try one more time
        
die("Couldn't get $location");
    }
}
$f = @fopen('/home/keith/kbdcms/Data/delicious.html','w') or die("Couldn't open file");
fwrite($f,$file);
fclose($f);
?>

That's currently set to run every 90 minutes. Next, the part of my template which fetches the thing:

<h2 id="delicious">del.icio.us links:</h2>
<?php readfile('/.../delicious.html');?>

Piece of cake. Someone asked me the other day what's good about PHP, why I'd use it, etc. This is an example of it. If I had PHP5, I could have done away with fopen(), etc. and just used file_put_contents() and saved two lines. Smiley

Update: Updated the source a bit. Incidentally, I'm wondering if I've been confused about PHP's scoping behavior.

← Kerry unfit to be Commander in ChiefConditional get →

Comments XML gif

66.100.151.131 wrote:

Or you could have done include('http://del.icio.us/html/keith?extended=body');

That would be sweet!

Sorry, I shouldn't even say such things. Including remote URLs (whose contents are then parsed, I believe?) is bad. Doing that on every page load is pretty bad too.

∴ 66.100.151.131 | 3-May-2004 4:36pm est | #4488

Keith (http://keithdevens.com/) wrote:

Well, I could do something like:

echo file_get_contents('http://del.icio.us/html/keith?extended=body');

which wouldn't interpret the contents as PHP. Yes, include()ing remotely is bad.

But, of course, I can't be hitting del.icio.us on every page request. Not only is it very rude, but it would slow my site down as well.

Keith | 4-May-2004 12:00am est | http://keithdevens.com/ | #4489

Sparticus (http://iamsparticus.co.uk) wrote:

I've had issues with file_get_contents and file_put_contents when I've used them on my test server on my computer. I managed to crash php a few times if they file existed but was empty. I'm thinking it's probably only a winxp problem, but still.

∴ Sparticus | 4-May-2004 4:06am est | http://iamsparticus.co.uk | #4491

Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

August 2008
SunMonTueWedThuFriSat
 12
3456789
10111213141516
17181920212223
24252627282930
31 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 3 posts

Recent comments XML

new⇒WoW Forums -> Tanking in Wrath of the Lich King

 cheap wow gold in www.wow4s.com or​www.agamegold.com.and cheap​powerleveli...

74.53.254.179: Aug 29, 11:19pm

new⇒Johnny Walker Blue Label

Wow, thanks for the scotch review​:D

Lagavulin and Laphroaig are​some of...

Keith: Aug 29, 3:35pm

Girls, please don't get breast implants

Wow, After all this time, the​comments on this page continue to​grow. It wa...

Ajeet: Aug 25, 2:36am

Generated in about 0.145s.

(Used 8 db queries)

mobile phone