How to execute PHP scheduled tasks in CentOS7

How to execute PHP scheduled tasks in CentOS7

Preface

This article mainly introduces the relevant content about CentOS7 executing PHP scheduled tasks, and shares it for your reference and learning. Let's take a look at the detailed introduction.

1. Install crontab in CentOS 7:

yum install crontabs

grammar:

crontab [-u <username>][configuration file] or crontab [-u <username>][-elr]

parameter:

  • -e Edit the timer settings for this user.
  • -l Lists the timer settings for this user.
  • -r Delete the timer settings for this user.
  • -u<username> Specifies the user name for which the timer is to be set.

For more information about how to use the Crontab command, please refer to this article: https://www.jb51.net/article/148575.htm

1. Enter in the command line:

crontab -e

Then add the corresponding tasks, save and exit with wq;

2. Find the PHP execution directory:

which php

3. Execution script format

* * * * * /usr/local/php/bin/php /var/www/aaa.php

4. Service Status

systemctl start crond.service
systemctl stop crond.service
systemctl restart crond.service
systemctl reload crond.service
systemctl enable crond.service ##Set cron to start at boot crontab -l ##View the current cron
crontab -e ##Edit the current cron
crontab -r ##Delete the current cron

2. Practical Examples

Parameter Description

  • Minute: The minute of each hour at which the task is executed. The value range is 0-59.
  • Hour: the hour of the day when the task is executed, the value range is 0-23;
  • Day: the day of the month on which the task is executed, ranging from 1 to 31;
  • Month: the month of the year in which the task is executed, with a value range of 1-12;
  • DayOfWeek: the day of the week on which the task is executed. The value range is 0-6, where 0 means the weekend.
  • CommandPath: specifies the program path to be executed;
30 21 * * * /etc/init.d/nginx restart ##Restart nginx at 21:30 every night.
45 4 1,10,22 * * /etc/init.d/nginx restart ##Restart nginx at 4:45 on the 1st, 10th, and 22nd of each month.
10 1 * * 6,0 /etc/init.d/nginx restart ##Restart nginx at 1:10 every Saturday and Sunday.
0,30 18-23 * * * /etc/init.d/nginx restart ##Restart nginx every 30 minutes between 18:00 and 23:00 every day.
0 23 * * 6 /etc/init.d/nginx restart ##Restart nginx at 11:00 pm every Saturday.
* */1 * * * /etc/init.d/nginx restart ##Restart nginx every hour
* 23-7/1 * * * /etc/init.d/nginx restart ##Restart nginx every hour between 11pm and 7am
0 11 4 * mon-wed /etc/init.d/nginx restart ##Restart nginx on the 4th of each month and at 11:00 every Monday to Wednesday
0 4 1 jan * /etc/init.d/nginx restart ##Restart nginx at 4:00 on January 1st
*/30 * * * * /usr/sbin/ntpdate 210.72.145.20 ##Synchronize time every half hour

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM.

You may also be interested in:
  • Solution to the "syntax error: unexpected end of file" message when running .sh script in CentOS7
  • Use crontab to run the script of executing jar program regularly in centOS6
  • CentOS 6.5 configuration ssh key-free login to execute pssh command explanation
  • Detailed explanation of using crontab to execute tasks regularly under CentOS 7
  • Solve the problem that /etc/rc.local does not execute when starting centos7
  • How to set up a scheduled task to execute a specified script in centos
  • CentOS uses expect to remotely execute scripts and commands in batches

<<:  Detailed explanation of the implementation of manual and automatic tracking of WeChat applet (Taro)

>>:  Learn the black technology of union all usage in MySQL 5.7 in 5 minutes

Recommend

CSS to achieve text on the background image

Effect: <div class="imgs"> <!-...

Real-time refresh of long connection on Vue+WebSocket page

Recently, the Vue project needs to refresh the da...

How to convert extra text into ellipsis in HTML

If you want to display extra text as ellipsis in ...

MySQL 5.7.12 installation and configuration tutorial under Mac OS 10.11

How to install and configure MySQL on Mac OS 10.1...

Realize the CSS loading effect after clicking the button

Since there is a button in my company's produ...

IE conditional comments for XHTML

<br />Conditional comments are a feature uni...

Comparison of the use of form element attributes readonly and disabled

1) Scope of application: readonly:input[type="...

Vue realizes dynamic progress bar effect

This article example shares the specific code of ...

Detailed steps to install and uninstall Apache (httpd) service on centos 7

uninstall First, confirm whether it has been inst...

Detailed explanation of Vue's simple store

The simplest application of store in Vue is globa...

JavaScript Regular Expressions Explained

Table of contents 1. Regular expression creation ...

Ubuntu compiles kernel modules, and the content is reflected in the system log

Table of contents 1.Linux login interface 2. Writ...

mysql three tables connected to create a view

Three tables are connected. Field a of table A co...

Using Vue3 (Part 1) Creating a Vue CLI Project

Table of contents 1. Official Documentation 2. Cr...