search
HomeBackend DevelopmentPHP TutorialCrontab scheduled task management based on PHP_PHP tutorial

PHP-based crontab scheduled task management

Linux's crontab has always been a powerful tool for server operation and maintenance and business development. But when the number of scheduled tasks increases, management and migration become cumbersome and prone to problems. The following provides a crontab manager written in PHP, but you still need to add a call under crontab that executes once a minute to run this manager. Through this manager, you can achieve the following purposes:

  • Centralized management of distributed scheduled tasks
  • Merge multiple crontab records
  • crontab records persistent storage (configuration file or database)

    It is not recommended that you use a database for crontab configuration management unless you can ensure that database requests can maintain a stable response for a long time. It is recommended to use nosql type cache storage and make persistent backups.

    Without further ado, here’s the last piece of test code:

    define('DS', DIRECTORY_SEPARATOR);
    requiredirname(__FILE__) . DS . 'vendor'. DS . 'autoload.php';
    date_default_timezone_set('PRC');
     
    error_reporting(E_ALL);
     
    $crontab_config= [
        'test_1'=> [
            'name'=> '服务监控1',
            'cmd'=> 'php -v',
            'output'=> '/tmp/test.log',
            'time'=> '* * * * *'
        ],
        'single_test'=> [
            'name'=> 'php -i',
            'cmd'=> 'php -i',
            'output'=> '/tmp/single_script.log',
            'time'=> [
                '* * * * *',
                '* * * * *',
            ],
        ],
    ];
     
    $crontab_server= new\Jenner\Zebra\Crontab\Crontab($crontab_config);
    $crontab_server->start();

    This code uses PHP's package manager composer. If you don't understand it, you can manually include the classes you need to use into your PHP script.

    After running, we will view the crontab running record in the default log file (/var/log/php_crontab.log). Of course, you can specify the log file log by passing the second parameter to Crontab (make sure it is writable). The content of the log file is as follows:

    [2014-11-10 19:50:08]-content:start. pid3778
    [2014-11-10 19:50:08]-content:php -v
    [2014-11-10 19:50:08]-content:php -i
    [2014-11-10 19:50:08]-content:php -i
    [2014-11-10 19:50:08]-content:end. pid:3778

    The log will record the program's startup time, running commands, pid and other information. Since I did it manually, the description is not exact 00 seconds. When it is officially used, add the following command to the crontab to realize the automatic operation of the manager.

    * * * * * php php_crontab_manager.php

    Manager related dependencies:

    • Process control package: "jenner/multi_process": "1.0.0",
    • pcntl extension
    • crontab service

      The jenner/multi_process package is a simple process control package. It is mainly used to use child processes to execute scheduled tasks, so that the parent process will not block and cause delays in scheduled tasks.

      Project address:

      This project is hosted on github and also provides packagist package support. You can add: "jenner/crontab" to composer.json: "1.0.0" to load this package.

      The specific source code can be viewed on github.

      Original article, please indicate when reprinting: Reprinted from Always Not Enough

      Link address of this article: Crontab scheduled task management based on PHP

      www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/914778.htmlTechArticlePHP-based crontab scheduled task management BY JENNER · November 10, 2014 · Number of reads: 6 Linux crontab It has always been a powerful tool for server operation and maintenance and business development. But when the number of scheduled tasks increases,...
Statement
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
模拟山羊3恐怖走廊任务怎么做模拟山羊3恐怖走廊任务怎么做Feb 25, 2024 pm 03:40 PM

恐怖走廊是模拟山羊3之中的一个任务,这个任务要怎么样才能够去完成呢,掌握到详细的过关方式和对应的流程,能够完成这个任务的相应挑战,下面就为大家带来模拟山羊3恐怖走廊攻略,了解相关的信息。模拟山羊3恐怖走廊攻略1、首先需要玩家前往地图左上角的寂静岭处。2、在这里可以看到一个屋顶上写着RESTSTOP的房子,玩家需要操作山羊进入这个房子。3、进入房间之后,我们首先向前直走,随后向右转,在这里尽头有一扇门,我们直接从这里进去。4、进入之后同样是先向前走随后右转,在这里走到门前门会关上,我们需要回头找到

修复: 操作员拒绝 Windows 任务计划程序中的请求错误修复: 操作员拒绝 Windows 任务计划程序中的请求错误Aug 01, 2023 pm 08:43 PM

要自动化任务和管理多个系统,任务计划软件是您武器库中的宝贵工具,尤其是对于系统管理员而言。Windows任务计划程序完美地完成了这项工作,但最近许多人报告说操作员拒绝了请求错误。该问题存在于操作系统的所有迭代中,即使已经广泛报告和涵盖,也没有有效的解决方案。继续阅读以找到真正对其他人有用的内容!操作员或管理员拒绝了任务计划程序0x800710e0中的请求是什么?任务计划程序允许在没有用户输入的情况下自动执行各种任务和应用程序。您可以使用它来安排和组织特定应用程序、配置自动通知、帮助传递消息等。它

