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

Docker installation and configuration steps for RabbitMQ

Table of contents Single-machine deployment Onlin...

JavaScript gets the scroll bar position and slides the page to the anchor point

Preface This article records a problem I encounte...

Summary of Linux file directory management commands

touch Command It has two functions: one is to upd...

【HTML element】Detailed explanation of tag text

1. Use basic text elements to mark up content Fir...

CSS float (float, clear) popular explanation and experience sharing

I came into contact with CSS a long time ago, but...

A brief analysis of event bubbling and event capture in js

Table of contents 01-Event Bubbling 1.1- Introduc...

Docker-compose steps to configure the spring environment

Recently, I need to package the project for membe...

Summary of the differences between get and post requests in Vue

The operating environment of this tutorial: Windo...

Using CSS3 to implement font color gradient

When using Animation.css, I found that the font o...

CSS to achieve Cyberpunk 2077 style visual effects in a few steps

background Before starting the article, let’s bri...

The actual process of encapsulating axios in the project

Table of contents Preface Benefits of axios encap...

Zen HTML Elements Friends who use zen coding can collect it

html ¶ <html></html> html:xml ¶ <h...