承接 toflar/cronjob-supervisor 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

toflar/cronjob-supervisor

最新稳定版本:2.0.3

Composer 安装命令:

composer require toflar/cronjob-supervisor

包简介

A simple supervisor for processes that can be triggered using a minutely cronjob

README 文档

README

Need to have a number of workers on some server but have no access to any daemon like supervisord or the likes but can configure a minutely cronjob? This library might come in handy for you then.

  1. Installation

composer require toflar/cronjob-supervisor

  1. Create your runner.php:
<?php

require_once 'vendor/autoload.php';

use Symfony\Component\Process\Process;
use Toflar\CronjobSupervisor\BasicCommand;
use Toflar\CronjobSupervisor\Supervisor;

    $supervisor = Supervisor::withDefaultProviders('/some/directory/you/want/to/store/your/state');
    
    $supervisor
        ->withCommand(new BasicCommand('sleep 10', 2, function () {
            return new Process(['sleep', '10']);
        }))
        ->withCommand(new BasicCommand('sleep 29', 4, function () {
            return new Process(['sleep', '29']);
        }))
    ->supervise()
;
  1. Configure the minutely cronjob

* * * * * /path/to/your/php/binary/php runner.php

That's it. The Supervisor will take care that even if your jobs are still running after a minute has passed, only ever your maximum number of processes will be created.

For this to work, it uses multiple providers to check if processes are still running. Currently supported are:

  • ps -p <pid>
  • tasklist /FI PID eq <pid>

Which means you should be able to run it on most Linux and Windows combinations.

统计信息

  • 总下载量: 304.5k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-26