What's wrong with an ad rotation script like this?

Discussion in 'PHP' started by phree_radical, Sep 26, 2006.

  1. #1
    <?php
    
      function load_setting() {
        return (int) trim( file_get_contents( 'setting.pedro' ) );
      }
    
      function load_counter() {
        return (int) trim( file_get_contents( 'counter.pedro' ) );
      }
    
      function load_adcode($which) {
        return trim( file_get_contents( "ad{$which}.pedro" ) );
      }
    
      function save_counter($count) {
        file_put_contents('counter.pedro',$count);
      }
    
      $counter = 1 + load_counter();
      if($counter >= load_setting())
        $counter = 0;
      save_counter($counter);
      echo load_adcode($counter);
    
    ?>
    Code (markup):
    Is it smart to save data to files like this? And any other suggestions?
     
    phree_radical, Sep 26, 2006 IP
  2. ThomasNederman

    ThomasNederman Peon

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why do you need to load the counters ? Would be better for performance If you dont load the counters every time.

    You could make a cron job every hour to count the stats, not every time someone load the page.

    You have one log file that saves what ad is published and you make a summary every hour.
     
    ThomasNederman, Sep 26, 2006 IP