Code Monkey home page Code Monkey logo

think-cron's Introduction

think-cron 计划任务

安装方法

composer require yunwuxin/think-cron

使用方法

创建任务类

<?php

namespace app\task;

use yunwuxin\cron\Task;

class DemoTask extends Task
{

    public function configure()
    {
        $this->daily(); //设置任务的周期,每天执行一次,更多的方法可以查看源代码,都有注释
    }

    /**
     * 执行任务
     * @return mixed
     */
    protected function execute()
    {
        //...具体的任务执行
    }
}

配置

配置文件位于 config/cron.php

return [
    'tasks' => [
        \app\task\DemoTask::class, //任务的完整类名
    ]
];

任务监听

两种方法:

方法一 (推荐)

起一个常驻进程,可以配合supervisor使用

php think cron:schedule

方法二

在系统的计划任务里添加

* * * * * php /path/to/think cron:run >> /dev/null 2>&1

think-cron's People

Contributors

liu21st avatar yunwuxin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

think-cron's Issues

任务能传递参数么?

return [
    'tasks' => [
        \app\task\DemoTask::class, //任务的完整类名
    ]
];

\app\task\DemoTask::class, //任务的完整类名

这里能传递参数么?

php think cron:schedule异常

小白提问,我环境是windows, 为什么我跑php think cron:schedule 会按间隔弹窗问我如何打开这个文件,让我选择一个应用程序

When to support php8.0

I am install the latest version ^3.0,but it is conflict with the thinkphp8.0,I am using the php8.2 and thinkphp8.0.
Below it is the error:

 Problem 1
    - yunwuxin/think-cron[v3.0.0, ..., v3.0.5] require topthink/framework ^6.0 -> found topthink/framework[v6.0.0-rc2, ..., 6.1.x-dev] but it conflicts with your root composer.json require (8.0.x-dev).
    - yunwuxin/think-cron v3.0.6 requires symfony/process ^4.4 || ^5.0 -> found symfony/process[v4.4.0, ..., v4.4.44, v5.0.0, ..., v5.4.26] but the package is fixed to v6.2.10 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - Root composer.json requires yunwuxin/think-cron ^3.0 -> satisfiable by yunwuxin/think-cron[v3.0.0, ..., v3.0.6].

安装提示被弃用

Package mtdowling/cron-expression is abandoned, you should avoid using it. Use dragonmantank/cron-expression instead.

任务执行有效期问题

yunwuxin\cron\command::serverShouldRun
代码里面的意思是只缓存60s 这样感觉不是很科学哦,比如定时推送微信模板消息类的肯定不止60s吧

yunwuxin\cron\Task::onOneServer属性怎么不默认为true呢?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.