PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 15, 2022

[FIXED] Multiple Jobs in One PHP file with Crunz

 March 15, 2022     cakephp-3.0, cron, cron-task, php     No comments   

Issue

I'm using https://github.com/lavary/crunz to make my CakePHP 3.0 cronjob calls.

The readme says: "The idea is very simple: instead of a installing cron jobs in a crontab file, we define them in one or several PHP files, by using the Crunz interface."

I want to define all my cronjobs in only one PHP file, but all the examples I could get showed only one job per file.

Does someone knows how to do multiple cronjobs in one file using Crunz?


Solution

The Crunz\Schedule::run() method registers and returns a new event each time you call it, so you can create many tasks with many calls to run(). A rough example probably looks like:

<?php
// tasks/backupTasks.php

use Crunz\Schedule;

$schedule = new Schedule();

// Register your first task
$schedule->run('cp project project-bk')       
         ->daily();

// Register another task
$schedule->run('other-task taskparam1 taskparam1')
         ->hourly();

return $schedule;


Answered By - Simon Brahan
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing