Welcome Guest, Not a member yet? Register   Sign In
CI/PHP/Unix newbie: How to schedule a cronjob in CI?
#1

[eluser]guy_in_cali[/eluser]
Hey everyone! I'm fairly new to CI (and I'm now addicted to it) and PHP in general. My background is mostly using Coldfusion in Windows environments. I have a question. I'm trying to figure out how to schedule a cron job for my CI site. My application/system folders are located outside of my website directory (as sibling folders) for security reasons, but everything works great. Because of the way functions are called i.e. url/controller/function, my cronjob gives me a "No such file or directory" error message. This is the 1st time I've ever run a cron job as well. Please forgive me of my ignorance, but can anybody point me in the right direction?
#2

[eluser]gstjohn[/eluser]
Here is a good starting point for setting UNIX cron jobs:

http://www.adminschoice.com/docs/crontab.htm

I can give you some more specific direction, but I need to know a bit more about what you are trying to do and your environment.

Is the task you are trying to run available to the web at a given url (i.e. - http://www.somedomain.com/controller/fxn/var1)?

If not, are you trying to run the cron on a PHP file? Is the PHP file within your CI installation?
#3

[eluser]guy_in_cali[/eluser]
Hey, thanks for your reply. Thanks for the website, I'll check it out. Acutally, my hosting provider has a cronjob form for newbies, there's a field called "Command to execute" and it shows an example of just entering at path for the desired script to run. The time settings are all entered through the form as well. As to your question, I want to run a function in my controller such as http://www.mydomain.com/index.php/contro...e_function. I guess I could write a PHP script outside of CI and enter that URL or path for the cron job. What do you think? Is that enough detail? Thanks in advance Smile
#4

[eluser]gstjohn[/eluser]
Try using this command:

Quote:lynx -dump 'http://www.mydomain.com/index.php/controller/some_function' > output.txt

If you don't have 'lynx' on your machine, you might have 'links'. With shell access you can verify its existence by typing 'which lynx'.
#5

[eluser]guy_in_cali[/eluser]
Hey thanks, I'll try that. I'll have to get back to you though because I can't tell if its working since I've discovered there is a bug somewhere in my code. I'll get back to you when I get my code working. Thanks for all your help though Smile
#6

[eluser]guy_in_cali[/eluser]
Hey my friend. It looks like I have the kinks worked out of my code. I tried running the command you gave me, but it doesn't seem to be running or something. I don't know about shell access, but they give an example and it says 'lynx', so that command should work. Is it supposed to be outputing something to the file output.txt? Where would this file be generated, I don't see it generating one. Any ideas? Thanks for all your help! Smile


[quote author="gstjohn" date="1229138902"]Try using this command:

Quote:lynx -dump 'http://www.mydomain.com/index.php/controller/some_function' > output.txt

If you don't have 'lynx' on your machine, you might have 'links'. With shell access you can verify its existence by typing 'which lynx'.[/quote]
#7

[eluser]gstjohn[/eluser]
Well, it's good to know that lynx exists (at least you might think so since they use it in an example). How did you try running the command?

It should output the contents of the page to that file, you probably ought to use a full path so that you know exactly where it will end up. If you have shell access, you can test whether it will work before you set it up as a cron job. Are you on a shared machine? Can you get shell access?
#8

[eluser]Iverson[/eluser]
Using LAMP and CI, I simply made a cron.php controller and created various functions to do whatever operations I needed to run. If your cron is doing database manipulation, I would suggest making those functions in a model and calling them from your cron.php controller. This way you can take advantage of all of CI's features instead of a from scratch file. After making your functions, just run

Code:
wget http://www.example.com/cron/method
#9

[eluser]guy_in_cali[/eluser]
Hey thanks for all your help. I actually did go back to making a "from scratch file" outside of CI because I couldn't figure out if my cron job was running. Ok, I think I'll go back to using CI and running the command you suggested. Once again, thanks! :-)
#10

[eluser]guy_in_cali[/eluser]
Hey, thanks for all your help. I ran the command exactly as you suggested
Code:
wget http://www.mysite.com/index.php/cron/my_function

and its emailing me this error: wget: missing URL

I looked up the documentation for wget and it looks like it should work. Although thier example points to an actual file. Any ideas?




Theme © iAndrew 2016 - Forum software by © MyBB