CodeIgniter Forums

Full Version: No output using CLI with CodeIgniter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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";
 
   }
 } 

[font=verdana, arial, helvetica, sans-serif]And if I run this command on the terminal[/font]


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

[font=verdana, arial, helvetica, sans-serif][font=verdana, arial, helvetica, sans-serif]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?[/font][/font]
It seems there is an error, but you don't output PHP errors.
(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?
What's your ENVIRONMENT ?
and display_errors and display_startup_errors in php.ini for cli?
(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.
> 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?
You too registered just to cross-post from StackOverflow?!
(11-24-2015, 05:06 PM)soda Wrote: [ -> ][font=verdana, arial, helvetica, sans-serif][font=verdana, arial, helvetica, sans-serif]... But if I delete the database and session libraries from the autoload.php file, it runs perfectly. Any ideas?[/font][/font]

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.