Git Product home page Git Product logo

php-crond's Introduction

PHP-Crond

一个简单的PHP定时任务框架,通过创建子进程来执行定时任务

安装

composer require wangruyi/php-crond

示例

$sch = new \Wangruyi\PhpCrond\Scheduler();

$job = new \Wangruyi\PhpCrond\Job('* * * * *', 'php echo.php -a=1001', 'echo', 'log/echo.log');
$sch->addJob($job);

$job2 = new \Wangruyi\PhpCrond\Job('*/2 * * * *', 'php -v', 'phpv', 'log/echo.log');
$sch->addJob($job2);

$job3 = new \Wangruyi\PhpCrond\Job('*/2 * * * *', 'php echo.php -a=3001', 'echo', 'log/echo.log');
$sch->addJob($job3);

$sch->run();

Thinkphp使用示例

namespace app\common\command\system;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use Wangruyi\PhpCrond\Job;
use Wangruyi\PhpCrond\Scheduler;

class Schedule extends Command
{

    protected function configure()
    {
        $this->setName('schedule:run')
            ->setDescription('定时任务调度器入口');
    }

    protected function execute(Input $input, Output $output)
    {
        $sch = new Scheduler();
        $jobs = [
            new Job('*/10 * * * *', 'php think order:stat', 'stat', '/var/logs/order_stat.log'),
            new Job('4 0 * * *', 'php think order:settlement', 'settlement', '/var/logs/order_settlement.log'),
        ];
        $sch->addJobs($jobs);
        $sch->run();
    }

}

php-crond's People

Contributors

ruyi512 avatar

Watchers

 avatar

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.