Welcome Guest, Not a member yet? Register   Sign In
CI from Command-Line - script outputs to webbrowser but not on command-line
#1

[eluser]Nick Jennings[/eluser]
Hello All,

I had this working before, but now for some reason the script only works when I call it from my web browser, but not when I try to run it via. the command line:

cron.php
Code:
#!/usr/bin/php
<?php
$_GET["/ma/cli/do_cron"] = null;
$_SERVER["REQUEST_URI"] = '/ma/cli/do_cron/';
require 'index.php'
?>

When I access: http://localhost/project/cron.php - the output is fine
When I try via. the command-line:
Code:
project# php cron.php
project#

It just returns me to the prompt, no output. Not sure how to get any debugging info or if there are any logfiles which I can check, but as far as I know I'm not getting any errors at all.

Can anyone offer any insight to this? I was working on my old system, but I've since re-installed Linux, made changes to the code, updated codeigniter, etc. etc. So I'm not sure where the problem lies. I was reading several variations of how to do this, and this is what I was using as reference (and worked for me before):
http://booleandreams.wordpress.com/2008/...m-croncli/

Thanks for any help!
-Nick
#2

[eluser]Phil Sturgeon[/eluser]
Have a go with my slightly more robust solution.
#3

[eluser]Nick Jennings[/eluser]
I tried your solution also, with the same results. The function (do_cron) runs fine and displays output when run from a browser, but when run on the command-line there is no output at all.

http://localhost/index.php/ma/cli/do_cron
- works

# php index.php ma/cli do_cron
#

returns to prompt, no output.

I could really use some help on this one, I don't know how to go about debugging CI from the command line, and I'm not getting a single error...
#4

[eluser]brianw1975[/eluser]
try changing
Code:
#!/usr/bin/php
to
Code:
#!/usr/bin/php -q
thats what all of my command line php files have.
#5

[eluser]Nick Jennings[/eluser]
[quote author="brianw1975" date="1251494458"]try changing
Code:
#!/usr/bin/php
to
Code:
#!/usr/bin/php -q
thats what all of my command line php files have.[/quote]

Thanks for the response, but that doesn't seem to make any difference.

The thing is there don't seem to be any errors. It's just I'm not getting any of the output on the console. I get the correct output (unformatted text), with no errors, when run from the browser.
#6

[eluser]brianw1975[/eluser]
ok, do you have error_reporting turned off or set to E_NONE?
#7

[eluser]Nick Jennings[/eluser]
[quote author="brianw1975" date="1251495140"]ok, do you have error_reporting turned off or set to E_NONE?[/quote]

I Don't have error_reporting turned off. I don't think this is a PHP issue, I'm pretty sure it's something codeigniter related. The code seems to execute fine, but none of the output is being displayed when run from the console.

i.e. if I made a method that just echo'd TEST it would display in the browser, but not when I ran it from the console.
#8

[eluser]jedd[/eluser]
[quote author="nerohj" date="1251495857"]
I don't think this is a PHP issue, I'm pretty sure it's something codeigniter related.
[/quote]

Happily you are the owner of a real operating system, so this is pretty easy to check.

diff the two config files (the fact there are two has caught me out before - with phpdoc, actually - where I was sure I had plenty of memory configured .. alas it was in the apache config, not the cli config -- but I digress).

I use kdiff3 - because it's pretty to look at - but whatever diff viewer you feel comfortable with. On my system the two config files are at:
/etc/php5/apache2/php.ini
/etc/php5/cli/php.ini

Note they also have separate conf.d files - so anything you're pulling in that mechanism on your web front end may also be missing on the CLI version.
#9

[eluser]Nick Jennings[/eluser]
error_reporting is set to E_ALL ... like I said though, the function works fine. it's just that there is no output when run from the command line (the function executes though, i see the DB queries going to the database).

For example: I made a function called "test" in the test controller.

controllers/test.php
Code:
function test() {
    echo "TEST\n";
}

when run from a browser, 'TEST' is displayed.
when run from the command-line:
Code:
# php index.php test test
#

nothing...




Theme © iAndrew 2016 - Forum software by © MyBB