模拟山羊3帝陵任务怎么过模拟山羊3帝陵任务怎么过Mar 11, 2024 pm 01:10 PM

模拟山羊3是有着经典模拟玩法的游戏,可让玩家充分体验到休闲动作类操作模拟的乐趣,游戏中还拥有很多特色任务的精彩,其中模拟山羊3帝陵任务是需要玩家找寻到钟塔上的三个钟并操作的,一些玩家还不清楚要怎么弄,下面带来模拟山羊3帝陵任务攻略流程分享!模拟山羊3帝陵任务攻略流程按照顺序敲击钟即可。详细步骤拓展1、首先玩家需要打开地图去到雾丘公墓。2、然后上到钟楼上,里面会有着三个钟。3、接着按照从大到小的顺序,按照222312312熟悉怒敲击。4、完成敲击后即可完成任务,并打开大门获得光剑。

模拟山羊3营救史蒂夫任务怎么做模拟山羊3营救史蒂夫任务怎么做Feb 25, 2024 pm 03:34 PM

营救史蒂夫是模拟山羊3中的一个独特任务,具体需要怎么做才能够完成呢,这个任务比较简单,但是我们需要注意不要理解错意思,下面就为大家带来模拟山羊3营救史蒂夫任务攻略,能够更好的完成相关的任务。模拟山羊3营救史蒂夫任务攻略1、首先来到地图中右下角的温泉。2、在来到温泉边上之后就可以触发营救史蒂夫的这个任务。3、注意在温泉里有个男人,虽然他也叫史蒂夫,但是并不是本次任务的目标。4、在这个温泉里找到一条叫史蒂夫的鱼,并且将其带上岸,即可完成这个任务。

抖音粉丝团任务在哪里看?抖音粉丝团会掉等级吗?抖音粉丝团任务在哪里看?抖音粉丝团会掉等级吗?Mar 07, 2024 pm 05:25 PM

抖音作为当下最受欢迎的社交媒体平台之一,吸引了大量用户参与其中。在抖音上,有很多粉丝团任务可供用户完成,从而获得一定的奖励和福利。那么,抖音粉丝团任务在哪里可以找到呢?一、抖音粉丝团任务在哪里看?为了找到抖音粉丝团任务,你需要访问抖音的个人主页。在主页上,你会看到一个名为“粉丝团”的选项。点击这个选项,你就可以浏览你所加入的粉丝团和相关任务。在粉丝团任务栏目中,你会看到各种不同类型的任务,如点赞、评论、分享、转发等。每个任务都有对应的奖励和要求,一般来说,完成任务后会获得一定数量的金币或者经验值

如何在 Windows 11 中停止任务管理器进程更新并更方便地终止任务如何在 Windows 11 中停止任务管理器进程更新并更方便地终止任务Aug 20, 2023 am 11:05 AM

如何在Windows11和Windows10中暂停任务管理器进程更新按CTRL+窗口键+删除打开任务管理器。默认情况下,任务管理器将打开“进程”窗口。正如您在此处看到的,所有应用程序都在无休止地移动,当您想要选择它们时,可能很难将它们指向下方。因此,按CTRL并按住它,这将暂停任务管理器。您仍然可以选择应用程序,甚至可以向下滚动,但您必须始终按住CTRL按钮。

时序分析五边形战士!清华提出TimesNet:预测、填补、分类、检测全面领先时序分析五边形战士!清华提出TimesNet:预测、填补、分类、检测全面领先Apr 11, 2023 pm 07:34 PM

实现任务通用是深度学习基础模型研究的核心问题,也是近期大模型方向的主要关注点之一。然而,在时间序列领域,各类分析任务的差别较大,既有需要细粒度建模的预测任务,也有需要提取高层语义信息的分类任务。如何构建统一的深度基础模型高效地完成各类时序分析任务,此前尚未有成型方案。为此,来自清华大学软件学院的团队围绕时序变化建模这一基本问题展开研究,提出了任务通用的时序基础模型TimesNet,论文被ICLR 2023接收。作者列表:吴海旭*,胡腾戈*,刘雍*,周航,王建民,龙明盛链接:https://ope

一切关于Windows 11任务栏中的“结束任务”选项的重要信息一切关于Windows 11任务栏中的“结束任务”选项的重要信息Aug 25, 2023 pm 12:29 PM

冻结或无响应的程序很容易从任务管理器中杀死。但是Microsoft最近为用户提供了直接从任务栏终止这些任务的便利。虽然该选项并未向所有人推出,但如果您有WindowsInsider版本,则很容易获得。以下是启用“结束任务”按钮并从任务栏关闭任务所需的一切。如何从任务栏中获取“结束任务”按钮以杀死应用目前,为任务栏应用启用“结束任务”按钮的选项仅作为具有Windows预览体验成员版本的用户的开发人员选项提供。但是,这在即将推出的功能更新中可能会发生变化,因为它将在稳定版本上向全球用户推出。如果您尚

See all articles

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)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.