Hello Guys, welcome back to this tutorial on how to make a cron job on the server.

Let's Understand first what is a cron job. Basically, a cron job is an automatic task performed by our servers. In this, we do not need to run a page onto the browser.

Let's take an:

Example 1: Suppose we want to make an automated system for email sending at a particular time, so for this task, we need a cron job to perform this job done.

Example 2: Suppose we want to send SMS to customer mobile numbers daily at 7:00 PM, so for this, we need cron job. No need to send it by running a script through your browser.


So, next is how to perform a cron job with the help of our server. In this tutorial, we recommend that you have your own WHM CPanel, in this panel we easily create a cron job to run a particular page. This page contains a script that you want to perform.

Let's take a sample for this example

Step 1: Create a PHP file that contains a PHP script that will insert some data into the database without running this page on the browser. Actually, we run this page via a cron job.


First Make config.php


define('DB_HOST', 'localhost');
    define('DB_USER', 'root');
    define('DB_PASSWORD', '');
    define('DB_DATABASE1', 'tutorialswave');

function connection()
//Connect to mysql server
	$link = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
	if(!$link) {
		die('Failed to connect to server: ' . mysql_error());

//Select database
	$db = mysql_select_db(DB_DATABASE1);
	if(!$db) {
		die('Unable to select database  45454');



Now Create Database File


  `stu_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `studentname` varchar(100) DEFAULT NULL,
  `stuclass` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`stu_id`)


Now Create student.php


include 'config.php';

$sql="INSERT INTO student (studentname,stuclass) VALUES ('Amit Kumar','2nd')";



Now its time create cron job to perform an automated task

Login to your CPanel :

cron job cpanel

Now Enter the Command as your requirement


After doing all that, the cron job automatically run the student.php file every day at 7:00 PM


Have Fun!