[Extension] Crontab

I just created a extension to manage system cron jobs with Yii that can also be used to run Application console commands.


just release version 0.3

Previous jobs are now retrieve from crontab file for further modifications and stuff…

Looks nice. :) Two notes:

  • You should better use __construct() as constructor name.

  • Maybe add a comment, that the crontab file must be writeable for the webserver if you want to manage jobs through a webinterface. This should be a well considered decision, as it can open up a huge security hole.

Crontab file access is based upon user permission. If user is wwwuser1, the extension creates a crontab file(typically, this is just a normal text file) for that user in the directory of this extension and then use ‘crontab file’ unix command to load the jobs in system crontab for that user. I guess there shouldn’t be any security holes.

I’m going to try to use it for my current project :)

Can you please add other documentation?

I’ve extracted everything under the folder extensions, but when you try to do

$cron = new Crontab('my_crontab'); // my_crontab file will store all added jobs

It will exit with this error:

PHP Error


include(Crontab.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory

File Sorgente


Can you please provide further informations like what to put into yii config?


I have some trouble using your extension… I’ve posted here http://www.yiiframework.com/forum/index.php?/topic/23217-crontab-help-please/

Can you help me?

Thanks in advance!


In the usage guide document (http://www.yiiframework.com/extension/yii-crontab) has code lines


See the following code example:

// Usage with ApplicationConsole and normal jobs


    $cron = new Crontab('my_crontab'); // my_crontab file will store all added jobs


    $jobs_obj = $cron->getJobs(); // previous jobs saved in my_crontab


    foreach($jobs_obj as $job)

        echo $job->getCommand();


    $cron->eraseJobs(); // erase all previous jobs in my_crontab


    // Application console job

    $cron->addApplicationJob('yiicmd', 'test1', array(), '*');


    // to change job values:

    $jobs_obj = $cron->getJobs();




    // <= adds a job with: * * * * * php /home/user/my_project/www/yiicmd.php test 'datetime'


    // add an other job

    $job = new CronApplicationJob('yiicmd', 'test', array("'datetime"), '0', '0'); // run every day




    // <= adds a second job with: 0 0 * * * php /home/user/my_project/www/yiicmd.php test 'date'


    // add a regular cron job

    $cron->addJob('/home/user/myprogram.bin', '0', '0', '*', '*', '1'); // run every monday

    $jobs_obj = $cron->getJobs();

    echo $jobs_obj[2]->getCommand();


    // <= adds a third job with: 0 0 * * 1 /home/user/myprogram.bin 


    $cron->removeJob(2); // removes job with offset 2 (last added here)


    $cron->saveCronFile(); // save to my_crontab cronfile


    $cron->saveToCrontab(); // adds all my_crontab jobs to system (replacing previous my_crontab jobs)

I don’t know where is php file to put these code lines? Please help me


Split function php is deprecated, us preg_split!!

This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.