This is the handling class of the cron service.

When executed, it checks all component manifests for cron jobs and runs them sequentially. The components are processed in the order they are returned by the component loader, the jobs of a single component are run in the order they are listed in the configuration array.

Cron Job configuration

Each cron job is defined by an associative array containing the following keys:

  • string handler holds the full class name which should handle the cron job invocation, it will be defined by the responsible component.
  • Array handler_config is the handler specific configuration of the cron job. This is optional and can therefore be an empty array. It is used to customize cron job behavior on a manifest level only (use your component configuration for more specific settings.)
  • int recurrence must be one of MIDCOM_CRON_* constants.
  • string component (INTERNAL) holds the name of the component this Cron job is associated with. This key is created automatically.

The Cron service uses customdata section of the manifest, using the key as you might have guessed. So, an example cron entry could look like this:

'customdata' => Array
    '' => Array
            'handler' => 'net_nehmer_static_cron_test',
            'handler_config' => Array ('test', 'configuration', 'entries'),
            'recurrence' => MIDCOM_CRON_MINUTE,

A simple (and useless) handler class would look like this:

        $this->print_error(strftime('%x %X'));


Cron Job implementation suggestions

You should keep output to stdout to an absolute minimum. Normally, no output whatsoever should be made, as the cron service itself is invoked using some kind of Cron Daemon. Only if you output nothing, no status mail will be generated by cron.

Launching MidCOM Cron from a System Cron

You need to request the midcom-exec-midcom/cron.php page of your website to have cron running. Lynx or the GET command line tools can be used, for example, to retrieve the cron page:

lynx -source

The script produces no output unless anything goes wrong.

At this time, this script does also do a request_sudo to gain Administrator privileges. This is a temporary workaround until we can deal with HTTP authentication at this point.



__construct ($recurrence)




_execute_job (array $job)

Executes the given job.



arrayThe job to execute.

execute ()

This is the main cron handler function.

load_jobs (array $data)

This helper function loads and validates all registered jobs.

After this call, all required handler classes will be available.



arrayThe job configurations

_validate_job (array $job)

This function checks a jobs definition for validity.



arrayThe job to register.


booleanIndicating validity.



array $_jobs

The list of jobs to run.

See the class introduction for a more precise definition of these keys.


Array $_midcom_jobs

Jobs specific to the MidCOM core not covered by any component.

(Services use this facility for example.)

todo Factor this out into its own configuration file.

int $_recurrence

The recurrence rule to use, one of the MIDCOM_CRON_* constants (MIDCOM_CRON_MINUTE, MIDCOM_CRON_HOUR, MIDCOM_CRON_DAY).

Set in the constructor