In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use the Crontab command to execute the PHP file regularly in the Ubuntu system. The article is very detailed and has a certain reference value. Interested friends must read it!
First of all, let's unveil our protagonist today, the Crontab command. This is the system timing command, the function is to regularly perform some tasks. Contains some system-level tasks, of course, users can also directly borrow this command to implement some of their own scheduled tasks.
This command usually starts with the system. We can use the following command to see if cron is started.
Pgrep cron
If started, a process id will be returned
The Crontab file is usually stored in the / etc directory. We use crontab-e to edit the cron task. (the first time you use this command, you will choose a text editor.)
Open the cron file and observe the last line m h dom... Here is a brief introduction to its meaning.
M: minutes, 0-59
H: hours, 0-23
Dom: date, 1-31
Mon: month, 1-12
Dow: week, 0-6 July 0 is Sunday
Command: command
Here, we should already know its approximate usage. As long as we fill in the numerical date we need in the corresponding position, we can use it to indicate the minutes (m) of executing a command (command) on a certain day (dom) or day of the week (dow) in a certain month (dom) or day of the week (dow).
Take a chestnut:
* php / path/to/your/cron.php5 asterisks represent minutes, hours, days, months and weeks, respectively. * 19 * if the second parameter h is 19 for php / var/www/cron/crontab.php, it means that crontab.php is executed at 7: 00 p.m. Every day. * php / path/to/your/cron.php performs tasks every minute 0 * php / path/to/your/cron.php performs tasks at 0 o'clock every hour, for example, 6 php 00 10 php 00 6 10 * 2 * * php / path/to/your/cron.php on the 2nd of each month Perform tasks at 6 minutes and 10 minutes per hour * / 3 php / path/to/your/cron.php perform tasks every 3 or 5 minutes, for example, 10 03 10 charge 05 10 charge 06
In this example, we see not only numbers but also asterisks and / and other symbols. These symbols can make timing more flexible.
* (asterisk): indicates any value. Enter * in the corresponding location, which can be executed arbitrarily. For example, if h is *, it is any hour.
, (comma): indicates that multiple values are filled in in a section, for example, 1 minute or 5 minutes in m position.
/ (slash): indicates how often. For example, filling in * / 2 in section h means every 2 hours, and * / 3 means every 3 hours.
There is no difference between * / 1 and *, so it can be omitted. Think about it here. * / 2 means the time it takes to be divisible by 2 is easy to understand.
Use your editor and save-> after exiting. Restart the cron task. The effect can be seen at the corresponding time of day.
Let's start with two common ones that I often use in PHP development.
The first one: directly call the PHP file
This is relatively simple. Let's create a new php file. Insert some simple date content into a file.
#! / usr/bin/php-Q
Note: this direct call to the PHP file requires #! / usr/bin/php-Q code at the top of the PHP file, while the second way (which we'll talk about next) is to access the link directly and parse the PHP through Apache, which is not required for this PHP script.
16 * / path/to/your/cron.php at 06:01 every morning, execute the cron.php file
Second: timing by visiting URL links.
Access to URL links needs to be done with the help of a browser. We chose Lynx browser, Lynx browser is a portable web browser, used in most Unix and Linux system environments. Installation commands:
Sudo apt-get install lynx
Then you can access the URL on a schedule similar to directly accessing the PHP file.
* lynx-dump http://weiya.me/index.php
Note that it is best to use an absolute address that contains the full url of "http://"."
The above is all the contents of the article "how to use Crontab commands to execute PHP files regularly in Ubuntu system". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.