CodeIgniter Forums
No output using CLI with CodeIgniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: No output using CLI with CodeIgniter (/showthread.php?tid=63665)



No output using CLI with CodeIgniter - soda - 11-24-2015

I'm making a Cron job in CodeIgniter and I need access to my models in order to perform it's tasks. Here's my controller code.


PHP Code:
<?php
    class Cron 
extends CI_Controller
    
{
 
   public function send_mail() {
 
   if PHP_SAPI !== 'cli' ) exit('No web access allowed');
 
           echo "Hello World";
 
   }
 } 

And if I run this command on the terminal


Code:
php /home/path/to/project/index.php cron send_mail

It doesn't return anything, it's not executing the function. But if I delete the database and session libraries from the autoload.php file, it runs perfectly. Any ideas?


RE: No output using CLI with CodeIgniter - kenjis - 11-24-2015

It seems there is an error, but you don't output PHP errors.


RE: No output using CLI with CodeIgniter - soda - 11-24-2015

(11-24-2015, 09:30 PM)kenjis Wrote: It seems there is an error, but you don't output PHP errors.
It's because it doesn't output anything, if I add the -l flag when executing the php command it returns that there's no syntax errors in my code. Is there a way to debug or log everything in order to check what's wrong?


RE: No output using CLI with CodeIgniter - kenjis - 11-25-2015

What's your ENVIRONMENT ?
and display_errors and display_startup_errors in php.ini for cli?


RE: No output using CLI with CodeIgniter - soda - 11-25-2015

(11-25-2015, 05:01 AM)kenjis Wrote: What's your ENVIRONMENT ?
and display_errors and display_startup_errors in php.ini for cli?

My environment is set to 'development' and the settings in the php.ini are 'on'. Still no outputs.


RE: No output using CLI with CodeIgniter - kenjis - 11-25-2015

> My environment is set to 'development' and the settings in the php.ini are 'on'. Still no outputs.

Then, you should see errors when errors happens.

By the way, does the controller (without cli checking) work via your web browser?


RE: No output using CLI with CodeIgniter - Narf - 11-25-2015

You too registered just to cross-post from StackOverflow?!


RE: No output using CLI with CodeIgniter - skunkbad - 11-26-2015

(11-24-2015, 05:06 PM)soda Wrote: ... But if I delete the database and session libraries from the autoload.php file, it runs perfectly. Any ideas?

I just did a test of my own, and had no problem with the database and session libraries being autoloaded. I doubt that's your problem. I actually used your code too, and didn't have a problem.