How to use Cron with Codeigniter to query a MySQL database? |
[eluser]tim peterson[/eluser]
Hi all, i'm interested in what the code (command line and php) would look like where every minute or hour you take inventory of the number of item sales obtained from a mysql database and do some action based on that. I'm using codeigniter for php and i'll call my controller "cronControl". Here's what I have so far for the cronControl Controller: Code: class CronControl extends CI_Controller { Code: * * * * * php index.php cronControl countSales Code: -bash: 404.php: command not found any thoughts on what's going on? thank you, tim
[eluser]CroNiX[/eluser]
Did you try setting up an actual cron job with crontab or are you just entering that (with the asterisks) straight into the command prompt?
[eluser]tim peterson[/eluser]
Hi Cronix, i tried both ways, both didn't work, think there is something going on here with paths i'm specifying. If it is relevant, i've written the .htaccess rules so I can just type, http://localhost/cronControl/countSales and not http://localhost/index.php/cronControl/countSales. thanks, tim
[eluser]CroNiX[/eluser]
Try using a full path to your php and also a full path to your index.php. Also, the -q flag might be necessary. /usr/bin/php -q /home/site/index.php controller method
[eluser]tim peterson[/eluser]
Hi CroNIX, unfortunately, these aren't working either. my index.php is in my htdocs folder whereas my CI app is in the application folder i'm on a mac and here's what i mean: /applications/xampp/htdocs/index.php /applications/xampp/htdocs/application thanks, tim
[eluser]CroNiX[/eluser]
Don't know what else I can do to help. I only use my mac to test websites with the browser so I'm not sure how to advise you on setting up cron jobs for a mac. What I posted works on my production servers, which are Ubuntu and CentOS. Have you set up other cron jobs for your mac? Maybe they have some unorthodox settings. I'd try google to see about cron jobs on a mac in general. It could also be a permissions issue.
[eluser]tim peterson[/eluser]
ok i figured it out. the key when typing the command is in the crontab file to include the asterisks, but in the shell to NOT include the asterisks so crontab -e: * * * * * /usr/bin/php /applications/xampp/htdocs/index.php cronControl countSales whereas in htdocs $ /usr/bin/php /applications/xampp/htdocs/index.php cronControl countSales thanks, tim
[eluser]CroNiX[/eluser]
The asterisks determine what time/day to run the cron job on a schedule. When running from the command line, there is no scheduled time needed as you are just executing a command on the command line for immediate execution.
[eluser]tim peterson[/eluser]
ok thanks, i think i now understand! thanks again, tim |
Welcome Guest, Not a member yet? Register Sign In |