I want to run a URL every day on 1PM which checks if some variables have been changed by running a query on an external API, and if have changed - store the new vars and notifies me via email.
Workspace:
I am using CodeIgniter MVC Framework.
Ubuntu Server 15.10.
More information of the situation:
- The controller
function cron_job()
is set to public, although I'm not sure it's safe and relevant for being public, since it's a special function that only the server has to run.
public function cron_job(){
// checks for vars and sends updated using email.
}
- The function is written in a controller that allows you to to run it only if you have a logged_in session. The logged_in session is created using the enctypted function that CodeIgniter offers. Which is kind of cool and easy to use. and safe. So if I want to run this I'll have to add a session somehow before running the
cron_job()
function. (Create a new private function that adds a session and call thecron_job()
function? I'm really not sure whats the right way doing this)
something like this?
private function add_session() {
$date = array(
'email' => $email, // ??? 'is_logged_in' => TRUE
);
$this->cron_job();
}
am i even allowed to run a private function from the server?
or can I insert a session variable using the encrypted functionality of CI and do this easily along with the cron job functionality of my ubuntu server?
Don't use web-based concepts for CLI functionalities ... And in general, don't mess with authentication and logged-in states.
What you should do is move that function into a separate controller, that doesn't require you to be "logged in" and put in a check to make sure that it can only be run via CLI, like this:
Also, making a controller method non-public in CI will make it inaccessible from the outside world, so that idea couldn't possibly work.