How to Check if php script is running from cli or command line interface



function isCli(){
       if( defined('STDIN') )
        {
            return true;
        }
        
        if( empty($_SERVER['REMOTE_ADDR']) and !isset($_SERVER['HTTP_USER_AGENT']) and count($_SERVER['argv']) > 0) 
        {
            return true;
        } 
        
        return false;
    }

Leave a Comment

Your email address will not be published. Required fields are marked *