KBD

Keith Devens .com

Sunday, March 21, 2010 Flag waving
Any sufficiently complicated C or Fortran program contains an ad hoc, informally specified, bug-ridden, slow implementation of half of... – Philip Greenspun (Greenspun's Tenth Rule)
← 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)
:

March 2010
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
28293031 



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⇒Spider solitaire

I to am somewhat addicted to​spending too much time on SS.  I​have been stu...

stupid_horse: Mar 20, 10:34pm

I hate ASP.NET

I hate ASP... I was doing wonders​with PHP, then suddenly one of my​clients...

Johnies: Mar 17, 6:14am

Quantum physics and free will

I knew you were going to say that....

Tom Massey: Mar 15, 9:26pm

Generated in about 0.119s.

(Used 8 db queries)