Apex Software Platform

Apex Training - Crontab Job

Let's create our crontab job that will execute once every 24 hours, and randomly pick a winner using our pick_inner() method we created in the previous library. Within tyerminal, type:

./apex create cron training:pick_winner

This will create a new file at /src/training/cron/pick_winner.php. Open the file, and enter the following contents.

declare(strict_types = 1);

namespace apex\training\cron;

use apex\app;
use apex\libc\db;
use apex\libc\debug;
use apex\training\lottery;

 * Class the handles the lottery package, and pickcing a 
 * winner every 24 hours.
class pick_winner

    // Properties
    public $time_interval = 'D1';
    public $name = 'Lottery - Pick Winner';

 * Picker lottery winner.
public function process()

    // Get a random user
    $client = app::make(lottery::class);
    $userid = $client->pick_winner();

    // Return
    return $userid;



As you will notice within the properties of the above class, we set $time_interval = 'D1';, which represents one day and is the interval at which the crontab job will execute. That's it, the above method will not execute every 24 hours.


Let's move on to Creating a Notification Controller to handle the e-mail messages that will be sent out.

Need a Developer?

Taking work, any size or scope, and your imagination is the only limit. Contact me for a free consultation at [email protected].

Recent News

Apex v1.5 Released!
Auto-Install via YAML, Preloading, CRUD Scaffolding, Code ReOrganization, Import / Export between Packages, and more...
Apex v1.4.0 Released!
New Package Format, Service Providers and Adapters, New Theme Tools, and more
Apex v1.3.0 Released!
PHP 7.4, Docker, git Integration, 96.4% Test Coverage, and more!

Mailing List

Subscribe to the low traffic mailing list to stay updated on Apex.

Admin Screenshot