- weblog of Mizanur Rahman
Many of us faced the problem of running CodeIgniter controllers from Cron or from Command Line. usually we write the following codes to run a php file from cron/CLI.
php /var/www/path/to/your/script
but if we give CodeIgniter Controller path here it will not work since CodeIgniter will fail to initialize its core classes. A work around of this is running the script using CURL
curl http://yourwebsite/controllername
the problem with the above command is that it takes too much CPU resources .
Today my collegue Hasan showed me a nice way of doing it, just write the following codes in a php file in your root folder. here is the way to go
<?
$_GET["/external/do_cron"] = null;
require “index.php”;
?>
note: here “external” is the controller name and “do_cron” is the function name that you want to execute.
now save this file to any name you want (eg. mycron.php) and run the script using
php /var/www/path/to/script
[here it is php /var/www/mywebsite/mycron.php]
if the above code does not work, you can try the following one. (thanks to sucio)
$_SERVER["REQUEST_URI"] =”external/do_cron”;
require “index.php”;
Sucio Kastro
April 9th, 2008 at 11:55 am
I tried it but it didnt work, This is the code that worked
Sucio Kastro
April 9th, 2008 at 11:56 am
$_SERVER["REQUEST_URI"] =”external/do_cron”;
require “index.php”;
CodeIgniter Framework :: TermiT's Blog
April 16th, 2008 at 10:00 am
[...] Running CodeIgniter from Cron/CLI [...]
Some CodeIgniter Tutorial links « Afruj’s Weblog
May 2nd, 2008 at 3:49 am
[...] Running CodeIgniter from Cron/CLI [...]
Simple URL Checker - запуск проверок по расписанию | SimpleCoding.org
May 7th, 2008 at 7:24 am
[...] Об этом способе я прочитал в статье «Running CodeIgniter from Cron/CLI». Идея такая. Нужно написать скрипт (cron_cli.php) и [...]
CodeIgniter Tutorial Links « Brandontruong’s Weblog
June 27th, 2008 at 7:26 am
[...] Running CodeIgniter from Cron/CLI [...]
mike
September 29th, 2008 at 7:09 am
$_GET["/external/do_cron"] = null;
require “index.php”;
worked great!
Thank you!