title: How to create a iCal ics Feed in PHP
body: <p>I am looking for specifics in creating an iCal feed, for use in applications such as Google Calendar and on peoples phones.</p>
  
  <p>I currently have a script using the <a href="http://www.kigkonsult.se/iCalcreator/index.php" rel="nofollow">iCalendar</a> class that when the url is visited, an ics file is created and sent to the browser:</p>
  
  <pre><code>  function returnCalendar() {
      $filename = $this-&gt;getConfig( 'filename' );
      $output   = $this-&gt;createCalendar();
      $filesize = strlen( $output );
      if( 'xcal' == $this-&gt;format )
        header( 'Content-Type: application/calendar+xml; charset=utf-8' );
      else
        header( 'Content-Type: text/calendar; charset=utf-8' );
      header( 'Content-Length: '.$filesize );
      header( 'Content-Disposition: attachment; filename="'.$filename.'"' );
      header( 'Cache-Control: max-age=10' );
      echo $output;
      die();
    }
  </code></pre>
  
  <p>I would like (as I previously mentioned) to create a feed (a unique url per user), and was wondering about the techicalities of this? I was thinking I would need a cronjob to just generate a calandar for everyone and then link users to this feed, however this seems very inefficient if say only one user is using the feed.</p>
  
  <p>Would it be possible to set the script to only run when someone requested a calandar and then send them the appropriate one back? </p>
  
  <p>Does anyone know how often Google Calandar etc updates, how it works and how I can test it?</p>
  
  <p>Many thanks for your time,</p>