The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Cron job problems with Carp

Hi,

I have been using the CaRP RSS to html converter and for this I implemented over 50 cron jobs (one for each news category on a website) to keep things speedy.
Recently they were all cut off due to them being a big drain on server resources. The solution to this I was told, is to use a script similar to this (which I have named "update.php":

Code:

<?php
# Create the associative array as LongName => ShortName
# Add as many as needed. Be sure to use a comma at the end.
$celebs = array(
'GeorgeClooney' => 'clooney',
'CherylCole' => 'cole',
'Couples' => 'couples',
'Actors' => 'actors',
);
# Loop through every item in the array and perform some action.
foreach ( $celebs as $lname => $sname ) {
echo "Do something for long name $lname or for short name $sname\n";
}
?>
<?php # Create the associative array as LongName => ShortName # Add as many as needed. Be sure to use a comma at the end. $celebs = array( 'GeorgeClooney' => 'clooney', 'CherylCole' => 'cole', 'Couples' => 'couples', 'Actors' => 'actors', ); # Loop through every item in the array and perform some action. foreach ( $celebs as $lname => $sname ) { echo "Do something for long name $lname or for short name $sname\n"; } ?>

Now, I have done this, but the echo statement is apparently not appropriate and instead the CarpConf and CarpCache functions in the following script should be put in its place. The problem is that I have about 50 odd scripts to run and I fail to see how I can achieve this with one mention of the the Carp functions.

So, for example, I have the update_actors.php script, as follows:

Code:

<?php
require_once '/usr/local/apache/celebsusa/carp/carp/carp.php';
/* set the cache interval to 1 minute (you'll control how often the cache is actually refreshed with your cron settings, not here) */
CarpConf('cacheinterval',1);
CarpCache('http://feeds.feedburner.com/actorsc','actors');
?>
<?php require_once '/usr/local/apache/celebsusa/carp/carp/carp.php'; /* set the cache interval to 1 minute (you'll control how often the cache is actually refreshed with your cron settings, not here) */ CarpConf('cacheinterval',1); CarpCache('http://feeds.feedburner.com/actorsc','actors'); ?>

I have added the variable "?value=actors" to the URL of this script in the hope of it being picked up and run by the update.php script. This hasn't happened though.

Therefore, there is obviously something missing here and it must be the CarpCache and CarpConf parts of the update script.

Does anyone have any idea how I can get this working?

Thanks,
Dan

ps. I have posted on the Carp forums and also the Daniweb forums but with no luck as of yet unfortunately.

It sounds to me like you are not caching your data but building everything from RSS as required. This is a bad idea. Not many RSS files update more than twice a day anyhow some no more than once a week.

Better to have your 50 carp commands (as you had in cronjobs) in a file with a time variable, execute one each time your main page is loaded (providing the timer is timed out) and set the timers for 30 min intervals. Then when you have the carp data write it to a file and when you display always go to this file to display and not straight to carp.

Thanks for the reply. There is one snag here: I don't have a clue how to do what you just to told me. I would rather modify what I am working with already as I at least think I have a slight grasp on how it works.
Also, most of the rss feeds are from quite active sites so are updated frequently.

Thanks for the reply. There is one snag here: I don't have a clue how to do what you just to told me. I would rather modify what I am working with already as I at least think I have a slight grasp on how it works.
Also, most of the rss feeds are from quite active sites so are updated frequently.

Cheers,
Dan

Oops sorry. Kind of assumed since you were posting PHP code you knew your way around... will shut up now!