3

I'm setting up my cron job controller that will only run within the CLI, I've not started with anything built, just in the testing phase with CI's examples. However, when running it I get no output or anything else, just a new line, this is the command I ran:

root@serv$ php /var/www/ci/index.php tools message
root@serv

As you can see in the second line, I get no output, just a new line to run an command but I don't understand why and I cannot debug it. The code contains this:

<?php
class Tools extends CI_Controller {

    public function message($to = 'World')
    {
        echo "Hello {$to}!".PHP_EOL;
    }
}
?>

In my configuration file, the $config['uri_protocol'] is set to AUTO so this does not seem to be the problem.

How can I debug this? What are the options that I may need to deal with?

I also have display_errors on and error_reporting on to E_ALL.

12
  • 1
    Well, it works - I just tested it with a basic CI setup (no changes to config.php). Commented Feb 22, 2012 at 8:35
  • 2
    @stealthyninja No, CLI syntax for CodeIgniter is php index.php controller method params. Commented Feb 22, 2012 at 8:39
  • @Repox That's strange, but I have no idea what I need to be aware of for changes I may have made towards CI configuration, that affects the CLI application. I don't understand why it doesn't return any output? Commented Feb 22, 2012 at 13:28
  • Any log file output? It seems odd that you wouldn't get anything... Commented Feb 24, 2012 at 19:55
  • @landons Nope, no type of errors being logged. Commented Feb 25, 2012 at 1:25

6 Answers 6

4

I found the problem, it was a problem with a redirect('domain.com'); exit; I had on an autoloaded library, because it was matching against the domain in a database, that way CLI doesn't serve a domain when it detects, hence I included a redirect('domain.com') with an exit which is why I'm not seeing any output.

Sign up to request clarification or add additional context in comments.

Comments

1

I also encountered this while i was playing w/ cli for codeigniter. It took me a while to troubleshoot the issue and found out that I forgot to except my controller on my login model which runs a redirect function.

1 Comment

Saved me about 4 hours of cursing trying to understand why, I owe you
0

This may be a silly suggestion, but might as well give it a shot... @lolwut, what if instead of using "echo", maybe you have to "return" the output?

1 Comment

Nope, that didn't help - still the same effect.
0

I have an application following this guide: http://codeigniter.com/wiki/Category:Advanced::CronScript running (and producing output). CI was only 1.7.2 when I did so, but it might still hold

Comments

0

(CodeIgniter 2.2.0)

Add a route in /application/config/routes.php

for...

<?php
class Cron extends CI_Controller
{    
    public function process_dumps()
    {
        echo "Processing dumps..." . PHP_EOL;
    }
}
?>

add...

$route['cron/process_dumps'] = 'cron/process_dumps'

Without this line there was no output on the CLI!

Comments

0

I think you can find the answer in the Codeigniter Wiki.

By calling to the cron.php with parameters controller and function, and then define CRON_CI_INDEX to the refer to the file path of your main index.php.

For example,

php /var/www/ci/cron.php --run=/tools/message

1 Comment

That didn't help too :( I still get no output generated, no logs too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.