On Mar 14, 2011, at 14:33, cricket wrote:
> On Mon, Mar 14, 2011 at 12:04 PM, [email protected] wrote:
>> is it possible to recognize that app is running as a SHELL??
>> 
>> I use a simple database switch in app/config/core.php ... I switch
>> between LOCAL and LIVE database...
>> 
>> I ask simply for domain.... domain.com OR domain.local
>> 
>> But if I run it trough SHELL, it does not provide this variable
>> $_SERVER['SERVER_NAME']; because it is not under Apache but running as
>> a SHELL.
>> 
>> 
>> Is there a way how can I recognize SHELL mode? or at least pass some
>> variables?

> Test whether $_SERVER exists.


That won't work because $_SERVER *does* exist, even for a CLI script. (In that 
case, it contains things like $_SERVER['argv'].)

In my projects, I like to test if PHP_SAPI == 'cli'. If you then need to 
further differentiate based on the hostname of the system, you can use 
gethostname().


<?php

$hostname = (PHP_SAPI == 'cli') ? gethostname() : $_SERVER['SERVER_NAME'];
switch ($hostname) {
        case 'production.example.com':
                // something
                break;
        case 'development.local':
                // something
                break;
        default:
                // unknown hostname
}

?>


Actually, to simplify things, you might just be able to use gethostname() in 
all cases (not just CLI).



-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to