Jinsong Li
Jinsong Li

Reputation: 7398

Yii2 console app: how to detect runtime environment?

Say I have a PHP Yii2 console app, run in command line, like this

/var/www/my_app/yii myconsole/action

When I deploy the app in my production server (run as a cronjob), I have problem looking for an elegant way to detect if the app is running in my local machine or in production server.

When it is a web app, setting an environment variable in VirtualHost is a great solution. But for console app, right now I can use php_uname() function to differentiate environment by machine name, are there any better ideas for this?

Upvotes: 0

Views: 3561

Answers (1)

Jeffrey - Humanized
Jeffrey - Humanized

Reputation: 801

See The official documentation for Environmental Constants

Basically, check your index.php file to see which YII_ENV is defined, and you can then call it globally

Hope it helps!

Upvotes: 2

Related Questions