how to programmatically set a cron job in php

//The stackoverflow link with detailed explanation
https://stackoverflow.com/questions/23544851/how-to-set-up-a-cron-job-programmatically

// Create a cron job
require_once 'xmlapi.php';

/*
 *  Instanciate the class, setting up username/password/IP
 *  @ip - cPanel server IP, if this script is on the cPanel server replace $ip by $ip = getenv('REMOTE_HOST');
 *  @account - string - your cPanel username
 *  @pass - string - your cPanel password
 */

$ip = '127.0.0.1';
$account = 'username';
$pass = "password";
$xmlapi = new xmlapi($ip, $account, $pass);

/*
 * Just to be sure that XML-API will use the correct port and protocol
 * @set_port(port); change port to 2082 if it isn't redirected to HTTPS and/or using HTTP protocol, else.. use 2083
 * @set_protocol(protocol); change protocol to http if your sever accept HTTP else put the protocol to https
 * @set_output(format); change to XML if you want the result output w/ XML, JSON if you want the result output w/ JSON
 */
$xmlapi->set_port('2083');
$xmlapi->set_protocol('https');
$xmlapi->set_output("json");
$xmlapi->set_debug(1);

/*
 *  @command string - The command, script, or program you wish for your cronjob to execute.
 *  @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.
 *  @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.
 *  @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.
 *  @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.
 *  @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.
 */

$command = "/usr/bin/php cron.php";
$day = "1";
$hour = "1";
$minute = "1";
$month = "1";
$weekday = "1";

/*
 * @api2_query(account, module, function, params)
 */
print $xmlapi->api2_query($account, "Cron", "add_line", array(
    "command"=>$command,
    "day"=>$day,
    "hour"=>$hour,
    "minute"=>$minute,
    "month"=>$month,
    "weekday"=>$weekday
));

//Response 
{"cpanelresult":{"module":"Cron","event":{"result":1},"apiversion":2,"data":[{"statusmsg":"crontab installed","status":1,"linekey":"9b0c93fe238a185e4aa78752a49a0718"}],"func":"add_line"}}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
cron job in php query how to run php script using cron job creating php cron job how to create a cronjob in php run a php script cron job php call cron job php execute cron job php script cron job cron job command php Cron job PHP script create cron job in php example create cron job in php localhost php settings for cron job how to implement cron job in php creating cron job php run a cron job php how to use cron in php set cron job using php How to call a cron job function in php cron job in php windows php setup cron job cron job in php sample code how to set time using cron job in php php create cron tutorial cron job class in php set the value of cron job from php script cron job tutorial php windows cron job php how to write a cron job in windows with php how to set a cron job php initiate cron job php set up cron using crontab in php implement cron job in php to execute php script how to set cron job in php what is the work of cron job in php how to create cron job php setup cron job with php set a cron job with php run cron job from php script php manually run a cron job how to hit cron job from php cron jobs php set cron job with php script set cron job for php script linux write cron job in php what is cron job in php php cron job framework Cron jobs for php how to run a cron job in php cron jobs in php cron job php example cron job php file run cron job automatically php cron job example in php php cron jobs what the alternative to cron job in php php with crontab use php in crontab setup cron job php php cron job add how to create cron job in php with example create cron job script in php what are the alternative to cron jobs in php use cron job in php add cron job functions.php how to make cron job for php page CREATE CRON JOB IN PHPH cron job in php edureks cron job php examples cron job function in php are cron jobs just for php? php start cron job using cron job php add php job to cron tab add php cron job add php job to cron run cron job in php simple php cron job cron job php script example how to add php scripts to crontab linux create cron job to call php script set php cron in crontab how to create cron job in php How to run cron job in PHP how to use cron job in php php script to run cron job cron job in php function cron job in php command in cron job php php how to include in cron job what is a cron job php cron job examples php version how to write cron job in PHP cron job in php example php cron job example php program cron php create cron job cron job php setup cron job php script cron job with php php cron job code php cron job how to run cron job using php how to programmatically set a cron job in php
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source