How to Setting Cronjob PHP on Cpanel Hosting

How to Setting Cronjob PHP on Cpanel Hosting
For those of you who are new to hosting it will be introduced with one of the most popular hosting manager software in the world that is cpanel, on cpanel there is a setting to run script commands automatically, commonly called cronjob or scheduled task, its use on the web itself I know so far these are, automatic payment verification, managing realtime database, and others.

Cronjob can be said to be an application provided by cpanel to schedule tasks that will be executed automatically (usually in the form of php script), the task will be executed at certain intervals that we can set itself as a user, because the cpanel we use mostly use linux server so the command code to run it also uses linux commands, while for windows server scheduling may be different.

In cpanel set cronjob is very easy because it provides a time setting commonly used by many people ranging from 1 minute to monthly.

In this article I will run php file to run every certain interval, to secure cronjob php file so it can not be accessed by others except server, the file can be placed outside the public_html folder that we have. The reason is because public html is a folder that can be accessed website url so can access from outside by others.

How to Setting Cronjob PHP on Cpanel Hosting

The next stage you should have opened your cpanel homepage, then scroll down and search for settings called cron job or scheduled task.

How to Setting Cronjob PHP on Cpanel Hosting

After that you can set the time to the general settings that have been provided by cpanel, for manual way I also do not understand, if you are interested to learn manual settings can see the picture below and in accompanied by identify the pattern of general setting results in cpanel.

How to Setting Cronjob PHP on Cpanel Hosting

The smallest interval allowed by cpanel is 1 minute and the longest for months, but actually you can make script execution run at intervals under one minute by manipulating php script but after I ask in forum, program execution less than 1 minute is not recommended. (more precisely under 30 seconds).

This is because it is feared the time of php script execution could have lasted long enough, because of a problem, so feared execution of the script even accumulate and can lead to undesired execution errors.

Here is a set time screenshot that I have set.

How to Setting Cronjob PHP on Cpanel Hosting

After setting the time, now we have to fill in the special command run the php script

php -q /home/xxxx3736/cronjob/expired.php

red color is the folder that leads to the php file to be executed, must be different in every one so check in your hosting, for folder / home / xxxx3736 / can you check at home cpanel, more details can be seen in picture below.


How to Setting Cronjob PHP on Cpanel Hosting

By default the above command script will send an email in the form of output from the executable code selected (expired.php), I think it aims to ensure the php code that we run normally and no errors or cool language is the process of debugging. So if the program code running smoothly when cronjob execution you can turn off this feature.

For cronjob folder is a folder that you can name yourself (not necessarily "cronjob"), see first picture for more clear.

To turn off this send email feature you must add a script

>/dev/null 2>&1 

if combined with the previous script then it will be.

php -q /home/xxxx3736/cronjob/expired.php >/dev/null 2>&1

You can also find these instructions on the top page of the cron job settings.

How to Setting Cronjob PHP on Cpanel Hosting

Setting the time and script the command is complete, then click Add New Cron job to create and save the settings, this setting will be seen at the bottom of the cronjob settings page, you can delete or change the command or time created before. For more details can be seen in the picture below.

How to Setting Cronjob PHP on Cpanel Hosting

That's how I set the php script to be executed in cronjob, currently I only use cronjob for php files only, if you already know cronjob deeper and already use it to execute other types of files, can comment below. Do not forget if this article useful and you want to share can click on the social media link below. See you again

No comments:

Post a Comment