• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cronjob outputs welcome message [SOLVED]

#11
(12-26-2016, 04:41 AM)Wouter60 Wrote: I've found a workaround, which involves modifying the is_cli() function inside the system/core/Common.php file:
PHP Code:
function is_cli()
{
 
  //the old part was:    
 
  //return (PHP_SAPI === 'cli' OR defined('STDIN'));  

 
  //this will do the trick":
    
if( PHP_SAPI == 'cli' OR defined('STDIN') )
    {
        return 
TRUE;
    }
    
    if( empty(
$_SERVER['REMOTE_ADDR']) and !isset($_SERVER['HTTP_USER_AGENT']) and count($_SERVER['argv']) > 0
    {
        return 
TRUE;
    } 
    
    return 
FALSE;


I know I shouldn't modify any system files, but what other options do I have?

perhaps not so elegant, but you can write that in the cron controller as `my_is_cli()` and call it in the construct.

That will, at least, not cause problems when updating the system dir.

Glad there's progress.
Reply

#12
Quote:perhaps not so elegant, but you can write that in the cron controller as `my_is_cli()` and call it in the construct.
Problem is that the cronjob won't load my cron controller unless CI knows it's a CLI request in an earlier stage.
Besides that, the session library calls the is_cli() function.
Is it possible to load my own is_cli() function before the one in system/core/common.php is loaded?
Reply

#13
It's in system/core/Common.php around line 373 (in CI 3.1,2)

You should be able to overload the system file like:

Create application/core/MY_Common.php

then just write the functions you need.


PHP Code:
    /**
     * Is CLI?
     *
     * Test to see if a request was made from the command line.
     *
     * @return     bool
     */
    
function is_cli()
    {
        
//return (PHP_SAPI === 'cli' OR defined('STDIN'));
                // your code here...
    


I don't think you need the if statement:

PHP Code:
if ( ! function_exists('is_cli')) 

I've never overwritten the Common.php file before, and it's a little different than Controller/Config/etc which are actual classes, so I'm not 100% this will work.
Reply

#14
Doesn't work, because Common.php is not a class.
Reply

#15
Finally found a working solution without changing the core/Common.php file.
I added my own is_cli() function to application/config/constants.php
Maybe it's not the most elegant solution, but I found in core/Codeigniter.php that the constants.php file is loaded right before Common.php.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.