SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2008
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

  2. #2
    SitePoint Zealot Mattinblack's Avatar
    Join Date
    May 2009
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    This should even out server loading.

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2008
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Mattinblack,

    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

  4. #4
    SitePoint Zealot Mattinblack's Avatar
    Join Date
    May 2009
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dantheman50_98 View Post
    Hi Mattinblack,

    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!

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2008
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I still have had no luck sorting this out. Does anybody have a solution to this? Any help massively appreciated.
    Cheers,
    Dan


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •