定制 pnixx/crontab 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

pnixx/crontab

最新稳定版本:1.0.3

Composer 安装命令:

composer require pnixx/crontab

包简介

Provides a clear syntax for writing and deploying cron jobs

README 文档

README

Crontab for PHP provides a clear syntax for writing and deploying cron jobs (inspired by whenever).

Installation

$ composer require pnixx/crontab

Usage

use PNixx\Crontab\Crontab; use PNixx\Crontab\Job; //Initialize constructor $crontab = new Crontab('example.com', '/path/to/example.com'); //Add job for run every minute $job = new Job('bin/console hello'); $crontab->add($job); //Add job for run hourly $job = new Job('bin/console update'); $job ->setTime(Job::HOURLY) ->setLogFile('logs/execute.log'); $crontab->add($job); //Add job for run custom time $job = new Job('rm -Rf /var/cache'); $job->setTime('15 * * * *'); $crontab->add($job); //Add job for run every two minutes $job = new Job('echo "Hello World!"'); $job->setMinute('*/2'); $crontab->add($job); //Update crontab $crontab->update();

Result append or replace block to your crontab:

#===BEGIN Crontab for project: example.com * * * * * cd /path/to/example.com && bin/console hello 0 * * * * cd /path/to/example.com && bin/console update >> /path/to/example.com/logs/execute.log 15 * * * * cd /path/to/example.com && rm -Rf /var/cache */2 * * * * cd /path/to/example.com && echo "Hello World!" #===END Crontab for project: example.com 

Capistrano\Symfony integration

See on Capistrano::Symfony documentation plugin for reference.

Symfony 3 command class for generation crontab

use PNixx\Crontab\Crontab; use PNixx\Crontab\Job; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class CrontabUpdateCommand extends ContainerAwareCommand { public function configure() { $this->setName('crontab:update'); $this->setDescription('Update all cron tasks for project'); } protected function execute(InputInterface $input, OutputInterface $output) { $root_path = realpath($this->getContainer()->get('kernel')->getRootDir() . '/..'); //Initialize constructor crontab for current environment $crontab = new Crontab($this->getContainer()->get('kernel')->getEnvironment(), $root_path); //Add your jobs $crontab->add(new Job('echo "Hello World!"')); //Update $crontab->update(); } }

Add the following to deploy.rb for Capistrano '~> 3.5'

namespace :deploy do task :crontab do on roles(:db) do invoke 'symfony:console', 'crontab:update', '--no-interaction' end end end after 'deploy:published', 'deploy:crontab'

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固