Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg

PHP : Function Reference : MCAL Functions

MCAL Functions


MCAL stands for Modular Calendar Access Library.

Libmcal is a C library for accessing calendars. It's written to be very modular, with pluggable drivers. MCAL is the calendar equivalent of the IMAP module for mailboxes.

With mcal support, a calendar stream can be opened much like the mailbox stream with the IMAP support. Calendars can be local file stores, remote ICAP servers, or other formats that are supported by the mcal library.

Calendar events can be pulled up, queried, and stored. There is also support for calendar triggers (alarms) and recurring events.

With libmcal, central calendar servers can be accessed, removing the need for any specific database or local file programming.

Most of the functions use an internal event structure that is unique for each stream. This alleviates the need to pass around large objects between functions. There are convenience functions for setting, initializing, and retrieving the event structure values.


This extension has been moved to the PECL repository and is no longer bundled with PHP as of PHP 5.0.0.


PHP had an ICAP extension previously, but the original library and the PHP extension is not supported anymore. The suggested replacement is MCAL.


This extension is not available on Windows platforms.


This extension requires the mcal library to be installed. Grab the latest version from and compile and install it.


After you installed the mcal library, to get these functions to work, you have to compile PHP -with-mcal[=DIR].

Runtime Configuration

This extension has no configuration directives defined in php.ini.

Resource Types

This extension has no resource types defined.

Predefined Constants

The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

MCAL_SUNDAY (integer)
MCAL_MONDAY (integer)
MCAL_TUESDAY (integer)
MCAL_FRIDAY (integer)
MCAL_JANUARY (integer)
MCAL_MARCH (integer)
MCAL_APRIL (integer)
MCAL_MAY (integer)
MCAL_JUNE (integer)
MCAL_JULY (integer)
MCAL_AUGUST (integer)
MCAL_OCTOBER (integer)
MCAL_M_SUNDAY (integer)
MCAL_M_MONDAY (integer)
MCAL_M_TUESDAY (integer)
MCAL_M_FRIDAY (integer)
MCAL_M_WEEKEND (integer)
MCAL_M_ALLDAYS (integer)

Table of Contents

mcal_append_event — Store a new event into an MCAL calendar
mcal_close — Close an MCAL stream
mcal_create_calendar — Create a new MCAL calendar
mcal_date_compare — Compares two dates
mcal_date_valid — Returns TRUE if the given year, month, day is a valid date
mcal_day_of_week — Returns the day of the week of the given date
mcal_day_of_year — Returns the day of the year of the given date
mcal_days_in_month — Returns the number of days in a month
mcal_delete_calendar — Delete an MCAL calendar
mcal_delete_event — Delete an event from an MCAL calendar
mcal_event_add_attribute — Adds an attribute and a value to the streams global event structure
mcal_event_init — Initializes a streams global event structure
mcal_event_set_alarm — Sets the alarm of the streams global event structure
mcal_event_set_category — Sets the category of the streams global event structure
mcal_event_set_class — Sets the class of the streams global event structure
mcal_event_set_description — Sets the description of the streams global event structure
mcal_event_set_end — Sets the end date and time of the streams global event structure
mcal_event_set_recur_daily — Sets the recurrence of the streams global event structure
mcal_event_set_recur_monthly_mday — Sets the recurrence of the streams global event structure
mcal_event_set_recur_monthly_wday — Sets the recurrence of the streams global event structure
mcal_event_set_recur_none — Sets the recurrence of the streams global event structure
mcal_event_set_recur_weekly — Sets the recurrence of the streams global event structure
mcal_event_set_recur_yearly — Sets the recurrence of the streams global event structure
mcal_event_set_start — Sets the start date and time of the streams global event structure
mcal_event_set_title — Sets the title of the streams global event structure
mcal_expunge — Deletes all events marked for being expunged
mcal_fetch_current_stream_event — Returns an object containing the current streams event structure
mcal_fetch_event — Fetches an event from the calendar stream
mcal_is_leap_year — Returns if the given year is a leap year or not
mcal_list_alarms — Return a list of events that has an alarm triggered at the given datetime
mcal_list_events — Return a list of IDs for a date or a range of dates
mcal_next_recurrence — Returns the next recurrence of the event
mcal_open — Opens up an MCAL connection
mcal_popen — Opens up a persistent MCAL connection
mcal_rename_calendar — Rename an MCAL calendar
mcal_reopen — Reopens an MCAL connection
mcal_snooze — Turn off an alarm for an event
mcal_store_event — Modify an existing event in an MCAL calendar
mcal_time_valid — Returns TRUE if the given hour, minutes and seconds is a valid time
mcal_week_of_year — Returns the week number of the given date

