Home>Article>PHP Framework> Second-level scheduled task tool based on the workerman library

Second-level scheduled task tool based on the workerman library

藏色散人
藏色散人 forward
2020-01-15 17:40:26 3400browse

The following columnworkerman Tutorialwill introduce to you the method of implementing the second-level scheduled task tool based on the workerman library. I hope it will be helpful to friends in need!

Second-level scheduled task tool based on the workerman library

#For PHP developers, I must have had enough of configuring various scheduled tasks on the Linux system, and I am also very annoyed. So, I recently wrote a second-level scheduled task tool. Here is a brief introduction.

GitHub source code address (https://github.com/2lovecode/cron-job)

Second-level scheduled task tool, based onworkermanlibrary

In the past, we mainly relied on configuring crontab on the server side to implement scheduled tasks, but this approach has several disadvantages

1) Crontab only supports minute level. If you want to implement second-level tasks, You must write a shell script to achieve this.

2) If you need to change or add new scheduled tasks after the code is deployed online, you must log in to the server to make manual changes, which is time-consuming, labor-intensive and error-prone.

cron-job solves the main problem

1) By using a second-level timer (the specific implementation of the timer has performance differences due to different installed extensions, but it does not affect our functions ), realizing second-level scheduled tasks.

2) The configuration of scheduled tasks can be changed in the configuration file. After the code deployment is online, just reload the scheduled task service, and reload provides a smooth restart and does not affect the tasks being executed.

3) Support the deployment of scheduled task distributors and scheduled task executors to different servers.

Usage example

1. Install using composer

Add under require in the composer.json file:

“require” : { “2lovecode/cron-job”: “dev-master” }

Execute Just composer install or composer update

2.test.php

Related recommendations: "workerman Tutorial"

The above is the detailed content of Second-level scheduled task tool based on the workerman library. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete