How to use Cron Jobs to execute PHP regularly under Cpanel

How to use Cron Jobs to execute PHP regularly under Cpanel

Open the cpanel management backend, under the "Advanced" option there is a "Clock Guardian Job", as shown below, click to enter.

The settings page has three options: Cron Email (notification email address, this email address will be notified every time the scheduled execution succeeds or fails), Add New Cron Job (add a new scheduled task), and Current Cron Jobs (currently existing scheduled tasks).

The main thing is to set the Add New Cron Job option, as shown below:

The command shown in the figure is executed every 5 minutes:

command: "php /home/piaoyi.org/public_html/cron.php" means:

Executing the command in the form of a PHP script is equivalent to accessing it through a browser.
piaoyi.org is your current username. Find it in cpanel and make sure to change it.

cron.php is a file that is executed at a scheduled time.

Note: If your command is not written correctly, you will receive an error message like "/bin/sh: /home/www.piaoyi.org/public_html/cron.php: Permission denied" or "No such file or directory" in your mailbox; if it is successfully executed, you will receive a code like "X-Powered-By: PHP/5.2.13 Content-type: text/html" in your mailbox.

Regarding the time setting of crontab, the following are explained:

The basic format of crontab is:
* * * * * command
The first column of the time-sharing, day-month-week command indicates minutes from 1 to 59. Each minute is represented by * or */1. The second column indicates hours from 1 to 23 (0 indicates 0 o'clock).
The third column represents the date 1 to 31
The fourth column represents the months 1 to 12
Column 5 identifies the day of the week from 0 to 6 (0 for Sunday)
Column 6 The command to be run
Some examples of crontab files:
30 21 * * * /usr/local/etc/rc.d/lighttpd restart
The above example restarts lighttpd at 21:30 every night.
45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart
The above example restarts lighttpd at 4:45 on the 1st, 10th, and 22nd of every month.
10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart
The above example restarts lighttpd at 1:10 every Saturday and Sunday.
0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart
The above example restarts lighttpd every 30 minutes between 18:00 and 23:00 every day.
0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart
The above example restarts lighttpd at 11:00 pm every Saturday.
* */1 * * * /usr/local/etc/rc.d/lighttpd restart
Restart lighttpd every hour
* 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart
Restart lighttpd every hour between 11pm and 7am
0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart
Restart lighttpd on the 4th of each month and every Monday to Wednesday at 11:00
0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart
Restart lighttpd at 4:00 on January 1st

This is the end of this article about how to use Cron Jobs to execute PHP on a scheduled basis under Cpanel. For more information about how to use Cron Jobs to execute PHP on a scheduled basis, please search previous articles on 123WORDPRESS.COM or continue browsing the following related articles. I hope you will continue to support 123WORDPRESS.COM in the future!

<<:  DIV common attributes collection

>>:  Analysis of the situation where js determines and informs the support of CSS attributes (values)

Recommend

How to solve the Docker container startup failure

Question: After the computer restarts, the mysql ...

MySql5.7.21 installation points record notes

The downloaded version is the Zip decompression v...

React implements the expansion and collapse function of complex search forms

Give time time and let the past go. In the previo...

Example statements for indexes and constraints in MySQL

Foreign Keys Query which tables the primary key o...

Several CSS3 tag shorthands (recommended)

border-radius: CSS3 rounded corners Syntax: borde...

Implementation of vue3.0+vant3.0 rapid project construction

Table of contents 1. Project Construction 2. Vue3...

A simple method to implement scheduled backup of MySQL database in Linux

Here are the detailed steps: 1. Check the disk sp...

Zabbix's psk encryption combined with zabbix_get value

Since Zabbix version 3.0, it has supported encryp...

Implementation example of Vue+Element+Springboot image upload

Recently, I happened to be in touch with the vue+...

How to check the version of Kali Linux system

1. Check the kali linux system version Command: c...

How to make an input text box change length according to its content

First: Copy code The code is as follows: <input...

Example code for using Nginx to implement 301 redirect to https root domain name

Based on SEO and security considerations, a 301 r...

CSS code to distinguish ie8/ie9/ie10/ie11 chrome firefox

Website compatibility debugging is really annoyin...

Solution for importing more data from MySQL into Hive

Original derivative command: bin/sqoop import -co...