开发者

Accessing environment variable in a fastcgi application

I have writen a fastcGI application using C and C++

I have a free function that returns a string, if a specific environment variable has not been set. The function looks like this:

namespace
{
    std::string getNameString()
    {
        char * datastr_ = getenv(MY_ENVAR.c_str());

        if (datastr_)
            return std::string(datastr_);
        return DEFAULT_NAME;
    }
};

I then carry out the following steps (in the order given开发者_开发问答 below)

  1. I have edited my /etc/environment and added the appropriate environment variable
  2. I confirm that the variable has been set by typing printenv on the console
  3. I stop and then start the apache daemon

When I debug my application, I find that the environment variable has not been set. I suspect that the environment under which the fastcgi application is running may different from the environment 'normal' applications run under.

Does anyone know how to retrieve environment variable in a fastcgi app?


I suspect that fastcgi processes are spawned in a "cleaned" environment by default, given your observations. Apache certainly provides a way of setting environment variables for fastcgi. This has the added bonus of being slightly less cryptic too (who expects a webservice to behave differently when /etc/environment is changed?), like this you keep "web config things" with "web config things".


You could look here http://httpd.apache.org/docs/current/env.html and try to set the env variable in the apache process. I have assumed latest apache version.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