Code Examples / Notes » ref.mcal


MCAL is a great little package, but has changed quite a bit since the documentation has been updated.  If you're having trouble stop by and pop a question onto the mcal users mailing list and we'll be happy to help you out.


Correction to previous extensive note:
ANDing distinct bit values will always result in zero, so your weekly events won't ever be raised. You must use the bitwise-or operator (|) to combine several week days.
mcal_event_set_recur_weekly takes an additional integer parameter
"weekdays" which is basicly a binary mask created by bitwise
ORing together integers representing the days of the week.
Sunday = 1
Monday = 2
Tuesday = 4
Wednesday = 8
Thursday = 16
Friday = 32
Saturday = 64
So if I wanted the value needed to raise the event every "Monday, Wednesday, and Friday" I would do this:
$weekdays = 2 | 8 | 32;


As of 7/3/2001, libmcal can be built shared (, which should get rid of the linking problem with the MySQL driver. Check the latest version out of the repository if you're planning on building it this way.


After a thorough search of the web for documentation of how recurence works in MCAL, or even for documentation of the recurence function parameters, I found nothing.  So, I gave up and dove into the MCAL source code for answers, and this is what I have found.  Please keep in mind that this is all "As far as I can tell" information.
First of all, I believe that mcal_list_events DOES return events that recur in the range being searched.
The mcal_event_set_recur_* functions take in an mcal stream, and date for the event to stop recuring by (given by day, month, year), and an "interval".
mcal_event_set_recur_weekly takes an additional integer parameter "weekdays" which is basicly a binary mask created by bitwise ANDing together integers representing the days of the week.
Sunday = 1
Monday = 2
Tuesday = 4
Wednesday = 8
Thursday = 16
Friday = 32
Saturday = 64
So if I wanted the value that represented  "Monday, Wednesday, and Friday" I would do this:
$weekdays = 2 & 8 & 32;
Here is how to interpret "interval" and "weekdays".
For mcal_event_set_recur_daily:
This event should recur every "interval" days.
For mcal_event_set_recur_weekly:
This event should recur on every day specified in "weekdays", and should do so every "interval" weeks.
For mcal_event_set_recur_monthly_mday:
This event should recur on the "interval" day of every month.
For mcal_event_set_recur_monthly_wday:
This event should recur every on every Xday of the Yth week of the month, every "interval" months. (Where Xday is a day of the week, e.g. Monday, Tuesday, etc.  Note: This is the one I am the least sure about though it seems to be the logical assumption for how it should work based on the fact that there are two monthly functions and the other one's operation is intuitive.)
For mcal_event_set_recur_yearly:
This event should recur every "interval" years.

Change Language

Follow Navioo On Twitter
.NET Functions
Apache-specific Functions
Alternative PHP Cache
Advanced PHP debugger
Array Functions
Aspell functions [deprecated]
BBCode Functions
BCMath Arbitrary Precision Mathematics Functions
PHP bytecode Compiler
Bzip2 Compression Functions
Calendar Functions
CCVS API Functions [deprecated]
Class/Object Functions
Classkit Functions
ClibPDF Functions [deprecated]
COM and .Net (Windows)
Crack Functions
Character Type Functions
Cybercash Payment Functions
Credit Mutuel CyberMUT functions
Cyrus IMAP administration Functions
Date and Time Functions
DB++ Functions
Database (dbm-style) Abstraction Layer Functions
dBase Functions
DBM Functions [deprecated]
dbx Functions
Direct IO Functions
Directory Functions
DOM Functions
DOM XML Functions
enchant Functions
Error Handling and Logging Functions
Exif Functions
Expect Functions
File Alteration Monitor Functions
Forms Data Format Functions
Fileinfo Functions
filePro Functions
Filesystem Functions
Filter Functions
Firebird/InterBase Functions
Firebird/Interbase Functions (PDO_FIREBIRD)
FriBiDi Functions
FrontBase Functions
FTP Functions
Function Handling Functions
GeoIP Functions
Gettext Functions
GMP Functions
gnupg Functions
Haru PDF Functions
hash Functions
Hyperwave Functions
Hyperwave API Functions
i18n Functions
IBM Functions (PDO_IBM)
iconv Functions
ID3 Functions
IIS Administration Functions
Image Functions
Imagick Image Library
Informix Functions
Informix Functions (PDO_INFORMIX)
Ingres II Functions
IRC Gateway Functions
PHP / Java Integration
JSON Functions
LDAP Functions
libxml Functions
Lotus Notes Functions
LZF Functions
Mail Functions
Mailparse Functions
Mathematical Functions
MaxDB PHP Extension
MCAL Functions
Mcrypt Encryption Functions
MCVE (Monetra) Payment Functions
Memcache Functions
Mhash Functions
Mimetype Functions
Ming functions for Flash
Miscellaneous Functions
mnoGoSearch Functions
Microsoft SQL Server Functions
Microsoft SQL Server and Sybase Functions (PDO_DBLIB)
Mohawk Software Session Handler Functions
mSQL Functions
Multibyte String Functions
muscat Functions
MySQL Functions
MySQL Functions (PDO_MYSQL)
MySQL Improved Extension
Ncurses Terminal Screen Control Functions
Network Functions
Newt Functions
NSAPI-specific Functions
Object Aggregation/Composition Functions
Object property and method call overloading
Oracle Functions
ODBC Functions (Unified)
ODBC and DB2 Functions (PDO_ODBC)
OpenAL Audio Bindings
OpenSSL Functions
Oracle Functions [deprecated]
Oracle Functions (PDO_OCI)
Output Control Functions
Ovrimos SQL Functions
Paradox File Access
Parsekit Functions
Process Control Functions
Regular Expression Functions (Perl-Compatible)
PDF Functions
PDO Functions
Phar archive stream and classes
PHP Options&Information
POSIX Functions
Regular Expression Functions (POSIX Extended)
PostgreSQL Functions
PostgreSQL Functions (PDO_PGSQL)
Printer Functions
Program Execution Functions
PostScript document creation
Pspell Functions
qtdom Functions
Rar Functions
GNU Readline
GNU Recode Functions
RPM Header Reading Functions
runkit Functions
SAM - Simple Asynchronous Messaging
Satellite CORBA client extension [deprecated]
SCA Functions
SDO Functions
SDO XML Data Access Service Functions
SDO Relational Data Access Service Functions
SESAM Database Functions
PostgreSQL Session Save Handler
Session Handling Functions
Shared Memory Functions
SimpleXML functions
SNMP Functions
SOAP Functions
Socket Functions
Standard PHP Library (SPL) Functions
SQLite Functions
SQLite Functions (PDO_SQLITE)
Secure Shell2 Functions
Statistics Functions
Stream Functions
String Functions
Subversion Functions
Shockwave Flash Functions
Swish Functions
Sybase Functions
TCP Wrappers Functions
Tidy Functions
Tokenizer Functions
Unicode Functions
URL Functions
Variable Handling Functions
Verisign Payflow Pro Functions
vpopmail Functions
W32api Functions
WDDX Functions
win32ps Functions
win32service Functions
xattr Functions
xdiff Functions
XML Parser Functions
XML-RPC Functions
XMLReader functions
XMLWriter Functions
XSL functions
XSLT Functions
YAZ Functions
YP/NIS Functions
Zip File Functions
Zlib Compression Functions
eXTReMe Tracker