CodeIgniter Forums
[SOLVED]cron job - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [SOLVED]cron job (/showthread.php?tid=19780)



[SOLVED]cron job - El Forum - 06-18-2009

[eluser]bobbob[/eluser]
To run a cron job is there a way of redirecting in a file that then goes to a codeigniter controller and runs a normally or is that simply not possible with cron?
I have seen posts on this and it looks like there is no easy answer. Hoping to be wrong.


[SOLVED]cron job - El Forum - 06-18-2009

[eluser]jedd[/eluser]
[quote author="bobbob" date="1245367734"]To run a cron job is there a way of redirecting in a file[/quote]

What does redirecting in a file mean?
Quote: that then goes to a codeigniter controller

What goes to - the cron job, or the redirected .. something?

Quote: and runs a normally or is that simply not possible with cron?

What runs normally?

I'm speculating that you want to run a job periodically, and that job needs to hit a web page with an arbitrary URL. Is that right?

You've failed to mention what OS you're on, which is going to affect the elegance of any solution.

If I've guessed right then (apart from me getting a gold star) there is good news - you can do that. You want lynx or wget, and you'd call these at the end of the shell script that is called by cron.


[SOLVED]cron job - El Forum - 06-18-2009

[eluser]bobbob[/eluser]
Glad to here I may be in luck.
I am running it on a Unix system
Yes I will put a file on the server outside the codeigniter application and it will be called by cron and execute a controller in the codeigniter application.
At least that would be my ideal.


Hope that is clear.


[SOLVED]cron job - El Forum - 06-18-2009

[eluser]jedd[/eluser]
[quote author="bobbob" date="1245368731"]
Yes I will put a file on the server outside the codeigniter application and it will be called by cron and execute a controller in the codeigniter application.
[/quote]

Then it's very easy.

Your server needs to have either wget or lynx (or something else that can hit a web page from a CLI) installed. I'd probably go for wget as it's a bit lighter.

I'm assuming that you have a shell script somewhere that you are running? If you don't then you'll either need to wrap your binary in a shell, or call them both sequentially in cron. The former is easier as it means the call to your CI controller only happens after the successful running of the binary.

In either case you need a command like this:
Code:
wget  -O  -  -q  -t 1  http://www.yoursite.com.au/baseurl/controller/method   >  /dev/null



[SOLVED]cron job - El Forum - 06-18-2009

[eluser]bobbob[/eluser]
I am amazed at how many complicated solutions there are in these forums.

What worked for me was

<?php echo file_get_contents("http://www.youdomain.com/index.php/croncontroller"); ?>

inside the php file called by the cron

Enjoy!!


[SOLVED]cron job - El Forum - 06-18-2009

[eluser]jedd[/eluser]
Oh, so you're actually running within a php script, not wanting to call one.

I think it's a tad disingenuous to write a question like this:
Quote:To run a cron job is there a way of redirecting in a file that then goes to a codeigniter controller and runs a normally or is that simply not possible with cron?
.. and then claim the answer is complicated.


[SOLVED]cron job - El Forum - 06-18-2009

[eluser]bobbob[/eluser]
disingenuous is my middle name

Thanks for your time anyway.