This is a simple bootstrap file that you can use to directly run your CodeIgniter controllers from the command line and redirect the output to a log file.
Note: While CodeIgniter 2.0 introduced CLI support, its syntax is less attractive and does not support logging or setting time limits.
Features
- Easy to use
- No core framework hacking
- Bootstrap file exists independently of your application
- Supports runtime limit
- Log the results of each run
- Run directly without the PHP command (on UNIX systems only)
Download
Get it on Github.com.
Hi Jonathon,
I think this is a cool solution. I have a few comments:
1) the source code provided in the download links, does not match the documentation: no –server parameter. Of course, this is not a show stopper.
2) My hosting service didn’t work with cron.php as a standalone script. so I ran it with “php PATH_TO/cron.php –run=/controller/method”, and removed the shebang.
3) I made logging optional. In the provided code, if no –log-file option is provided, it stills logs to “cron.log”
Anyway, thanks a lot for open sourcing the script.
Works perfectly. Thanks!
Thanks Jonathon! Worked first time.
–show-output will need to be something with equal sign.
–show-output=1 worked.
I get an error as I am using mod rewrite to remove index.php
PHP Notice: Undefined index: HTTP_HOST in /var/www/vhosts/xxxx.com/httpdocs/application/config/config.php on line 15
any work around?
In CI 2.0 I needed to change $config['uri_protocol'] to PATH_INFO as CI was using the wrong method for the script in AUTO mode.
There’s some minor bugs on the script but that doesnt compromise this awesome clean way to run CodeIgniter Cron Jobs.
Fully working.
Thanks for posting this work, it has been a great help to me getting CRON and CI to play nice together.
@David: work around the .htaccess issue by hard coding your HTTP_HOST in cron.php. Around line 44 add something similar to:
$_SERVER['HTTP_HOST'] = ‘http://localhost/index.php/’;
Nice script. It broke in v2 though. But then again: v2 runs CLI smoothly out of the box
http://codeigniter.com/user_guide/general/cli.html
Thanks for this. I love the concept, however, I have not been able to successfully make it work on my end. I’ve posted my question to both StackOverflow and Quora so I’ll simply link to them here. Please feel free to answer the question in either location.
http://stackoverflow.com/questions/6200828/issues-with-codeignitor-and-cron-bootstrapper
http://www.quora.com/Why-will-Codeignitor-Cron-Bootstrapper-not-work-with-my-CI-setup
Thanks in advance for your help.
-Tim
how to put schedule date on it.
i would like to run my cron on 10am every day. is it possible?
@Joseph – See http://unixgeeks.org/security/newbie/unix/cron-1.html, esp. the section “Using cron”.
very useful script.
1 Question: can be used to run CI with HMVC ?
ie. can I use:
– run [module name]/[controller]/[method]
I haven’t tried it, it will probably work, just thought to bring up the matter.
You can, but not out of the box. Google “CI HMVC”, there are plugins out there to enable it.
Warning: array_shift() [function.array-shift]: The argument should be an array in /home/content/63/8862763/html/cron.php on line 54
Warning: implode() [function.implode]: Invalid arguments passed in /home/content/63/8862763/html/cron.php on line 55
Warning: Invalid argument supplied for foreach() in /home/content/63/8862763/html/cron.php on line 58
Usage: cron.php –run=/controller/method [--show-output][-S] [--log-file=logfile] [--time-limit=N] [--server=http_server_name]
.. please help me to solve it …
Satish, what is the full command line you are executing (with all of the options)?
hi, i am using your cron, anw i have a question:
this is the default :
cron.php –run=/controller/method
if i want to adding log, how to type it?
cron.php –run=/controller/method –logfile
i am i wrong?
thanks
Posted in SO but no replies as yet – please could you take a look?
http://stackoverflow.com/questions/13281407/codeigniter-cronjob-cpanel-command-line-using-bootstrapper
I’ve just set up a Cronjob using the bootstrapper on GitHub (mentioned on here but not this specific issue). https://github.com/EllisLab/CodeIgniter/wiki/Cron-job-bootstrapper
As per guidance I have defined the CI index.php as below
define(‘CRON_CI_INDEX’, ‘/home/mysite/public_html/index.php’);
As a new user to the syntax, I’m not sure I’m entering the correct information on the command line. I have:
php -q -f /home/mysite/public_html/cronjobbootstrapper/cron.php –run=/testing/email_sending_function
And various other variations without the — before run= etc. I’m not sure what I’m doing wrong here, it’s not particularly clear in the guidance but others on here have used it successfully! I simply get an email through from the server containing part of the file contents. Usage: cron.php –run=/testing/mail_send_greg [--show-output][-S] [--log-file=logfile] [--time-limit=N] [--server=http_server_name]