How can We Create Cron Jobs and Add them in Cpanl.

Creating cron jobs and implementing them on server is little bit tricky for web beginners. Here i will elaborate a simple example for creating and implementing crons on PHP server.

Here is a simple code which deletes all records whose type is “Graphics”.
Cron job is an independent file which is executed by server on our given time. We need db info so that we can connect to db and performs our operations on data.

In above code we are creating db login information variables. Now we will try to connect to db in next step.

After successful db connection we will perform our required operations. In this example we will delete some records.

Now our sampled cron has been ready and next step is to put this file on server. Log in to your hosting panel using your login info and go to cpanel which is main page as shown below. Click on cron job icon.

On next page you will see a window which has some options about your cron running time and path to cron file. In this case i put my file on root so i will give my path like this :

Here onw thing in above syntax, php -f is a syntax which is required and executes an action. While home/my-folder-name/ is my root path. Now next i will give my file name if it is on root. Other wise give your own path according to your folders.
Next yo u have to set up cron job running times and date.
After mints, hours or daily, weekly.
Give a single mint interval to check that cron is working fine. Confirmation will be get by receiving an email if you have given your correct email on that hosting.

Comments are closed.