Home Backend Development PHP Tutorial yii2 configure crontab scheduled tasks

yii2 configure crontab scheduled tasks

Aug 19, 2017 am 09:35 AM
crontab yii2 Task

1. Detection environment:

First we switch to the project root directory. If yii2 is installed normally, there will be a commands folder with a sample file HelloController.php in it.

<?php
namespace app\commands;use yii\console\Controller;class HelloController extends Controller
{    public function actionIndex($message = 'hello world')
    {        echo $message . "\n";
    }
}
Copy after login

Cut to the project root directory, command line output php yii hello, output hello world indicating that the environment is normal


2. Write the code:

You can Create a new controller file in the commands folder, inherit yii\console\Controller; define class methods, the actionIndex method is generally the default route,

When debugging, enter php yii in the project root directory Add the controller name (lowercase)/route (can be omitted if index)

Third, Linux scheduled task crontab.

1About crontab:

## In the linux environment, crontab -l displays scheduled tasks, crontab -e edits scheduled tasks

2 Basic syntax

Basic format: * * * command Time-sharing, day, month and week commands

The first column represents minutes 1 to 59. Each minute is represented by * or */1

The second column represents hours 1 to 23 (0 represents 0 o'clock)

The 3rd column represents the date 1~31
The 4th column represents the month 1~12
The 5th column identifies the weekday 0~6 (0 means Sunday)
The 6th column represents the command to be run

3 Usage examples

30 21 * * * /usr/local/etc/rc.d/lighttpd restart#   #The above example indicates that apache is restarted at 21:30 every night.

 45

4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart  #The above example indicates that apache is restarted 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 represents 1 of every Saturday and Sunday : 10Restart apache.

  0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart

##   #The above example indicates that between 18:00 and 18:00 every day Restart apache every 30 minutes between 23:00.

 0

23 * * 6 /usr/local/etc/rc.d/lighttpd restart#   #The above example indicates that apache is restarted at 11:00 pm every Saturday.

  0

*/1 * * * /usr/local/etc/rc.d/lighttpd restart ##  #Restart apache every hour

Four, Linux scheduled task crontab executes the controller php file content under commands

Follow the third step and add php yii + project root path + routing ( Controller name/method name)

The above is the detailed content of yii2 configure crontab scheduled tasks. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to complete the horror corridor mission in Goat Simulator 3 How to complete the horror corridor mission in Goat Simulator 3 Feb 25, 2024 pm 03:40 PM

The Terror Corridor is a mission in Goat Simulator 3. How can you complete this mission? Master the detailed clearance methods and corresponding processes, and be able to complete the corresponding challenges of this mission. The following will bring you Goat Simulator. 3 Horror Corridor Guide to learn related information. Goat Simulator 3 Terror Corridor Guide 1. First, players need to go to Silent Hill in the upper left corner of the map. 2. Here you can see a house with RESTSTOP written on the roof. Players need to operate the goat to enter this house. 3. After entering the room, we first go straight forward, and then turn right. There is a door at the end here, and we go in directly from here. 4. After entering, we also need to walk forward first and then turn right. When we reach the door here, the door will be closed. We need to turn back and find it.

How to pass the Imperial Tomb mission in Goat Simulator 3 How to pass the Imperial Tomb mission in Goat Simulator 3 Mar 11, 2024 pm 01:10 PM

Goat Simulator 3 is a game with classic simulation gameplay, allowing players to fully experience the fun of casual action simulation. The game also has many exciting special tasks. Among them, the Goat Simulator 3 Imperial Tomb task requires players to find the bell tower. Some players are not sure how to operate the three clocks at the same time. Here is the guide to the Tomb of the Tomb mission in Goat Simulator 3! The guide to the Tomb of the Tomb mission in Goat Simulator 3 is to ring the bells in order. Detailed step expansion 1. First, players need to open the map and go to Wuqiu Cemetery. 2. Then go up to the bell tower. There will be three bells inside. 3. Then, in order from largest to smallest, follow the familiarity of 222312312. 4. After completing the knocking, you can complete the mission and open the door to get the lightsaber.

Fix: Operator denied request error in Windows Task Scheduler Fix: Operator denied request error in Windows Task Scheduler Aug 01, 2023 pm 08:43 PM

To automate tasks and manage multiple systems, mission planning software is a valuable tool in your arsenal, especially as a system administrator. Windows Task Scheduler does the job perfectly, but lately many people have reported operator rejected request errors. This problem exists in all iterations of the operating system, and even though it has been widely reported and covered, there is no effective solution. Keep reading to find out what might actually work for other people! What is the request in Task Scheduler 0x800710e0 that was denied by the operator or administrator? Task Scheduler allows automating various tasks and applications without user input. You can use it to schedule and organize specific applications, configure automatic notifications, help deliver messages, and more. it

How to do the rescue Steve mission in Goat Simulator 3 How to do the rescue Steve mission in Goat Simulator 3 Feb 25, 2024 pm 03:34 PM

Rescue Steve is a unique task in Goat Simulator 3. What exactly needs to be done to complete it? This task is relatively simple, but we need to be careful not to misunderstand the meaning. Here we will bring you the rescue of Steve in Goat Simulator 3 Task strategies can help you better complete related tasks. Goat Simulator 3 Rescue Steve Mission Strategy 1. First come to the hot spring in the lower right corner of the map. 2. After arriving at the hot spring, you can trigger the task of rescuing Steve. 3. Note that there is a man in the hot spring. Although his name is Steve, he is not the target of this mission. 4. Find a fish named Steve in this hot spring and bring it ashore to complete this task.

Do you know some reasons why crontab scheduled tasks are not executed? Do you know some reasons why crontab scheduled tasks are not executed? Mar 09, 2024 am 09:49 AM

Summary of some reasons why crontab scheduled tasks are not executed. Update time: January 9, 2019 09:34:57 Author: Hope on the field. This article mainly summarizes and introduces to you some reasons why crontab scheduled tasks are not executed. For everyone Solutions are given for each of the possible triggers, which have certain reference and learning value for colleagues who encounter this problem. Students in need can follow the editor to learn together. Preface: I have encountered some problems at work recently. The crontab scheduled task was not executed. Later, when I searched on the Internet, I found that the Internet mainly mentioned these five incentives: 1. The crond service is not started. Crontab is not a function of the Linux kernel, but relies on a cron.

Where can I find Douyin fan group tasks? Will the Douyin fan club lose level? Where can I find Douyin fan group tasks? Will the Douyin fan club lose level? Mar 07, 2024 pm 05:25 PM

TikTok, as one of the most popular social media platforms at the moment, has attracted a large number of users to participate. On Douyin, there are many fan group tasks that users can complete to obtain certain rewards and benefits. So where can I find Douyin fan club tasks? 1. Where can I view Douyin fan club tasks? In order to find Douyin fan group tasks, you need to visit Douyin's personal homepage. On the homepage, you will see an option called "Fan Club." Click this option and you can browse the fan groups you have joined and related tasks. In the fan club task column, you will see various types of tasks, such as likes, comments, sharing, forwarding, etc. Each task has corresponding rewards and requirements. Generally speaking, after completing the task, you will receive a certain amount of gold coins or experience points.

How to use Systemd and Crontab to implement parallel execution of tasks in Linux systems How to use Systemd and Crontab to implement parallel execution of tasks in Linux systems Sep 26, 2023 pm 06:37 PM

How to use Systemd and Crontab to implement parallel execution of tasks in a Linux system. In a Linux system, parallel execution of tasks is one of the important means to improve system efficiency and performance. This article will introduce how to use Systemd and Crontab tools to implement parallel execution of tasks in a Linux system, and provide specific code examples. 1. Introduction to Systemd Systemd is a tool used to manage the startup process and service management of Linux systems. via configuration

How to stop Task Manager process updates and kill tasks more easily in Windows 11 How to stop Task Manager process updates and kill tasks more easily in Windows 11 Aug 20, 2023 am 11:05 AM

How to Pause Task Manager Process Updates in Windows 11 and Windows 10 Press CTRL+Window Key+Delete to open Task Manager. By default, Task Manager will open the Processes window. As you can see here, all the apps are endlessly moving around and it can be hard to point them down when you want to select them. So, press CTRL and hold it, this will pause the task manager. You can still select apps and even scroll down, but you must hold down the CTRL button at all times.

See all articles