Welcome Guest, Not a member yet? Register   Sign In
No output using CLI with CodeIgniter
#1

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?
Reply
#2

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

(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?
Reply
#4

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

(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.
Reply
#6

> 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?
Reply
#7

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

(This post was last modified: 11-26-2015, 12:15 AM by skunkbad.)

(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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB