Welcome Guest, Not a member yet? Register   Sign In
Yet another cron jobs / cli question
#1

[eluser]Clooner[/eluser]
Calling controllers and methods from the cli is now directly supported by CI which is a great thing!

My question is how do I prevent the script from executing when being accessed by a http request. e.g. when someone tries to call the controller method directly by accessing the url.

Code:
http://example.com/index.php/cron_controller/method_every_minute/

I can use the same system I did before by creating a symbolic link to index.php name it cron.php and check if the file being accessed is cron.php in the controller construct. Then deny access to the cron.php from the web.

There are several other ways to check some server variables like $argc and $argv and check STDIN or maybe CI2 contains a helper function to do just this.

My method seems a bit verbose to me! How do you guys prevent access to cron job controllers from the web?
#2

[eluser]bubbafoley[/eluser]
the input class has a function for that

Code:
if($this->input->is_cli_request())
{
  // do something
}
#3

[eluser]Clooner[/eluser]
[quote author="bubbafoley" date="1300313970"]the input class has a function for that

Code:
if($this->input->is_cli_request())
{
  // do something
}
[/quote]

That is exactly what I was hoping for. I searched the user guide for the keyword 'cli' but only the changelog came up.
Hopefully the reactor team will also start updating documentation because what are new features if they are not documented. One of the best features of CodeIgniter is the documentation and that should not change!
#4

[eluser]bubbafoley[/eluser]
yeah I had to grep over the system folder to find it.




Theme © iAndrew 2016 - Forum software by © MyBB