If you’re like me, you have a number of offline jobs running in your application. These jobs process images, send emails, warm up caches, and sync up data with 3rd-party APIs.
Also, if you’re like me, you run into the same problems over and over:
- Manually maintaining crontab files is a burden.
- Frequent jobs that stall or delay may start running multiple copies.
- Knowing when a job fails automatically is tough because honestly who has time to look at log files?
- If you have a webfarm, you have to decide which jobs run on which servers, or all of them.
Enter jobby, the PHP cron job manager.
Install a single crontab entry on each of your servers, and never edit crontab again. The master cron job runs a PHP file which contains all of your real jobs and executes them according to their individual schedules (using crontab syntax) along with other configs. The nice thing is that since jobby
is just PHP, you can decided what jobs to run and when programmatically. Now, I know there are more expansive server configuration tools out there, but those felt too heavy for this kind of use.
More features: jobby
will ensure only 1 copy of a job runs at a time, can email one or more recipients if a job fails, and can run as different users on select hosts.
I developed a version of jobby
years ago, and have brought it along with me on various projects, slowly tweaking it. It’s helped me immensely and if you’re interested, check out the README and composer install
away!
8 Comments to 'Introducing Jobby, Your PHP Cron Job Manager'
August 6, 2013
Hi
your bundle seems to be great, but i don’t understand how i can use it with Symfony.
I want to execute some php files directly from jobby.php.
Do you have some extra docs to do that ?
thanks in advance
December 3, 2013
@emmanueltesson,
Thanks for the note. jobby can run anything you can run from the command line (CLI). So if you need run PHP from the CLI, you can use jobby for it. The config in the README has an example of this. Cheers!
January 22, 2014
hi
i have a problem with jobby.php to execute a method from a controller class :
$jobby->add(‘sendAlertHire’,array(
‘command’ => EventController::sendAlerthire(),
‘schedule’ => ‘* * * * *’,
‘output’ => ‘app/logs/sendAlertHire.log’,
‘enabled’ => true,
));
When i’m trying this above, i have got an error :
Using $this when not in object context in /var/www/cliquezavantdentrer.com/src/Onet/EventBundle/Controller/EventController.php on line 363
and the line is : $em = $this->getDoctrine()->getManager();
could you help me ?
thanks
January 22, 2014
@emmanueltesson,
Instead of
‘command’ => EventController::sendAlertHire()
Try:
‘command’ => array(EventController, ‘sendAlertHire’)
Let me know if it works.
January 22, 2014
Thanks for your quick reply, but it seems it’s not the good solution :
PHP Notice: Use of undefined constant EventController – assumed ‘EventController’ in /home/webs/cliquezavantdentrer.com/html/jobby.php on line 34
$jobby->add(‘sendAlertHire’,array(
‘command’ => array(EventController,’sendAlertHire’), //LINE 34
‘schedule’ => ‘* * * * *’,
‘output’ => ‘app/logs/sendAlertHire.log’,
‘enabled’ => true,
));
January 22, 2014
I think maybe ‘EventController’ needs to be quotes, if it’s a static call. If it’s not static, then it needs to be an instance of EventController. Not sure on the syntax off the top of my head.
Basically, that value has to adhere to rules for callbacks and Closures:
http://www.php.net/manual/en/language.types.callable.php
January 23, 2014
Hi
all seems to be ok with the quote !
The good code is :
$jobby->add(‘sendAlertHire’,array(
‘command’ => array(‘EventController’,’sendAlertHire’),
‘schedule’ => ‘* * * * *’,
‘output’ => ‘app/logs/sendAlertHire.log’,
‘enabled’ => true,
));
I think you could add this example to help others with same problem.
Thanks for explanation and help.
March 19, 2015
Hi, I’m having problems at the last step of the installation process:
* * * * * cd /www/project/html && php jobby.php 1>> /dev/null 2>&1
Returns:
-bash: cgi-bin: command not found
It would be great to have support on that specific issue. Thanks!