1//The stackoverflow link with detailed explanation
2https://stackoverflow.com/questions/23544851/how-to-set-up-a-cron-job-programmatically
3
4// Create a cron job
5require_once 'xmlapi.php';
6
7/*
8 * Instanciate the class, setting up username/password/IP
9 * @ip - cPanel server IP, if this script is on the cPanel server replace $ip by $ip = getenv('REMOTE_HOST');
10 * @account - string - your cPanel username
11 * @pass - string - your cPanel password
12 */
13
14$ip = '127.0.0.1';
15$account = 'username';
16$pass = "password";
17$xmlapi = new xmlapi($ip, $account, $pass);
18
19/*
20 * Just to be sure that XML-API will use the correct port and protocol
21 * @set_port(port); change port to 2082 if it isn't redirected to HTTPS and/or using HTTP protocol, else.. use 2083
22 * @set_protocol(protocol); change protocol to http if your sever accept HTTP else put the protocol to https
23 * @set_output(format); change to XML if you want the result output w/ XML, JSON if you want the result output w/ JSON
24 */
25$xmlapi->set_port('2083');
26$xmlapi->set_protocol('https');
27$xmlapi->set_output("json");
28$xmlapi->set_debug(1);
29
30/*
31 * @command string - The command, script, or program you wish for your cronjob to execute.
32 * @day int - The day on which you would like this crontab entry to run. Wildcards and any acceptable input to a crontab time expression line are allowed here.
33 * @hour int - The hour at which you would like this crontab entry to run. Wildcards and any acceptable input to a crontab time expression line are allowed here.
34 * @minute int - The minute at which you would like this crontab entry to run. Wildcards and any acceptable input to a crontab time expression line are allowed here.
35 * @month int - The month you would like this crontab entry to run. Wildcards and any acceptable input to a crontab time expression line are allowed here.
36 * @weekday int - The weekday on which you would like this crontab entry to run. Wildcards and any acceptable input to a crontab time expression line is allowed here. Acceptable values range from 0 to 6, where 0 represents Sunday and 6 represents Saturday.
37 */
38
39$command = "/usr/bin/php cron.php";
40$day = "1";
41$hour = "1";
42$minute = "1";
43$month = "1";
44$weekday = "1";
45
46/*
47 * @api2_query(account, module, function, params)
48 */
49print $xmlapi->api2_query($account, "Cron", "add_line", array(
50 "command"=>$command,
51 "day"=>$day,
52 "hour"=>$hour,
53 "minute"=>$minute,
54 "month"=>$month,
55 "weekday"=>$weekday
56));
57
58//Response
59{"cpanelresult":{"module":"Cron","event":{"result":1},"apiversion":2,"data":[{"statusmsg":"crontab installed","status":1,"linekey":"9b0c93fe238a185e4aa78752a49a0718"}],"func":"add_line"}}
60