You are not logged in.

Announcement

Support Has Moved!

SimplePie support has moved to Yahoo! Groups, and bug tracking has moved to bugs.simplepie.org. This support site will remain available as a read-only archive for the foreseeable future.

#1 31 August 2006 10:32:12

hcgtv
SimplePie Superstar
From: Charlotte, NC
Registered: 12 August 2006
Posts: 120
Website

Using wget & cron to refresh your feeds

On http://txplanet.net - I have 9 feeds coming in from Textpattern sites, a PunBB forum, a MediaWiki wiki and a Trac timeline. When the feeds need to be updated it takes about 15 seconds for the page to load.

So I experimented with using wget in a cron job to refresh the page, I set it up to run every 15 minutes and I have SimplePie configured to refresh the caches every 30 minutes.

Code:

0,15,30,45 * * * * www-data wget -q --spider http://txplanet.net

The cron job runs every 15 minutes just in case a feed hadn't timed out on the previous fetch. The --spider option does not actually grab the page, so there's no worries about where to save the output, it just issues a HEAD instead of a GET which seems to trigger the page to refresh.

Code:

"HEAD / HTTP/1.0" 200 - "-" "Wget/1.9.1"

I'm using Build 20060829 on this site with the 1.2 plugin.


Bert Garcia,  Use the Source: PHPXref

Offline

 

#2 1 September 2006 13:42:17

Skyzyx
Creator and Co-Developer
From: Silicon Valley, CA, USA
Registered: 30 January 2006
Posts: 1567
Website

Re: Using wget & cron to refresh your feeds

We've also built-in HTTP Conditional Get, which means that instead of dumping and refetching the feed in in regular intervals (yours is set to 30 minutes), it will instead ask the server if the feed has changed before dumping and refetching anything.  If it hasn't changed, SimplePie keeps the existing cache file for another 30 minutes.

Even still, running the cron job in the background can definitely keep the speed up.  I'm going to add this post to our tips and tricks section of the "Ideas" page.


SimplePie 1.0 | Trunk Demo | SimplePie Twitter | My Twitter | My LinkedIn

I'm currently working 2 full-time jobs, plus SimplePie. Responses will be lighter until February-ish 2008, but I expect to be available 1-2 times a week to answer questions. To get responses faster, try our IRC chat. irc://irc.freenode.net/simplepie. You must have an IRC client installed.

Offline

 

#3 1 September 2006 14:40:44

hcgtv
SimplePie Superstar
From: Charlotte, NC
Registered: 12 August 2006
Posts: 120
Website

Re: Using wget & cron to refresh your feeds

After a day of experimenting I have some more to add.

The cron job initially was set to run every 15 minutes, then I set it to run every 10 cause the feeds weren't being updated at the 30 minute stage. So I've been watching it to see what the deal is and I think I've come away with an answer.

This is when the cron job runs:

Code:

[01/Sep/2006:17:05:01 -0400] "HEAD / HTTP/1.0" 200 - "-" "Wget/1.9.1"

But these are the timestamps of the most recent caches:

Code:

9/1/2006 5:05:02 to 9/1/2006 5:05:18

When the cron job runs, it could be 30 minutes from the last run but the seconds may be off by a few. So the next run actually refreshes the cache at the 40 minute mark.

Glancing at this code:

Code:

else if ($cache->mtime() + $this->max_minutes * 60 < time())

If the seconds are dropped on the comparison, then the cron job only needs to run every 30 minutes to be effective.


Bert Garcia,  Use the Source: PHPXref

Offline

 

#4 2 September 2006 09:17:34

hcgtv
SimplePie Superstar
From: Charlotte, NC
Registered: 12 August 2006
Posts: 120
Website

Re: Using wget & cron to refresh your feeds

Another day brings enlightenment.

I changed this line in simplepie.inc:

Code:

else if ($cache->mtime() + $this->max_minutes * 60 < time())

To this:

Code:

else if ($cache->mtime() + $this->max_minutes * 60 - 30 < time())

The cron job looks like this now:

Code:

0,30 * * * * www-data wget -q --spider http://txplanet.net

It updates just fine at 30 minute intervals, visitors never have a wait time, happy happy, joy joy smile

Would be nice to have a seconds offset variable, that way we don't have to keep updating the SimplePie parser on subsequent updates.


Bert Garcia,  Use the Source: PHPXref

Offline

 

#5 6 November 2006 18:31:44

jessep
New member
Registered: 6 November 2006
Posts: 1

Re: Using wget & cron to refresh your feeds

Any updates on how this should work now? The code, that you changed here ...

hcgtv wrote:

I changed this line in simplepie.inc:

Code:

else if ($cache->mtime() + $this->max_minutes * 60 < time())

... is no longer there in the current version of simplepie.inc
It's not working for me.

~Jesse

Offline

 

