Jobs at Cron

I am trying to complete a cron job with a site created in CodeIgniter. I have access to the cPanel cron function. Can anyone suggest a better way to configure cron to work with CPanel?

I use CodIgniter, so I can’t be sure how to call the controller as part of the cron job?

For example, http://admin.com/sites/publish/

How do I access this publish feature in site controllers using a cron job?

+7
source share
4 answers

The best way is to invoke the cron job from the command line ...

 php /path/to/index.php controller >> /dev/null 

You can run controllers through the command line in CI, see here .

+9
source

For me, an easier way to do this is to use cURL and execute the url in cron:

 curl http://admin.com/sites/publish/ 

If you need to protect the URL, you can send data via a message using:

 curl -X POST -d "apikey=yourapikey&another=variable" http://admin.com/sites/publish/ 

This way you don't have to deal with php options and various configurations.

+5
source

I do it this way, create a cron folder

 /application /cron my_task.php /public 

make a script for each cron / cron / my_task.php job with the contents

 <? $_SERVER["SCRIPT_URL"] = "/controllerName/MethodName"; // you can set url in routes if you want $_SERVER["HTTP_HOST"] = "your_site_address.com"; // without http://www require(dirname(__FILE__) . "/../public/index.php"); // path to index.php ?> 

make the cron controller look like the others, but add an IP check to __construct

and final launch for example

 1 10 * * * cd /path_to_site_folder/cron/ && usr/local/bin/php /path_to_site_folder/cron/my_task.php >> path_to_log/some.log 
+2
source

For Cronjob, try this to access the command line controller, functions, and parameters:

 php index.php/controller/function/param1/param2/param3 etc 

or

 php index.php controller function param1 param2 param3 etc 
+1
source

All Articles