Update `codebox` macro
[GitHub/WoltLab/woltlab.github.io.git] / docs / php / api / cronjobs.md
1 # Cronjobs
2
3 Cronjobs offer an easy way to execute actions periodically, like cleaning up the database.
4
5 !!! warning "The execution of cronjobs is not guaranteed but requires someone to access the page with JavaScript enabled."
6
7 This page focuses on the technical aspects of cronjobs, [the cronjob package installation plugin page](../../package/pip/cronjob.md) covers how you can actually register a cronjob.
8
9
10 ## Example
11
12 {jinja{ codebox(
13 title="files/lib/system/cronjob/LastActivityCronjob.class.php",
14 language="php",
15 filepath="php/api/cronjobs/LastActivityCronjob.class.php"
16 ) }}
17
18
19 ## `ICronjob` Interface
20
21 Every cronjob needs to implement the `wcf\system\cronjob\ICronjob` interface which requires the `execute(Cronjob $cronjob)` method to be implemented.
22 This method is called by [wcf\system\cronjob\CronjobScheduler](https://github.com/WoltLab/WCF/blob/master/wcfsetup/install/files/lib/system/cronjob/CronjobScheduler.class.php) when executing the cronjobs.
23
24 In practice, however, you should extend the `AbstractCronjob` class and also call the `AbstractCronjob::execute()` method as it fires an event which makes cronjobs extendable by plugins (see [event documentation](events.md)).
25
26
27 ## Executing Cronjobs Through CLI
28
29 Cronjobs can be executed through the command-line interface (CLI):
30
31 ```
32 php /path/to/wcf/cli.php << 'EOT'
33 USERNAME
34 PASSWORD
35 cronjob execute
36 EOT
37 ```