An extension can run some of its routines periodically, for example, every 10 minutes, every hour, or daily. This scheduler interface manages the crontab utility on Linux and the Task Scheduler application on Windows. The interface is presented by two classes - pm_Scheduler and pm_Scheduler_Task. The first class represents a task manager and the second class represents a task.

To successfully schedule a task, your code must meet the following requirements:

  • Put a scheduled task under /plib/scripts/ relatively to the extension’s root directory.
  • Initialize the extension context (pm_Context::init) before scheduling a task.
  • Schedule the task using pm_Scheduler and pm_Scheduler_Task.


This sample code adds a periodic task to the scheduler. The following methods of pm_Scheduler_Task are used:

The code can look as follows:

$task = new pm_Scheduler_Task();
    'minute' => '0,4,9,14,19,24,29,34,39,44,49,54,59',
    'hour' => '*',
    'dom' => '*',
    'month' => '*',
    'dow' => '*'
var_dump($task->getId()); // Save task id in order to remove it if necessary

See an example of using scheduled tasks in Exercise 2.

Designing a Run Schedule

When designing a run schedule, you should pay attention to the following operating-system differences:

  • On Linux, the schedule may be specified in the cron format. Learn more about the format at:

  • On Windows, the schedule may be set by using commas (,) and asterisks (*).

  • We recommend that you use the following cross-platform constants when defining a period between two task runs:








  • On Windows, a task is limited to 48 different start conditions (triggers). Learn more about triggers and the limitation at:

Listing Tasks

If you need to loop through scheduled tasks, do it in the following way:

$tasks = pm_Scheduler::getInstance()->listTasks();
foreach ($tasks as $task) {

Removing Scheduled Tasks

We highly recommend that you save IDs of your scheduled tasks to the key-value storage and then remove the tasks during the removal of your extension. The following code removes a task:

$task = pm_Scheduler::getInstance()->getTaskById('64daef15d48e0fe038bb20a77a171150');

Passing Arguments to Tasks

If you need to pass certain arguments to a task, use the setArguments method. The following code creates a task with arguments:

$task = new pm_Scheduler_Task();
$task->setArguments(array('john', 'robert', 'ivan'));

To retrieve a task’s arguments, use the getArguments method, for example, in the following way:


Note that a task ID is assigned by the putTask method.