#6 7 November 2006 05:21:13

hcgtv
SimplePie Superstar
From: Charlotte, NC
Registered: 12 August 2006
Posts: 120
Website

Re: Using wget & cron to refresh your feeds

Hi Jesse,

It's still there around line 396:

Code:

// If the cache is new enough
else if ($cache->mtime() + $this->max_minutes * 60 < time())

Bert Garcia,  Use the Source: PHPXref

Offline

 

#7 9 November 2006 17:16:49

Trisha
Member
Registered: 24 October 2006
Posts: 10

Re: Using wget & cron to refresh your feeds

I can't find that line either.  I'm using the multifeed version with Version: 1.0 Beta 2 of simplepie.inc.

Offline

 

#8 21 November 2006 09:59:23

Trisha
Member
Registered: 24 October 2006
Posts: 10

Re: Using wget & cron to refresh your feeds

That line is still in the  “Lemon Meringue” Beta 3.x version. 

Even with that change and the cron set up as above it sometimes still loads pretty slow.  This is with 18 feeds  - each just displaying the most recent post of each.

Offline

 

#9 6 February 2007 07:12:30

Ma2T
New member
Registered: 2 February 2007
Posts: 8

Re: Using wget & cron to refresh your feeds

I added the cron job to my plesk acount under the user of apache,

Every 15mins I recive this email:

"/bin/sh: www-data: command not found"

The email subject is: "Cron <apache@as> www-data wget -q --spider http://www.nufluxmedia.com"

I used the code from the first post in this thread.

Offline

 

#10 6 February 2007 07:58:43

hcgtv
SimplePie Superstar
From: Charlotte, NC
Registered: 12 August 2006
Posts: 120
Website

Re: Using wget & cron to refresh your feeds

Ma2T wrote:

"/bin/sh: www-data: command not found"

See if your host gives you access to wget, some don't.


Bert Garcia,  Use the Source: PHPXref

Offline

 

#11 15 February 2007 10:37:56

kchrist
New member
From: San Francisco, CA
Registered: 15 February 2007
Posts: 1
Website

Re: Using wget & cron to refresh your feeds

Ma2T wrote:

"/bin/sh: www-data: command not found"

Remove "www-data". You only specify a user the cron job runs under if you're editing the system crontab (/etc/crontab). Control panels like Plesk will run cron jobs as you normally, and may allow you to choose another non-privileged user (as it appears you're allowed to run something as the Apache user).

On Debian systems, "www-data" is the web server user. This is the equivalent of ticking a box that says "Run as the Apache user" or whatever you've got there.

Offline

 

#12 22 March 2007 21:13:58

Gr8Dane
New member
Registered: 11 March 2007
Posts: 4

Re: Using wget & cron to refresh your feeds

I'm a new SimplePie user, and would like to refresh my feed this way.  Unfortunately, I know nothing about cron jobs, so I would appreciate any help you could give me in accomplishing this.  Is the code you provided everything that's needed, or is there more to it?  What kind of file would I create this in?  Where would I put it?  I'm sure there are more questions, but these should give you some idea of how clueless I am. ;-)

Offline

 

#13 17 August 2007 12:36:50

catchit
Member
Registered: 15 May 2007
Posts: 46

Re: Using wget & cron to refresh your feeds

I'd love to see some updated methods to be used with SimplePie 1.0.1 !   smile

Offline

 

#14 17 August 2007 14:50:47

hcgtv
SimplePie Superstar
From: Charlotte, NC
Registered: 12 August 2006
Posts: 120
Website

Re: Using wget & cron to refresh your feeds

I'm still running 1.0 b3.2 on all my sites, haven't had a chance to go live with 1.0.1 yet, even though I've been testing it locally.

As soon as I do, I'll put up some updated docs on the wiki.


Bert Garcia,  Use the Source: PHPXref

Offline

 

#15 19 August 2007 01:21:41

Skyzyx
Creator and Co-Developer
From: Silicon Valley, CA, USA
Registered: 30 January 2006
Posts: 1567
Website

Re: Using wget & cron to refresh your feeds

Argh.  I knew I had forgotten something -- the Mediawiki and TXP plugins!  I'll try to get those updated this week.  Ping me if they're not available by the end of the week.


SimplePie 1.0 | Trunk Demo | SimplePie Twitter | My Twitter | My LinkedIn

I'm currently working 2 full-time jobs, plus SimplePie. Responses will be lighter until February-ish 2008, but I expect to be available 1-2 times a week to answer questions. To get responses faster, try our IRC chat. irc://irc.freenode.net/simplepie. You must have an IRC client installed.

Offline

 

#16 29 August 2007 06:59:49

catchit
Member
Registered: 15 May 2007
Posts: 46

Re: Using wget & cron to refresh your feeds

Mediawiki and TXP plugins...  What's the link?

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson