how to programmatically set a cron job in php

Solutions on MaxInterview for how to programmatically set a cron job in php by the best coders in the world

showing results for - "how to programmatically set a cron job in php"
Lautaro
24 Oct 2017
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
queries leading to this page
schedule cron jobs by phpimplement cron job in php to execute php scriptset cron job using phpset up cron using crontab in phpphp cron job frameworkadd php job to croncron task phphow to implement cron job in phpcron job php examplecreating cron job phpcron job run php scripthow to make cron job for php pagewrite cron job in phphow to write cron job in phpphp how to include in cron jobcron job php windowsphp cron jobscron job in php mysqlphp create cron tutorialhow to add php scripts to crontabhow to use cronjob phphow to programmatically set a cron job in phpphp run cron jobadd cron job functions phpset php cron in crontabsetup cron job with phpcron task through phpphp cron job addadd php job to cron tabdo cron in phphow to stop cron jobs phphow to set time using cron job in phphow to run php script using cron jobrun cron job in phphow to create a cronjob in phpcron job in php windows php with crontabphp list cron jobshow to create cron jon in phphow to set a cron job php cron job phphow to turn off cron tasks phpwhat are the alternative to cron jobs in phpcreate cron job phphow to create cron job in php with examplephp command to run cron jobwhat is the work of cron job in phpadd cronjob from phpphp execute cron jobphp manually run a cron jobphp cron job classcomo hacer un cron job en phpcron job scedual task in phpsetup cron job from phplinux create cron job to call php scriptcrontab php script examplecommand in cron job phpphp create cron joblibrary to manage cron jobs task phpcron job function in phprun a php script form a cron jobphp script cron jobset cron job with php scriptcron job tutorial phpphp f cron jobcron job php linkcreating php cron jobcron jobs in phpwindows cron job phpenable cron job in phpphp cronjob windowsrun php script from cron jobset cron job using php codeusing cron job phphow to run cron job in phprun a php file in cron jobcreate cron job with php on windowsphp run cronjobcreate a cron job phphow to create cron job in phpphp cron job in backgroundhow to set cron job in phpcron job in php edurekscron job php connect databaseadd php cron jobphp start cron jobcron job in phpwhat can you not do with cron jobs in phpphp run crontabwhat is a cron job phprun a php script cron jobhow to call a cron job function in phpcron jobs phprun a php script from a cron jobcron job in php sample codecron job in php examplesetup cron job phpphp call cron jobcron job with php script widowscron job example in phphow to use cron in phpcron job class in phpcron job setting in phphow to run cron job using phpphp mysql scripts for cron jobsrun php script using cron jobcron job with phpcretae cron job with php script on windowsschedule cron jobs in php php ini cron jobcron job command phpcron job to arun a php scriptcron php scriptcron job php script examplephp script to run cron jobfunction cron job in phpphplist cron jobcronjob example phpphp setup cron jobphp command for the cron jobrun a cron job phpscript cron phpset a cron job with phpcreate cronjob phpwhat is cron job in phpcron job php fileset cronjob in phpinitiate cron job phpcreate cron job in phphphp cron job codehow to hit cron job from phpare cron jobs just for php 3fcron job php exampleshow to run php file using cron jobi want to add cron job run on each day in phphow to run a cron job in phpphp cron examplephp settings for cron jobhow to create cron job phpwhat the alternative to cron job in phpcreate cron job in php localhostset the value of cron job from php scriptcreate cron job in ubuntu using phpphp cron job examplehow to set up a cron job to link to a php functioncron jobs for phprun cron job automatically phphow to write a cron job in windows with phpset cron job for php script linuxcreate a php script 2c which will be called from a cron jobuse cron job in phpphp cron jobcreate cron job in php examplerun cron job from php scriptcron job run php filephp program cronsimple php cron jobphp without cron jobcron job examples php versionsetup cron job php scriptcreate cron job script in phphow to use cron job in phpphp cronjuse php in crontabphp cronjobcron task in phpset up a cron job phpset cron job in phpcron job in php query php cron job with inputshow to make cron job in phpcron job php with javascriptcron job php scripthow to programmatically set a cron job in php