Passing Http_Host Info To The Console Application

Hi…

I have requirement to connect the YII app to different databases based on HTTP_HOST.

E.g there will be same code for abc.com and xyz.com. But depending on URL, I will pick database config file abc.php or xyz.php.

This logic is perfectly working for front end.

I have also some console applications running. In console application there is no HTTP_HOST so how to select the database for console application as per above logic.Is there a way to find out the which URL or HTTP_HOST triggered console application.

Can anyone help me in this…

Thanks in advance !

Are you running these console apps from with the WebApp? If so, just past the needed information to select correct db as an ARG to the console app. Otherwise, a command line app is not run by a web request, it’s command line, so of course it doesn’t know what URL to use.

Thanks for you reply…

Yes I did the same thing.

For console applications running from webapp, I passed the host info as the extra argument from $_SERVER[‘HTTP_HOST’].

For scheduled console apps, I ws triggering the console apps from BAT file.

I had to create separate BAT file with hard-coded host as argument into it and set all file in scheduler.

Now these files will run after certain interval and access there on DB depending on host passed into them.