Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect environment in CLI?

Tags:

php

I have a different config files for a script that runs both on a dev and production server. The question is, can I detect somehow which is which ?

like image 992
johnlemon Avatar asked Jul 22 '11 16:07

johnlemon


People also ask

How can I see environment in CMD?

To Check if an Environment Variable ExistsSelect Start > All Programs > Accessories > Command Prompt. In the command window that opens, enter echo %VARIABLE%. Replace VARIABLE with the name of the environment variable.

How do I see environment variables in terminal?

To display the values of environment variables, use the printenv command. If you specify the Name parameter, the system only prints the value associated with the variable you requested.

What is a CLI environment?

A command-line interface (CLI) is a text-based user interface (UI) used to run programs, manage computer files and interact with the computer. Command-line interfaces are also called command-line user interfaces, console user interfaces and character user interfaces.

How do I find environment in Linux?

The most used command to displays the environment variables is printenv . If the name of the variable is passed as an argument to the command, only the value of that variable is displayed. If no argument is specified, printenv prints a list of all environment variables, one variable per line.


1 Answers

Have a different bootstrap file to include depending on the server you're on. So

include "bootstrap.php";
// your script etc..

On the production box, bootstrap.php will have a constant IS_DEV = FALSE On the development box, bootstrap.php will have the same constant IS_DEV = TRUE

So the same script will include the same file name, bootstrap.php, but the contents of bootstrap will have different values for the IS_DEV constant variable.

like image 120
FinalForm Avatar answered Sep 17 '22 19:09

FinalForm