PHP won't run model functions from terminal |
[eluser]bndk[/eluser]
Good evening, When I try to to run a controller's method from the terminal like so Quote:php index.php some_controller some_functionwith the following function body Code: function some_function() { However, when I load a model and try to call one of its functions from the controller, nothing happens. I tried to call the same model function from a web browser and it did what it was supposed to do, so I know there's not a problem with the function. Does anyone have an idea as to why it doesn't work? Your help is much appreciated ![]()
[eluser]CroNiX[/eluser]
My guess is that your app is relying on some $_SERVER variables, like $_SERVER['HTTP_HOST'] or similar, in order to do things like determine the database to use, etc. A lot of people use that to set their environment variables. Problems can happen when accessing from the CLI because those variables aren't present (since the request isn't coming from a browser) and so it can't operate properly. It's the main reason I've always used this method, as it allows you to set those variables as part of the CL request, or when used in a cron job. It's just more flexible.
[eluser]bndk[/eluser]
I tried to use the method you described above. I set the CRON_CI_INDEX to my app's main index.php. When I try to execute the controller's function I get a 404 error in return. Is there something more I need to set up?
[eluser]CroNiX[/eluser]
Here's what I have for my cron.php, which is in the same location as CI's index.php (with hardened permissions). Note the shebang with full path to php before php opening. I've disabled the logging in mine as I do the logging from my CI cron mothods, so it's commented out. Code: #!/usr/bin/php5 Code: /usr/bin/php5 -q /home/site/public_html/cron.php --run=/cron/daily --server=www.site.com
[eluser]bndk[/eluser]
Hmm... This is strange. I've copied everything you did above, but I still keep getting an 404 error. The whole page (html and css) are being output in the terminal. I'm hosting the website locally by the way, so I guess the server name should be localhost, right? |
Welcome Guest, Not a member yet? Register Sign In |