Skip to content

Use timer and cron jobs in your application

ExeOutput for PHP lets you create cron jobs using the TTimer component. This advanced feature lets you run HEScript functions or PHP code in the background regularly.

Create a timer / cron job

To create a timer, add a Timer (cron) to the "Components Used" list and then click Edit Timer.

The UI editor is shown and displays a ready-to-use timer that you can configure.

Configure a timer

In the UI editor, select the Timer component (step 1):

img

Configure the properties of the Timer component (step 2):

  • Enabled: when false, the timer is not running. This is the recommended way: you should only enable timers programmatically (see below how).
  • Interval: specify the interval in milliseconds (for instance, 1000 means one second). It determines how frequently the defined action occurs. Each time the specified interval passes, the action is triggered.

Define the action to be executed by the Timer component (step 3). The sole actions useful for timers are Execute PHP code and Execute an HEScript function. Learn more about control actions.

For instance, to configure the timer to execute a PHP script, make sure that this script is available in the application's root folder. Then use the PHP include command:

<?php include('cron.php') ?>
as shown in the screenshot above (step 3).

Start and stop timers programmatically

To start a timer component, use the StartTimer function defined in HEScript.

For instance, to start the timer named Timer1, pass its reference (Component Name + Control Name): in our case, it is timer1Timer1

img

In our example, we want to start this timer when the application starts. In the UserMain script, insert this code:

procedure OnStartMainWindow;
begin
 // When the main window is going to be displayed (just before the homepage is shown).
 StartTimer("timer1Timer1", 15000); // Start the timer named Timer1 in the timer1 component and set its interval to 15000.
end;   

Warning

Once a timer is started, it won't stop until the application is closed or you stop it with StopTimer.

To stop a timer component, use the StopTimer function defined in HEScript.

procedure StopIt;
begin
 StopTimer("timer1Timer1");
end;