📚 Encyclopedia

Web Development · updated 2026-11-02

Generating iCalendar (.ics) files and subscribe feeds

icalendaricsrfc5545calendartimezonesrecurrencephp

An .ics file (iCalendar, RFC 5545) is how a web page hands an event to Google Calendar, Apple Calendar or Android's calendar apps. The same format served at a stable URL is a subscribe feed: the calendar app re-downloads it periodically and shows the events read-only. The format is plain text but strict, and calendar apps silently drop events that break the rules. The notes below come from the cal.jhampton.io web app (PHP + SQLite), which serves a feed per shared calendar (/s/<viewKey>.ics) and one file per shared event (/e/<shareKey>.ics).

Skeleton

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//example.com//Calendar//EN
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:Team calendar          (feeds only: display name)
REFRESH-INTERVAL;VALUE=DURATION:PT1H  (feeds only: refresh hint)
X-PUBLISHED-TTL:PT1H                 (same hint, older clients)
BEGIN:VTIMEZONE ... END:VTIMEZONE    (one per TZID used)
BEGIN:VEVENT
UID:<stable-id>@example.com
DTSTAMP:20261027T150000Z
DTSTART:20261101T180000Z
DTEND:20261101T190000Z
SUMMARY:Dinner
END:VEVENT
END:VCALENDAR

Serve it as Content-Type: text/calendar; charset=utf-8 with Content-Disposition: inline; filename="name.ics" (sanitize the filename).

Rules that bite

Time zones and recurring events

Feeds vs files

See also

Linked from

Sources: calendar memory (calendar-web), calendar repo (web/public/index.php), tldr post #1854