Example #1
0
        // If we don't have a last rotated time, it's effectively now
        if ($this->lastRotated == NULL) {
            $this->lastRotated = time();
        }
        // Looking good, return the resource
        return $this->statusStream;
    }
    /**
     * Rotates the stream file if due
     */
    private function rotateStreamFile()
    {
        // Close the stream
        fclose($this->statusStream);
        // Create queue file with timestamp so they're both unique and naturally ordered
        $queueFile = $this->queueDir . '/' . self::QUEUE_FILE_PREFIX . '.' . date('Ymd-His') . '.queue';
        // Do the rotate
        rename($this->streamFile, $queueFile);
        // Did it work?
        if (!file_exists($queueFile)) {
            throw new Exception('Failed to rotate queue file to: ' . $queueFile);
        }
        // At this point, all looking good - the next call to getStream() will create a new active file
        $this->log('Successfully rotated active stream to queue file: ' . $queueFile);
    }
}
// End of class
// Start streaming/collecting
$sc = new GhettoQueueCollector('username', 'password');
$sc->setTrack(array('morning', 'goodnight', 'hello', 'the', 'and'));
$sc->consume();
Example #2
0
  }
  
  /**
   * Rotates the stream file if due
   */
  private function rotateStreamFile()
  {
    // Close the stream
    fclose($this->statusStream);
    
    // Create queue file with timestamp so they're both unique and naturally ordered
    $queueFile = $this->queueDir . '/' . self::QUEUE_FILE_PREFIX . '.' . date('Ymd-His') . '.queue';
    
    // Do the rotate
    rename($this->streamFile, $queueFile);
    
    // Did it work?
    if (!file_exists($queueFile)) {
      throw new Exception('Failed to rotate queue file to: ' . $queueFile);
    }
    
    // At this point, all looking good - the next call to getStream() will create a new active file
    $this->log('Successfully rotated active stream to queue file: ' . $queueFile);
  }
  
} // End of class

// Start streaming/collecting
$sc = new GhettoQueueCollector('newshorts', 'kGD_00bouer');
$sc->setTrack(array('sfsuperbowl', 'vanilla'));
$sc->consume();