![]() |
Running Controller Methods with cPanel Cron Jobs - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Running Controller Methods with cPanel Cron Jobs (/showthread.php?tid=57204) |
Running Controller Methods with cPanel Cron Jobs - El Forum - 02-25-2013 [eluser]php_princess[/eluser] I've been trying to figure this one out for hours. When I set up a cron job in cpanel, and I set the command to this: php /home/mywebsitenamehere/public_html/index.php it says it can't find the file. However if I point to any other file in that directory, it does find it (e.g. php /home/mywebsitenamehere/public_html/index2.php it finds) If I put this, it finds the file, but it doesn't appear to load the controller or the method: cd /home/mywebsitenamehere/public_html/; php index.php controllernamehere methodnamehere I have cpanel emailing me every time it does a cron job and what it sends me is the code you see if you view the source on the home page. If it was really loading the controller, it should go to the page that the controller controls. I've consulted with CI's manual, my host's knowledge base, and Google. I'm still stuck. By the way, my webhost lets me use PuTTY. So, if you need me to use it, I can. Running Controller Methods with cPanel Cron Jobs - El Forum - 03-09-2013 [eluser]php_princess[/eluser] Still haven't gotten any further with this problem. Any help is appreciated. Running Controller Methods with cPanel Cron Jobs - El Forum - 03-11-2013 [eluser]Aken[/eluser] Make sure that items look like they would in the URL. So if you want to call example.com/users/edit, you'd use php index.php users edit Basically take your URL segments and append them to the call. Running Controller Methods with cPanel Cron Jobs - El Forum - 03-11-2013 [eluser]php_princess[/eluser] Thanks for the reply. It's still not working. It works fine through the URL but not through the cron. Works: http://www.mysite.com/cron/run_test Doesn't Work: php /home/mysite/public_html/index.php cron run_test I'm no longer getting a notification email that index.php could not be found. Now the email is showing me all the HTML that is output by my default controller, which is called home. I'm guessing that the home controller is getting loaded and not the controller cron. My host uses cPanel. From what I read on-line a lot of people have trouble using doing crons with codeigniter when cPanel is involved. A lot of people gave up on calling the controller through the file system and resorted to having the cron call it through the URL but I don't want this controller to be callable through a URL, for obvious security reasons. I saw one person say they got cPanel to do CI's crons by changing "php" to "/usr/local/bin/php" but if I do that it just says it can't find the PHP file. It it finds it if I use "/bin/php" but I still have the same problems as before. What should I do now? Running Controller Methods with cPanel Cron Jobs - El Forum - 03-15-2013 [eluser]davidMC1982[/eluser] Rather than attempting to use the php command line, use curl or wget instead. That way, you can use your normal url. Something like the following: Code: 0 23 * * * /usr/local/bin/curl http://www.example.com/controller/method You may or may not need the full path to curl or wget. You can find the path to php, curl and wget by using "which php", "which curl" and "which wget" from the command line. Running Controller Methods with cPanel Cron Jobs - El Forum - 03-19-2013 [eluser]LifeSteala[/eluser] This is really late, but CI uses CLI requests. Means you have to use PHP CLI to use this cron job properly. From SSH in crontab view it should be similar to: Code: // Change CPANEL_USER Running Controller Methods with cPanel Cron Jobs - El Forum - 06-21-2014 [eluser]Unknown[/eluser] This works fine. /usr/bin/curl --user-agent cPanel-Cron http://www.example.com/controller/function :-) |